-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Validate AWS signer region and service in tests #125559
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
Validate AWS signer region and service in tests #125559
Conversation
Extends the predicate in `AwsCredentialsUtils` to verify that we are using a proper AWS v4 signature complete with the correct region and service, rather than just looking for the access key as a substring.
|
Pinging @elastic/es-distributed-coordination (Team:Distributed Coordination) |
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.
Left some superficial comments, LGTM
| * @see <a href="https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-auth-using-authorization-header.html">AWS v4 Signatures</a> | ||
| */ | ||
| public static BiPredicate<String, String> fixedAccessKeyAndToken(String accessKey, String sessionToken) { | ||
| public static BiPredicate<String, String> fixedAccessKeyAndToken(String accessKey, String sessionToken, String region, String service) { |
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.
| public static BiPredicate<String, String> fixedAccessKeyAndToken(String accessKey, String sessionToken, String region, String service) { | |
| public static BiPredicate<String, String> fixedAccessKeyAndToken(String accessKey, String sessionToken, String region, String awsServiceName) { |
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.
Going for serviceName - this is all AWS-related so we could really add an aws prefix everywhere if we start going down that path :)
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.
Fine by me 👍
Though I was thinking about our own service classes as opposed to cloud services.
modules/repository-s3/src/main/java/org/elasticsearch/repositories/s3/S3BlobContainer.java
Outdated
Show resolved
Hide resolved
| return authorizationHeader.contains("/" + service + "/aws4_request, "); | ||
| } | ||
|
|
||
| final var remainder = authorizationHeader.substring(expectedPrefix.length() + 8 /* YYYYMMDD not validated */); |
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.
| final var remainder = authorizationHeader.substring(expectedPrefix.length() + 8 /* YYYYMMDD not validated */); | |
| final var remainder = authorizationHeader.substring(expectedPrefix.length() + 8 /* add 8 to skip YYYYMMDD, not validated */); |
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.
👍 going for "YYYYMMDD".length() /* date not validated */ - no need for a magic 8
| } | ||
|
|
||
| if (region.equals("*")) { | ||
| // skip region validation; TODO eliminate this when region is fixed in all tests |
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.
I'd put this in the method comment, since callers use it: it's a feature.
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.
yep fair point
💔 Backport failedThe backport operation could not be completed due to the following error: You can use sqren/backport to manually backport by running |
Extends the predicate in `AwsCredentialsUtils` to verify that we are using a proper AWS v4 signature complete with the correct region and service, rather than just looking for the access key as a substring.
Following on from elastic#125559, we can validate the region and service name in tests that use `DynamicAwsCredentials` too.
Following on from #125559, we can validate the region and service name in tests that use `DynamicAwsCredentials` too.
Following on from elastic#125559, we can validate the region and service name in tests that use `DynamicAwsCredentials` too.
Following on from #125559, we can validate the region and service name in tests that use `DynamicAwsCredentials` too.
Extends the predicate in `AwsCredentialsUtils` to verify that we are using a proper AWS v4 signature complete with the correct region and service, rather than just looking for the access key as a substring.
Following on from elastic#125559, we can validate the region and service name in tests that use `DynamicAwsCredentials` too.
Extends the predicate in
AwsCredentialsUtilsto verify that we areusing a proper AWS v4 signature complete with the correct region and
service, rather than just looking for the access key as a substring.