Skip to content

fix(auth): strip -fips suffix from AWS service name in SigV4 signer - #14867

Open
macastelaz wants to merge 2 commits into
mainfrom
fix/aws-sts-fips-service-name
Open

macastelaz wants to merge 2 commits into
mainfrom
fix/aws-sts-fips-service-name

Conversation

@macastelaz

Copy link
Copy Markdown
Contributor

Summary

When Workload Identity Federation (BYOID) with AWS is configured with a regional AWS STS FIPS endpoint (sts-fips.{region}.amazonaws.com), AwsRequestSigner extracts the service name from the first hostname segment (hostSplit[0]), resulting in sts-fips.

AWS SigV4 requires the credential scope and signing key derivation to use the canonical service name (sts) even when calling a -fips endpoint. Scoping to sts-fips causes AWS STS to reject the signed GetCallerIdentity subject token with:

SignatureDoesNotMatch: Credential should be scoped to correct service: 'sts'.

This change strips the trailing -fips suffix from the extracted hostname label (.replaceAll("-fips$", "")) while preserving the full sts-fips.{region}.amazonaws.com hostname in the Host header and request URL.

Testing

  • Added unit test sign_postGetCallerIdentityFips in google-auth-library-java/oauth2_http/javatests/com/google/auth/oauth2/AwsRequestSignerTest.java.

Manual Testing

@macastelaz
macastelaz requested review from a team as code owners October 30, 2026 14:07

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment on lines +122 to +123
String serviceName =
Splitter.on(".").split(uri.getHost()).iterator().next().replaceAll("-fips$", "");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

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.

Suggested change
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;

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant