Repository navigation
fix(grant): rewrite only the bucket's delegations on a policy write - #112
Merged
Merged
Conversation
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.
Written by Claude.
Part of FIL-1646. Replaces #111, whose stuck-lock diagnosis was wrong.
Overlaps #110. That PR makes the same change, scoping a rotation's rewrite to the written bucket with
ReplaceBySubject, as one part of a larger redesign that drops policy ETags, preconditions and locks. That redesign also depends on fil-forge/libforge#89, fil-forge/ingot#320, fil-one/fil-one#948 and an RFC. This PR is meant to land first as the narrow fix for the cause, independent of that redesign. #110 would then rebase onto it, keeping eitherReplaceOveror its ownReplaceBySubject.Problem
Since 2026-10-29, every
PutBucketPolicyon staging eu-central-3 fails with "the policy is being changed concurrently" (409 OperationAborted at the gateway). That keeps fil-one's policies e2e suite red, and the suite gates fil-one's production deploys.A policy write rotates the stored delegations of every key bound to a principal whose actions changed.
Rotatedid that throughdelegations.Replace, which locks the keys, then reads, decodes, deletes and re-inserts everything they hold, over every bucket, to change their grants over one. A write's cost therefore grew with the principal's keys × the buckets they reach × the commands per grant. Once it passedgrant.BatchTimeout(8s), every write for that principal failed, andwriteErrorreports the deadline as a concurrent change.Evidence from staging:
s3_PutBucketPolicyspans (Tempo, 5-minute buckets) on 2026-10-29: p90 was about 1.7–2.0s at 12:25 UTC, 3.7s at 13:40, 6.6s at 14:10, and pinned at 8.0–8.4s from about 14:40. A latency climb over two hours points to growth, not a held lock.latencyof about 8.02s next to the concurrent-change error, which matchesBatchTimeoutrather than the 10sLockTimeout.published revocationlines per 6-hour window during 2026-10-26 to 10-29. That those keys and buckets are left over from e2e runs is an inference; I haven't counted the live rows.Change
delegation.StoregainsReplaceOver:Replacenarrowed to the delegations over one subject. It takes the same audience locks, so the two serialize. It reads and deletes only the rows over the subject, which the(audience, subject, command)index serves, and leaves the rest in place. It refuses an undefined subject, and a replacement over another subject (CheckReplacementOver). Memory and Postgres share the implementation withReplacebehind a privatereplace. Postgres uses two query texts rather than an optional-subject predicate, so each is planned for its index.RotateusesReplaceOver, so a write costs what the keys hold over the bucket being written. Revocations and the stored result are unchanged.Revoke(principal removal) still replaces whole sets, as it removes everything.Rotatelogs each rotation's key count and duration: Info on success, Warn with the error on any failure, including one while loading the keys or the tenant's key. A rotation with no keys logs nothing. Today the handler reports a deadline only as a concurrent change, which is why this was hard to see.What this doesn't fix
Observability
prepared delegation rotation/rotating delegations failedwithtenant,bucket,keys,tookanderror. Success reads "prepared" because a policy write commits after the rotation returns.s3_PutBucketPolicyspan, or Hilt's own once its traces are exported), against the 8sBatchTimeout. Part of FIL-1143. An alert at around 4s would have flagged this a day before it failed.Checks
go build ./... && go vet ./... && go test ./...pass locally, andgofmtis clean.Rotate, and the duplicate-audience store test fails against the memory store before its fix.✴️
https://claude.ai/code/session_01DhEPPzQsYKXVZ2yGjcRWff
Generated by Claude Code