Repository navigation
fix(pool): one inline policy per queue on the shared worker roles (calque#226) - #231
Merged
Merged
Conversation
…lque#226) calque-pool-worker and calque-fleet-worker are shared, account-wide roles. Each pool or fleet provisioning call handed its one-queue policy to spawn's CreateOrGetInstanceProfile as InlinePolicyJSON. In spawn v0.131.0 that is written with PutRolePolicy under the fixed name "spawn-scoped-policy" (createIAMRole for a new role, updateInlinePolicy for an existing one), and PutRolePolicy replaces the document. So `pool create --model b` removed pool a's queue grant and pool a's workers lost access to their queue; two fleet runs raced the same way. calque#167 fixed this class for real runs with a role per bucket. That does not fit pools and fleet runs: a role and instance profile per run id would accumulate with nothing reaping them. Instead the role stays shared and each queue gets its own inline policy, q-<first 12 hex of sha256(queue ARN)>: - CreateOrGetInstanceProfile is now called with no policy, so spawn creates the role and profile and attaches SSM and spored-baseline-policy but writes no shared policy. calque then PutRolePolicy's the queue's own grant. - `calque pool delete` removes that pool's grant once its queue is gone (kept if the queue delete fails, so a retry is consistent). The fleet run's cleanup, and its provisioning-failure path, remove the run's grant. DeleteRolePolicy only ever targets the one q-* name; other inline policies are never touched. - A grant that would exceed IAM's 10,240-byte aggregate inline-policy limit fails with ErrRolePolicyBudget and a message saying what to do. No fallback to a broader grant. - Throttling and ConcurrentModification are retried (concurrent pools now write different policies on one role at the same time). - Migration: a leftover spawn-scoped-policy is logged and left in place. It is deleted when the one queue it grants is torn down, or when a newly written per-queue grant is identical to it. A legacy policy whose queue an older calque already deleted is not removed automatically (documented). New caller permissions: iam:DeleteRolePolicy (required for teardown); iam:GetRolePolicy and iam:ListRolePolicies (best-effort: legacy migration and the size-limit message). docs/guide/getting-started.md updated. Tests use a fake IAM with real PutRolePolicy replace semantics and a fake CreateOrGetInstanceProfile modelling spawn v0.131.0. Reverting the grant step to the original call (InlinePolicyJSON through spawn) fails the concurrent pools, delete-keeps-other, fleet-cleanup and size-limit tests. Fixes #226
scttfrdmn
marked this pull request as ready for review
November 16, 2026 19:35
This was referenced Nov 16, 2026
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.
Fixes #226. Part of the Leave-no-trace epic spore-host/spore-host#752.
Root cause
Every pool's workers run under
calque-pool-worker, and every fleet run's undercalque-fleet-worker. Both are shared role names.ProvisionWorkers,ScaleWorkersandProvisionFleetWorkerspassed their one-queue policy to spawn'sCreateOrGetInstanceProfileasInlinePolicyJSON. In spawn v0.131.0 (the version calque pins),createIAMRolewrites that policy for a new role andupdateInlinePolicywrites it for an existing one. Both callPutRolePolicyunder the fixed namespawn-scoped-policy, andPutRolePolicyreplaces the whole document. Sopool create --model bremoved pool a's queue grant, and pool a's workers started getting AccessDenied onReceiveMessage. Two fleet runs raced the same way.Relation to #167
#167 found the same
PutRolePolicy-replaces behaviour on the real-run path and fixed it with one role per bucket (roleNameForBucket). That approach doesn't carry over here. Pools and fleet runs would need a role and instance profile per model or run id, and nothing reaps those. Instead the role stays shared and each queue gets its own inline policy.Fix
q-plus the first 12 hex characters ofsha256(queue ARN)(QueueGrantPolicyName). It is deterministic, so provisioning and teardown agree on the name without storing any state.CreateOrGetInstanceProfileis now called with no policy. spawn still creates the role and profile and attaches SSM andspored-baseline-policy, but writes no shared policy. calque then writes the queue's grant withPutRolePolicy(internal/pool/iam.go).calque pool deleteremoves that pool's grant after its queue is deleted. If the queue delete fails, the grant is kept so a retry is consistent.DeleteRolePolicyonly ever targets that oneq-*name. calque never touches the role's other inline policies.ErrRolePolicyBudgetand a message saying what to do. It does not fall back to a broader grant. Measured: a grant is about 700 bytes and spawn's baseline about 1.3 KB, so roughly 12 concurrent pools or fleet runs fit per role.ConcurrentModificationare retried, since concurrent pools now write different policies on one role at the same time.spawn-scoped-policyis logged and left in place. It is deleted in two cases: when the one queue it grants is torn down, or when a newly written per-queue grant is identical to it. In both cases nothing can still depend on it. Not handled: a legacy policy whose queue an older calque already deleted stays in place, because offline we can't tell it apart from a live legacy pool in another region or account. The docs say so. There is also a small read-then-delete window if an older calque writes the legacy policy at the same moment.New permissions for the calque caller
iam:DeleteRolePolicy: required for pool and fleet teardown.iam:GetRolePolicyandiam:ListRolePolicies: best-effort, used only for legacy migration and the size-limit message. Without them the policy is logged and left in place.docs/guide/getting-started.mdis updated. Its existing list already omittediam:GetRoleandiam:GetInstanceProfile, which spawn's helper calls. That gap predates this PR and is left as it was.Tests (
internal/pool/iam_test.go)The tests use a fake IAM with real
PutRolePolicyreplace-by-name semantics and the aggregate size cap. A fakeCreateOrGetInstanceProfilemodels spawn v0.131.0, writingInlinePolicyJSONasspawn-scoped-policy.TestEnsureWorkerProfile_ConcurrentPoolsKeepBothGrantsTestDeletePool_KeepsOtherPoolsGrant, andTestDeletePool_QueueDeleteFailsKeepsGrantTestFleetCleanup_RemovesOnlyItsOwnPolicy(also checks idempotence)TestQueueGrantPolicyName_Deterministic, with the value pinned and checked againstshasumTestPutQueueGrant_SizeLimitIsSurfacedTestPutQueueGrant_RetriesConcurrentModificationTestLegacySharedPolicy, with 4 casesRevert check: I put the original call back (
InlinePolicyJSONpassed through to spawn, no per-queue write, no legacy handling). With that, the concurrent-pools test fails withpool bert lost its queue grant: role policies = [spawn-scoped-policy spored-baseline-policy]. The delete-keeps-other, fleet-cleanup and size-limit tests fail too. The original code called the concrete*spawnaws.Clientwith no seam, so the revert was done through the new seam.Gates
All pass:
gofmt -l .(clean),go vet ./...,go build ./...,go test -count=1 ./...(parse contract tests ran with uv, 0 skips),go test -raceon pool and cmd/calque,golangci-lint run(0 issues; local v2.15.0, CI pins v2.12.2), govulncheck (0 affecting),uvx ruff check .(no Python changed), andsemgrep scan --config=auto --erroron the changed Go files (exit 0). Nothing was run against AWS.