-
Notifications
You must be signed in to change notification settings - Fork 550
feat(auth) - support aws sdk v2 for registry auth #3806
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
base: master
Are you sure you want to change the base?
Conversation
Eclipse JKube CI ReportStarted new GH workflow run for #3806 (2025-12-05T15:19:13Z) ⚙️ JKube E2E Tests (19933929469)
|
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3806 +/- ##
=============================================
+ Coverage 59.36% 72.13% +12.77%
- Complexity 4586 4845 +259
=============================================
Files 500 492 -8
Lines 21211 19259 -1952
Branches 2830 2569 -261
=============================================
+ Hits 12591 13892 +1301
+ Misses 7370 4160 -3210
+ Partials 1250 1207 -43 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Since we don't have access to a real AWS instance, we might be able to leverage https://github.com/localstack/localstack to ensure the changes are working |
|
| /** | ||
| * Factory for AWS SDK helpers that supports both AWS SDK v1 and v2. | ||
| * Automatically detects which SDK version is available on the classpath. | ||
| * Maintains backward compatibility with the original AwsSdkHelper API. | ||
| */ | ||
| public class AwsSdkHelper { | ||
| private static final String ACCESS_KEY_ID = "AWS_ACCESS_KEY_ID"; | ||
| private static final String SECRET_ACCESS_KEY = "AWS_SECRET_ACCESS_KEY"; | ||
| private static final String SESSION_TOKEN = "AWS_SESSION_TOKEN"; | ||
| private static final String CONTAINER_CREDENTIALS_RELATIVE_URI = "AWS_CONTAINER_CREDENTIALS_RELATIVE_URI"; | ||
| private static final String METADATA_ENDPOINT = "ECS_METADATA_ENDPOINT"; | ||
| private static final String AWS_INSTANCE_LINK_LOCAL_ADDRESS = "http://169.254.170.2"; | ||
| private static final String DEFAULT_AWSCREDENTIALS_PROVIDER_CHAIN = "com.amazonaws.auth.DefaultAWSCredentialsProviderChain"; | ||
| private static final String AWS_SESSION_CREDENTIALS = "com.amazonaws.auth.AWSSessionCredentials"; | ||
| private static final String AWS_CREDENTIALS = "com.amazonaws.auth.AWSCredentials"; | ||
|
|
||
| public boolean isDefaultAWSCredentialsProviderChainPresentInClassPath() { | ||
| try { | ||
| Class.forName(DEFAULT_AWSCREDENTIALS_PROVIDER_CHAIN); | ||
| return true; | ||
| } catch (ClassNotFoundException e) { | ||
| return false; | ||
| } | ||
| } | ||
| private final AwsSdkAuthHelper delegate; |
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.
Should this class implement the AwsSdkAuthHelper interface too to ensure all methods are delegated?
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 would also prevent naming inconsistencies:
AuthConfig getCredentialsFromDefaultCredentialsProvider();
AuthConfig getAuthConfigFromDefaultCredentialsProvider();| * @throws IllegalAccessException if AWS SDK method access fails | ||
| * @deprecated Use {@link #getAuthConfigFromDefaultCredentialsProvider()} instead | ||
| */ | ||
| @Deprecated |
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.
The deprecations in this and the rest of the methods are weird.
They throw an UnsupportedOperationException which will effectively be as removing from a functional perspective.
SDK-wise, I don't think there's anyone consuming JKube as a library.
I think we should directly remove the methods (unless I'm missing something else here).
Affected methods:
- getCredentialsFromDefaultAWSCredentialsProviderChain()
- getSessionTokenFromCrendentials()
- getAWSAccessKeyIdFromCredentials()
- getAwsSecretKeyFromCredentials()
| @@ -0,0 +1,10 @@ | |||
| /* | |||
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 (and other classes are lacking the license header.
Not sure why the CI check is not failing on this (we should probably revisit that too -separate PR-)
| @@ -0,0 +1,9 @@ | |||
| /* | |||
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.
| @@ -0,0 +1,25 @@ | |||
| /* | |||
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.
| @@ -0,0 +1,32 @@ | |||
| /* | |||
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.
| @@ -0,0 +1,37 @@ | |||
| /* | |||
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.
| * Utility class for modifying environment variables in tests. | ||
| * Uses reflection to modify the environment map. | ||
| */ | ||
| public class EnvironmentVariablesTestUtil { |
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 is kind of fragile.
We have other tests that depend on the environment.
Maybe it's a good time to implement a proper Environment wrapper (in a separate PR) that can be leveraged by this feature's production code so that it can be set in tests.
|
|
||
| @Override | ||
| public String getEcsMetadataEndpoint() { | ||
| return System.getenv(METADATA_ENDPOINT); |
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.
In the prior version this was falling back to (http://169.254.170.2)
I see this documented here: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-metadata-endpoint-v2.html
We might want to keep the fallback
| * @deprecated Use {@link #getAuthConfigFromDefaultCredentialsProvider()} instead | ||
| */ | ||
| @Deprecated | ||
| public String getSessionTokenFromCrendentials(Object credentials) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException { |
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.
getSessionTokenFromCrendentials there was a typo here.
Maybe a good time to rename to getSessionTokenFromCredentials
manusa
left a comment
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.
Thx @ash-thakur-rh
Overall looks good, I added a few comments.
Thanks @manusa. I will take care of comments once the OpenShift model upgrade is complete |




Description
Fixes #3732
Adds AWS SDK v2 support for ECR authentication while maintaining backward compatibility with AWS SDK v1.
Changes
1. AWS SDK v2 Support
New Architecture:
AbstractAwsSdkHelper- Abstract base class with common AWS credential handling logicAwsSdkHelperV1- AWS SDK v1 implementationAwsSdkHelperV2- AWS SDK v2 implementationAwsSdkAuthHelperinterface - Contract for SDK version abstractionKey Features:
AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY,AWS_SESSION_TOKEN)AWS_CONTAINER_CREDENTIALS_RELATIVE_URI)2. LocalStack Support & Error Handling
LocalStack Registry Support for development and testing:
*.dkr.ecr.*.localhost.localstack.cloud:PORTAWS_ENDPOINT_URLenvironment variable support for custom ECR endpoints. If set, uses custom ECR instead of real ECR for signing requestsEnhanced Error Messages:
AWS authentication failure. Status: 400, Response: {"__type": "AccessDeniedException", "message": "User: arn:aws:iam::000000000000:user/ash is not authorized to perform: ecr:GetAuthorizationToken..."}
Fully backward compatible
Type of change
test, version modification, documentation, etc.)
Checklist