auth: trim trailing slash from LoginEndpoint in tokenEndpoint - #1330
Open
randomnote1 wants to merge 1 commit into
Open
auth: trim trailing slash from LoginEndpoint in tokenEndpoint#1330randomnote1 wants to merge 1 commit into
auth: trim trailing slash from LoginEndpoint in tokenEndpoint#1330randomnote1 wants to merge 1 commit into
Conversation
When custom cloud metadata discovery returns a login endpoint with a trailing slash (e.g. https://login.microsoftonline.<suffix>/), the tokenEndpoint function constructs a URL with a double slash before the tenant ID. This causes client certificate authentication to fail because the signed JWT assertion uses the malformed URL as the aud claim, which does not match the canonical realm issuer. Apply strings.TrimRight to normalize the LoginEndpoint before building the token URL. Add comprehensive unit tests covering trailing slash, multiple trailing slashes, custom cloud endpoints, and the default tenant fallback. Fixes hashicorp#1329 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
auth: trim trailing slash from LoginEndpoint in tokenEndpoint
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Community Note
Description
When custom cloud (AGC) metadata discovery returns a login endpoint with a trailing slash (e.g.,
https://login.microsoftonline.<suffix>/), thetokenEndpointfunction insdk/auth/client_credentials.goconstructs a token URL with a double slash before the tenant ID:This causes client certificate authentication to fail because the signed JWT assertion uses the malformed URL as the
audclaim, which does not match the canonical realm issuer. The token service rejects the request with:Client secret authentication is unaffected because it does not use the token URL as an audience claim.
Fix
Apply
strings.TrimRightto normalizeendpoint.LoginEndpointbefore constructing the token URL:This is a single-line change. The
stringspackage was already imported in the file.Tests
Added two integration tests in
sdk/auth/token_endpoint_test.gothat exercise the full authorizer flow with a trailing-slash login endpoint:TestClientCertificateAuthorizer_TrailingSlashLoginEndpointTestClientSecretAuthorizer_TrailingSlashLoginEndpointBoth tests use the existing
AzureADAccessTokenMockClient, whose path regex inherently validates that the constructed URL does not contain a double slash.This is a (please select all that apply):
Related Issue(s)
Fixes #1329
Rollback Plan
If a change needs to be reverted, we will publish an updated version of the provider.
Changes to Security Controls
No changes to security controls. This change normalizes URL path construction only.
Note
If this PR changes meaningfully during the course of review please update the title and description as required.