-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Make AWS WebIdentityToken actually working and usable from inside EKS. #12339
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
Changes from all commits
3e8612c
26faaf3
307ba49
7f15e88
e0d5c64
f81f85a
d4753d8
b9b02da
6b2897d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -105,22 +105,31 @@ public S3InputSource( | |
| this.s3ClientSupplier = Suppliers.memoize( | ||
| () -> { | ||
| if (s3ClientBuilder != null && s3InputSourceConfig != null) { | ||
| if (s3InputSourceConfig.isCredentialsConfigured()) { | ||
| if (s3InputSourceConfig.getAssumeRoleArn() == null) { | ||
| s3ClientBuilder | ||
| .getAmazonS3ClientBuilder() | ||
| .withCredentials(createStaticCredentialsProvider(s3InputSourceConfig)); | ||
| } else { | ||
| applyAssumeRole( | ||
| s3ClientBuilder, | ||
| s3InputSourceConfig, | ||
| createStaticCredentialsProvider(s3InputSourceConfig) | ||
| ); | ||
| } | ||
| } else { | ||
| // Each of these if statements will manipulate s3ClientBuilder if the condition is fulfilled. | ||
|
|
||
| // If both static key-pair and assume role ARN are defined, use the static key-pair to assume role. | ||
| if (s3InputSourceConfig.isCredentialsConfigured() && s3InputSourceConfig.isAssumeRoleArnConfigured()) { | ||
| applyAssumeRole( | ||
| s3ClientBuilder, | ||
| s3InputSourceConfig, | ||
| createStaticCredentialsProvider(s3InputSourceConfig) | ||
| ); | ||
|
|
||
| // If only static key-pair is defined, build the S3 client with the static key-pair | ||
| } else if (s3InputSourceConfig.isCredentialsConfigured() && !s3InputSourceConfig.isAssumeRoleArnConfigured()) { | ||
| s3ClientBuilder.getAmazonS3ClientBuilder().withCredentials(createStaticCredentialsProvider(s3InputSourceConfig)); | ||
|
|
||
| // If assume role ARN is defined, static key-pair is undefined, and WebIdentityToken file from the environment variable is undefined. | ||
| } else if (s3InputSourceConfig.isAssumeRoleArnConfigured() && !s3InputSourceConfig.isCredentialsConfigured() && !s3InputSourceConfig.isWebIdentityTokenEnvConfigured()) { | ||
| applyAssumeRole(s3ClientBuilder, s3InputSourceConfig, awsCredentialsProvider); | ||
| } | ||
|
|
||
| // Actually build the ServerSideEncryptingAmazonS3 object. | ||
| return s3ClientBuilder.build(); | ||
|
|
||
| } else if (s3ClientBuilder != null) { | ||
| return s3ClientBuilder.build(); | ||
|
|
||
| } else { | ||
| return s3Client; | ||
| } | ||
|
|
@@ -166,15 +175,21 @@ private void applyAssumeRole( | |
| AWSCredentialsProvider awsCredentialsProvider | ||
| ) | ||
| { | ||
| String assumeRoleArn = s3InputSourceConfig.getAssumeRoleArn(); | ||
| if (assumeRoleArn != null) { | ||
| // Do not run if WebIdentityToken file and assumeRole ARN are detected from the environment variable, | ||
| // we want the default s3ClientBuilder behavior for ServiceAccount + eks.amazonaws.com/role-arn annotation to work. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please tell us how did you arrive at the above conclusion. Link to the relevant AWS documentation would be helpful.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the default credentials provider which is turned on by default on S3 Client (provided as reference). You can see that the WebIdentityToken is in the middle (enabled when I will give you a little background: Everyone who runs Druid on EKS wants to use the ServiceAccount with annotated Role ARN because it's more secure and uses AWS's newer IMDS v2 API. When we actually configured "ServiceAccount with annotated Role ARN", Now, the old codebase somehow picked up the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based on reading: https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRoleWithWebIdentity.html IMHO
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cryptoe I am surprised about this too, I did not specify it anywhere inside the ingestion spec. Why did the S3InputConfig object picked it up? I could not figure that out. |
||
| if (s3InputSourceConfig.isWebIdentityTokenEnvConfigured() && s3InputSourceConfig.isAssumeRoleArnEnvConfigured()) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isnt just this condition required and we can remove all the refactoring from 108:132 ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cryptoe To be honest, the previous nested if statements makes it really difficult to understand what-goes-where. If in the future someone needs to add another custom function, it will be hard to do so (with the nested if statements). |
||
| return; | ||
| } | ||
|
|
||
| if (s3InputSourceConfig.isAssumeRoleArnConfigured()) { | ||
| String roleSessionName = StringUtils.format("druid-s3-input-source-%s", UUID.randomUUID().toString()); | ||
| AWSSecurityTokenService securityTokenService = AWSSecurityTokenServiceClientBuilder.standard() | ||
| .withCredentials(awsCredentialsProvider) | ||
| .build(); | ||
|
|
||
| STSAssumeRoleSessionCredentialsProvider.Builder roleCredentialsProviderBuilder; | ||
| roleCredentialsProviderBuilder = new STSAssumeRoleSessionCredentialsProvider | ||
| .Builder(assumeRoleArn, roleSessionName).withStsClient(securityTokenService); | ||
| .Builder(s3InputSourceConfig.getAssumeRoleArn(), roleSessionName).withStsClient(securityTokenService); | ||
|
|
||
| if (s3InputSourceConfig.getAssumeRoleExternalId() != null) { | ||
| roleCredentialsProviderBuilder.withExternalId(s3InputSourceConfig.getAssumeRoleExternalId()); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this required? I do not see this package being used anywhere in aws-common
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cryptoe yes this is required. Without it being defined here, the
aws-java-sdk-sts-VERSION.jarwould not be downloaded into thelib/folder.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which lib folder are you taking about ? Can you post the full path of the same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cryptoe The lib folder that the tar.gz artifact contains.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was fixed in #12482 already, the PR explains in detail why it is required