fix(transport): Fixes fetching new access token on every use of Service Account transport#71
Open
cveticm wants to merge 2 commits into
Open
fix(transport): Fixes fetching new access token on every use of Service Account transport#71cveticm wants to merge 2 commits into
cveticm wants to merge 2 commits into
Conversation
…ce Account transport
cveticm
force-pushed
the
CLOUDP-418568-sa-token
branch
from
July 15, 2026 14:52
dd5ddcc to
3fca99b
Compare
cveticm
marked this pull request as ready for review
July 15, 2026 15:20
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.
Proposed changes
JIRA ticket: CLOUDP-418568
Summary
When authenticating with an SA, the Atlas CLI minted a new access token on every command. Service accounts are capped at 100 active tokens per hour, so any workflow that runs many CLI commands (e.g. an automated agent using a GSA) quickly exhausts the limit and fails with:
oauth2: "access_denied" "Access Token limit reached. Please use the existing Access Tokens or create a new Service Account"This PR persists the SA access token and reuses it until it expires (~1 token/hour instead of 1/command).
Root cause
transport.NewServiceAccountClientWithHostbuilt the client viaclientcredentials.Config.Client(ctx). Each CLI command is a new process, so the OAuth2 client-credentials source minted and cached a token only in-process, then discarded it on exit. Nothing was written to disk, unlike the UserAccount flow which already persists its token.Fix
NewServiceAccountClientWithHostnow composes token sources:oauth2.ReuseTokenSourcefrom the token persisted on disk (loaded via the newconfig.ServiceAccountToken()accessor — returns the access token + JWT-derived expiry, no refresh token, leaving Token()/UserAccount behavior untouched).Result: a valid persisted token is reused across invocations; a new one is minted (and saved) only when none exists or the current one has expired. UserAccount, API-key, and no-auth paths are unchanged. Logout already clears access_token, so the persisted SA token is cleaned up on logout.
Note: SA profiles will now also have an access token attriute:
Reproduction (before the fix)
Ran the CLI with an SA profile in a loop:
Fails at call 101 with Access Token limit reached, confirming one token minted per command.
Verification (after the fix)