Repository navigation
fix(auth): strip -fips suffix from AWS service name in SigV4 signer - #14867
macastelaz wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request adds support for AWS FIPS endpoints in 'AwsRequestSigner' by stripping the '-fips' suffix from the host's first segment to correctly identify the service name, and includes a new unit test to verify this behavior. The review feedback suggests optimizing this change by replacing the regex-based 'replaceAll' method with a more efficient 'endsWith' and 'substring' check to avoid unnecessary regex compilation overhead on every request signing operation.
| String serviceName = | ||
| Splitter.on(".").split(uri.getHost()).iterator().next().replaceAll("-fips$", ""); |
There was a problem hiding this comment.
Using String.replaceAll with a regular expression compiles the regex pattern on every invocation. Since AwsRequestSigner.sign() is called for every request signing operation, this introduces unnecessary overhead.
Using a simple endsWith and substring check is much more efficient and avoids regex compilation entirely.
| String serviceName = | |
| Splitter.on(".").split(uri.getHost()).iterator().next().replaceAll("-fips$", ""); | |
| String firstSegment = Splitter.on(".").split(uri.getHost()).iterator().next(); | |
| String serviceName = | |
| firstSegment.endsWith("-fips") | |
| ? firstSegment.substring(0, firstSegment.length() - 5) | |
| : firstSegment; |
Summary
When Workload Identity Federation (BYOID) with AWS is configured with a regional AWS STS FIPS endpoint (
sts-fips.{region}.amazonaws.com),AwsRequestSignerextracts the service name from the first hostname segment (hostSplit[0]), resulting insts-fips.AWS SigV4 requires the credential scope and signing key derivation to use the canonical service name (
sts) even when calling a-fipsendpoint. Scoping tosts-fipscauses AWS STS to reject the signedGetCallerIdentitysubject token with:This change strips the trailing
-fipssuffix from the extracted hostname label (.replaceAll("-fips$", "")) while preserving the fullsts-fips.{region}.amazonaws.comhostname in theHostheader and request URL.Testing
sign_postGetCallerIdentityFipsingoogle-auth-library-java/oauth2_http/javatests/com/google/auth/oauth2/AwsRequestSignerTest.java.Manual Testing
sts-fips.us-east-2.amazonaws.com): https://paste.googleplex.com/6755399436500064