Skip to content

Conversation

@DaveCTurner
Copy link
Contributor

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.

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.
@DaveCTurner DaveCTurner added >test Issues or PRs that are addressing/adding tests :Distributed Coordination/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs v8.19.0 v9.1.0 labels Mar 25, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-distributed-coordination (Team:Distributed Coordination)

@elasticsearchmachine elasticsearchmachine added the Team:Distributed Coordination Meta label for Distributed Coordination team label Mar 25, 2025
Copy link
Contributor

@DiannaHohensee DiannaHohensee left a 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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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) {

Copy link
Contributor Author

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 :)

Copy link
Contributor

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.

return authorizationHeader.contains("/" + service + "/aws4_request, ");
}

final var remainder = authorizationHeader.substring(expectedPrefix.length() + 8 /* YYYYMMDD not validated */);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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 */);

Copy link
Contributor Author

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
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep fair point

@DaveCTurner DaveCTurner added auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) auto-backport Automatically create backport pull requests when merged labels Mar 25, 2025
@elasticsearchmachine elasticsearchmachine merged commit 8d649f2 into elastic:main Mar 25, 2025
17 checks passed
@elasticsearchmachine
Copy link
Collaborator

💔 Backport failed

The backport operation could not be completed due to the following error:

An unexpected error occurred when attempting to backport this PR.

You can use sqren/backport to manually backport by running backport --upstream elastic/elasticsearch --pr 125559

DaveCTurner added a commit that referenced this pull request Mar 25, 2025
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.
DaveCTurner added a commit to DaveCTurner/elasticsearch that referenced this pull request Mar 26, 2025
Following on from elastic#125559, we can validate the region and service name
in tests that use `DynamicAwsCredentials` too.
DaveCTurner added a commit that referenced this pull request Mar 27, 2025
Following on from #125559, we can validate the region and service name
in tests that use `DynamicAwsCredentials` too.
DaveCTurner added a commit to DaveCTurner/elasticsearch that referenced this pull request Mar 27, 2025
Following on from elastic#125559, we can validate the region and service name
in tests that use `DynamicAwsCredentials` too.
elasticsearchmachine pushed a commit that referenced this pull request Mar 27, 2025
Following on from #125559, we can validate the region and service name
in tests that use `DynamicAwsCredentials` too.
omricohenn pushed a commit to omricohenn/elasticsearch that referenced this pull request Mar 28, 2025
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.
omricohenn pushed a commit to omricohenn/elasticsearch that referenced this pull request Mar 28, 2025
Following on from elastic#125559, we can validate the region and service name
in tests that use `DynamicAwsCredentials` too.
@DaveCTurner DaveCTurner deleted the 2025/03/25/aws-validate-signer-region branch April 2, 2025 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-backport Automatically create backport pull requests when merged auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) :Distributed Coordination/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs Team:Distributed Coordination Meta label for Distributed Coordination team >test Issues or PRs that are addressing/adding tests v8.19.0 v9.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants