Skip to content

CSHARP-3740: Add native support for AWS IAM Roles for service accounts, EKS in particular. #947

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 22, 2022

Conversation

DmitryLukyanov
Copy link
Contributor

@DmitryLukyanov DmitryLukyanov commented Nov 14, 2022

Asked a question about possible thead safe issue: aws/aws-sdk-net#2487

Copy link
Contributor

@JamesKovacs JamesKovacs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly questions with a few minor corrections.

exit 0
fi
PROJECT_DIRECTORY=${PROJECT_DIRECTORY} OS=$OS ASSERT_NO_URI_CREDS=true evergreen/run-mongodb-aws-test.sh

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we running run-mongodb-aws-test.sh twice, once without AWS_ROLE_SESSION_NAME set and once with it set? If we are testing two different scenarios, we should probably separate this into two separate functions. Otherwise if one fails, it will not be immediately obvious which one. We would have to check whether AWS_ROLE_SESSION_NAME is set or not to understand which test case failed. Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these cases are very similar (but different) because if AWS_ROLE_SESSION_NAME is missed, it will be added automatically by sdk. Also the reason why we configure both cases is requirement in the spec here (supporting both cases where AWS_ROLE_SESSION_NAME is added and where not)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

into two separate functions.

both of these steps require the same precondition in the first step, so I would say it's not too wrong running these ones in the same scope.

it will not be immediately obvious which one

given that it's almost the same scenarios, I would not expect failing them differently one from another. But even if so, EG provides a way to know what particular step was failed. For example pay attention on (step 9.2.. here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough.

@@ -9,7 +9,7 @@ set -o errexit # Exit the script with error if any of the commands fail
#
# Environment variables used as output:
# AWS_TESTS_ENABLED Allows runnings AWS tests
# AWS_ECS_TEST Allows runnings EVS tests
# AWS_ECS_ENABLED Allows runnings ECS tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allows runnings => Allows running

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

_awsHttpClientHelper = new AwsHttpClientHelper(httpClientWrapper);
_environmentVariableProvider = Ensure.IsNotNull(environmentVariableProvider, nameof(environmentVariableProvider));
var creds = FallbackCredentialsFactory.GetCredentials();
var immutableCredentias = creds.GetCredentials();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

immutableCredentias => immutableCredentials

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

return false;
}
var creds = FallbackCredentialsFactory.GetCredentials();
var immutableCredentias = await creds.GetCredentialsAsync().ConfigureAwait(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

immutableCredentias => immutableCredentials

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

using System.Security;
using System.Threading;
using System.Threading.Tasks;
using Amazon.Runtime;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't switching to use the AWS SDK be done in the context of https://jira.mongodb.org/browse/CSHARP-4390?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the AWS SDK is responsible for caching, do we need any of this caching logic that was introduced in https://jira.mongodb.org/browse/CSHARP-4273?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't switching to use the AWS SDK be done in the context of https://jira.mongodb.org/browse/CSHARP-4390?

Better to do it now, otherwise we will need implementing custom aws-web-identity-credentials functionality and then simply remove it in the next ticket. I consider the scope of CSHARP-4390 like replacement this logic on this (I already tried to include that logic here, but with no success yet, so I defer it until 4390)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the AWS SDK is responsible for caching, do we need any of this caching logic that was introduced in https://jira.mongodb.org/browse/CSHARP-4273?

yes. it's used in azure kms

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point about Azure KMS.

While I'm not enthusiastic about splitting the CSHARP-4390 work between these two tickets, I understand your reasoning. It doesn't make sense to implement something in this ticket to only revert it in the next. Accepted.

Copy link
Contributor

@JamesKovacs JamesKovacs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

{
return null;
// returns cached credentials source immediately. Only if cached source unavailable, makes quite heavy steps
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See https://github.com/aws/aws-sdk-net/blob/master/sdk/src/Core/Amazon.Runtime/Credentials/FallbackCredentialsFactory.cs#L127.
A full lookup for sources happens only first time and after failure. It's still not ideal, but maybe we can apply current solution now and create a ticket to track possible improvement (including submitting a PR to their repo)?

Copy link
Contributor

@JamesKovacs JamesKovacs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@DmitryLukyanov DmitryLukyanov merged commit daa8899 into mongodb:master Nov 22, 2022
dnickless pushed a commit to dnickless/mongo-csharp-driver that referenced this pull request Aug 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants