Skip to content

GCS snapshot tokens are minted locally, so large clusters no longer hit the STS quota - #3150

Open
ILLUM1N0X wants to merge 10 commits into
agent-substrate:mainfrom
ILLUM1N0X:local-cab-minting
Open

ILLUM1N0X wants to merge 10 commits into
agent-substrate:mainfrom
ILLUM1N0X:local-cab-minting

Conversation

@ILLUM1N0X

@ILLUM1N0X ILLUM1N0X commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #3156

In large clusters, bursts of cold suspends exceed the STS token exchange quota, 6,000 per project per minute by default, because the credential exchange made one STS call per actor. The suspends then fail.

gcsissuer now exchanges each source token at STS once, for an intermediary token and a session key. It mints each actor's token locally by encrypting the actor's Credential Access Boundary with that key. This is the client-side token exchange Google implements in its Java library and not yet in Go. STS now sees one call per source token refresh, about every 20 minutes, instead of one per actor. The STS team said the format is stable for implementations outside Google's libraries.

A refreshed source token is exchanged in the background while mints keep using the previous intermediary, so a slow or failing STS doesn't hold them up. If an exchange fails, mints fall back to the latest intermediary, and retries back off from one second up to 30 seconds. GCS checks the boundary only when a token is used, and refuses one over its limits with a bare 401. We measured the limits against GCS: an object prefix of 512 bytes in a condition, and a boundary of 4,096 bytes. Server-side tokens accept a prefix of at least 1,000 bytes. So for a boundary over either limit, the issuer asks STS to downscope that actor's token itself, at one STS call per such actor.

A template's gs:// storageLocation may be at most 338 characters for the bucket name and path together, so actors under it fit local minting. A longer --snapshot-location still works. ate-api-server logs a warning at startup, and actors whose prefix doesn't fit get their tokens from STS.

tink-go is a new dependency. STS sends the session key as a Tink keyset, and the encrypted part of the token carries Tink's key prefix, so the standard library's AES-GCM can't replace it without reimplementing parts of Tink.

Tested on a GKE cluster with a fresh install: the full e2e suite passed on gVisor workers, including the snapshot credential tests against real GCS, and a microVM actor suspended and resumed from its own snapshot. In Cloud Monitoring, 50 actors resumed and suspended in a row cost 50 STS token exchanges before this change and none after. Each ate-api-server pod made one intermediary exchange on first use. The STS fallback and the location check came after that run and have unit tests. The fallback was also checked against real GCS: for a 544-byte actor prefix, Issue got a token from STS that GCS accepted under the prefix and refused for a sibling.

AI use: AI-assisted, I reviewed and tested it.

  • Tests pass
  • Docs updated

@ILLUM1N0X
ILLUM1N0X marked this pull request as ready for review October 23, 2026 15:15
@ILLUM1N0X
ILLUM1N0X force-pushed the local-cab-minting branch 2 times, most recently from b526a3f to 19ee6fa Compare October 23, 2026 16:25

@sunnylovestiramisu Sunny (sunnylovestiramisu) 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.

We benchmarked with this PR, providing data points at scale. In our actual 200K runs with #3150, STS calls dropped from roughly 221,000 down to under 100 which significantly rescues startup latency TTFI(without this PR, at the default 6K/min STS quota, , STS 429 throttling cancelled Riptide image streaming and forced slow 35–39 second full image pulls, pushing TTFI p99 up to 31 to 119 seconds) and snapshot upload durability(without this PR, STS throttling caused roughly 50% of background snapshot uploads to fail silently).

@ILLUM1N0X ILLUM1N0X added the breaking-change PRs with breaking changes label Nov 20, 2026
Comment thread internal/resources/validate.go Resolved
@ILLUM1N0X ILLUM1N0X removed the breaking-change PRs with breaking changes label Nov 30, 2026
@ILLUM1N0X ILLUM1N0X closed this Nov 30, 2026
@ILLUM1N0X ILLUM1N0X reopened this Nov 30, 2026
The credential exchange made one STS call per actor, and bursts of cold
suspends in large clusters exceeded the STS token exchange quota.

gcsissuer now exchanges each source token at STS once, for an intermediary
token and a session key. It mints each actor's token locally by encrypting
the actor's Credential Access Boundary with that key, as Google's Java
library does for client-side Credential Access Boundaries. STS sees one call
per source token refresh instead of one per actor.

Signed-off-by: Johnny Shehade <johnnyshehade@google.com>
…TS fails

An STS outage or quota refusal at a source token refresh failed every mint,
though the previous intermediary token was still valid. Mints now use it
while it has more than stsTimeout left, as the source token's own fallback
does.

The exchange gets its own deadline, since dropping the caller's cancellation
also dropped its deadline. Each exchange is logged with its expiry. The
session key is decoded with or without padding, as Java's decoder does. The
Issuer contract now says force may reuse what an issuer keeps to mint.

Signed-off-by: Johnny Shehade <johnnyshehade@google.com>
A refreshed source token made mints wait for its STS exchange, so a slow
STS stalled them and a hanging one outlasted short caller deadlines, though
the previous intermediary token still had about 40 minutes left. After a
failed exchange every mint called STS again, one call per actor during the
quota refusals this package avoids.

While the previous intermediary has at least minServeLifetime left, mints
now use it and the exchange runs in the background, as Google's Java library
refreshes ahead of expiry. After a failed exchange, STS is not called again
for stsTimeout.

Signed-off-by: Johnny Shehade <johnnyshehade@google.com>
GCS checks a locally minted token's access boundary only when the token is
used. It refuses a condition string literal over 512 bytes or a boundary
over 4096 bytes with a 401 that does not say why, so the transfer failed
after a forced re-mint of the same boundary. These limits are measured, not
documented.

gcsboundary now refuses a longer literal, and the issuer a larger boundary,
before any STS call, with codes.Internal and an error naming the limit.

Signed-off-by: Johnny Shehade <johnnyshehade@google.com>
A failed exchange paused STS calls for stsTimeout, so one transient failure
with no intermediary to fall back on failed every mint for 30 seconds. The
pause now starts at a second and doubles with each failure up to stsTimeout.

Mints during the pause say STS is paused instead of repeating the failed
exchange's error. An STS timeout is the exchange's own deadline, so it no
longer reaches the caller as context.DeadlineExceeded, which the exchange
passed on as DeadlineExceeded instead of Unavailable.

Signed-off-by: Johnny Shehade <johnnyshehade@google.com>
Signed-off-by: Johnny Shehade <johnnyshehade@google.com>
GCS refuses a locally minted token with a bare 401 when the object prefix
in its access boundary condition is over 512 bytes. Under a long snapshot
location every actor's prefix is that long, so every suspend failed.

ValidateSnapshotLocation now refuses a gs:// location whose longest actor
prefix would go over the limit. ate-api-server and ate-setup reject such a
--snapshot-location at startup, and ActorTemplate and tag creation reject
such a location up front. gcsboundary still checks each grant, for
locations stored before this change. The limit and the name format move to
internal/resources, so both checks share them.

Signed-off-by: Johnny Shehade <johnnyshehade@google.com>
Signed-off-by: Johnny Shehade <johnnyshehade@google.com>
…ations

A locally minted token carries at most a 512-byte object prefix and a
4,096-byte boundary. An actor under a long snapshot location failed every
mint, and ate-api-server refused such a --snapshot-location at startup,
which broke upgrades of existing installs.

gcsissuer now asks STS to downscope an actor's token itself when its
boundary does not fit. ate-api-server only logs a warning for a long
--snapshot-location. The 338-character cap applies to the preview-gated
template storageLocation, so actors under it keep locally minted tokens.

Signed-off-by: Johnny Shehade <johnnyshehade@google.com>
Comment thread internal/resources/validate.go Resolved
Comment on lines +222 to 229
plain, err := encode(i.cel, rules)
if err != nil {
return credential.Token{}, status.Errorf(codes.Internal, "while building the access boundary: %v", err)
return credential.Token{}, status.Errorf(codes.Internal, "while encoding the access boundary: %v", err)
}
tok, err := ts.Token()
if err != nil {
return credential.Token{}, fmt.Errorf("while exchanging at STS: %w", err)
}
if tok.AccessToken == "" {
return credential.Token{}, errors.New("STS returned no access token")
tooLong := func(r gcsboundary.Rule) bool { return len(r.ObjectPrefix) > resources.MaxGCSResourceName }
if len(plain) > maxBoundary || slices.ContainsFunc(rules, tooLong) {
return i.exchangeServerSide(ctx, rules)
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🤖 Nit (optional): checking the prefix length before encode avoids parsing CEL and marshaling the boundary proto when a rule already exceeds MaxGCSResourceName (tiny compared to the STS call, so fine to skip)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

WDYT of keeping both limits in one check, so there's a single place that decides when to fall back to STS. The encode it would skip is tiny next to the STS call that follows, so I don't think the saving is worth splitting the check.

URL schemes are case-insensitive, and the actor prefixes built from a
GS:// location are gs:// ones, so its actors get GCS tokens.
ValidateGCSLocationLength matched only a lower-case gs:// prefix, so a
long GS:// template storageLocation skipped the check.

Signed-off-by: Johnny Shehade <johnnyshehade@google.com>

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

area/reliability area/security Security related issue/pr area/storage kind/bug Something isn't working / bugfixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

objectstore-plugin: snapshot credentials make one STS call per actor and hit the STS quota at scale

5 participants