Repository navigation
fix(iam): batch-queue results role; dashboard role scripts match the code (#1344) - #1352
Merged
Merged
Conversation
…code (#1344) - spawn launch --batch-queue without --iam-role/--instance-profile now gets a spawn-instance-* role (baseline + PutObject/AbortMultipartUpload on <result_s3_bucket>/<result_s3_prefix>/*, GetObject on schedules/*/params.yaml) instead of the shared spored-instance-role, which could not write results. - setup-dashboard-lambda-role.sh writes one idempotent inline policy scoped to every table/index/stream/bucket prefix the four dashboard Lambdas call, plus the Slack secret and WebSocket @connections grants when those exist. - setup-cross-account-role.sh: inline ec2:DescribeInstances only (was AmazonEC2ReadOnlyAccess + AmazonDynamoDBReadOnlyAccess), trust narrowed to Cognito_SpawnDashboard_Auth_Role as in production. - Dashboard terminate denied in a member account returns 403 naming `spawn terminate`; the terminate path itself is an owner decision (#1349). - Gate ledger: 13 entries removed; terminate/cancel/sts:AssumeRole now point at #1349; X-Ray left (#1344 item 1). Refs #1344 Refs #1349
scttfrdmn
force-pushed
the
fix/1344-iam-gaps
branch
from
October 27, 2026 02:23
7ab3319 to
217f8b7
Compare
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This was referenced Oct 27, 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.
Stacked on #1347: the base is its branch,
test/254-iam-drift-guard, because #1347 has not merged yet. Retarget tomainonce it merges.Refs #1344
Refs #1349
This uses Refs, not Fixes, because two of #1344's items stay open on purpose: item 1 (X-Ray) is still in the ledger, and the terminate half of item 4 needs an owner decision, filed as #1349.
What changed
Item 2, batch queue results upload.
spawn launch --batch-queuewith no--iam-roleor--instance-profilenow gets aspawn-instance-*role fromCreateOrGetInstanceProfile. That role carries the spored baseline, SSM, and thespawn:managed=truetag, so the reaper deletes it once no instance uses it (#1300). It also carriescmd.batchQueuePolicy.spored-instance-roleis unchanged. Explicit--iam-roleand--instance-profileare still attached verbatim. Aresult_s3_bucketthat is not a plain bucket name, or aresult_s3_prefixcontaining*,?or$, is refused before any AWS call.Item 3,
setup-dashboard-lambda-role.sh. It now writes one inline policy (put-role-policy, idempotent) where it used tocreate-policya managed policy that a re-run never updated. Each statement is scoped to the specific tables and indexes the code calls (see the list below). Two grants depend on deploy-time resources, so they are their own inline policies, written only when the resource exists:SLACK_SECRETS_ARNfrom the env or from the deployedspawn-dashboard-apiconfiguration;WS_API_IDfrom the env or fromapigatewayv2 get-apisby name.The script detaches the old customer-managed policy, and deletes it if nothing else has it attached.
Item 4, member-account read role (
setup-cross-account-role.sh). It now carries one inlineec2:DescribeInstances, the only EC2 call made on it, by dashboard-api and by the browser (spore-host/web/js/main.js). The script detachesAmazonEC2ReadOnlyAccessandAmazonDynamoDBReadOnlyAccess, which let every dashboard user read every EC2 resource and every DynamoDB table in the member account. The trust is narrowed fromarn:aws:iam::966362334030:rootto…:role/Cognito_SpawnDashboard_Auth_Role, which is whatcross_account.gosays the production role names.Terminate was deliberately NOT granted to the read role. Every signed-in dashboard user can assume that role directly with their Cognito credentials (the browser does). A tag-scoped terminate there would therefore let any user terminate any spore in the account and bypass the Lambda's
spawn:iam-userownership check. The sweep-cancel path has a related problem: it assumesSpawnSweepCrossAccountRole, whose trust names only the orchestrator. Both are in #1349 with three options. Until then, a denied dashboard terminate returns a 403 namingspawn terminate <id>instead of a raw 500.Item 1, X-Ray. Left in the ledger. #1337 is not on main yet, so
xray.gois still reachable.Ledger
13 entries removed:
spored run-queue×2SpawnDashboardLambdaRole×10 (everything exceptsts:AssumeRole)ec2:DescribeInstanceswildcardThree entries now point at #1349:
sts:AssumeRole,ec2:TerminateInstances,ec2:CancelSpotInstanceRequests.Gates watched failing against a compiling revert
TestEveryPrincipalCallIsGranted, run with the batch-queue write statement disabled (if false && …) and both scripts restored from the base. It reported exactly the 13 removed entries as gaps: run-queues3:PutObjectands3:AbortMultipartUpload; dashboard-apidynamodb:PutItem,dynamodb:DeleteItem,secretsmanager:GetSecretValue,s3:GetObject,s3:PutObject, andec2:DescribeInstanceson the read role; websocketdynamodb:PutItemanddynamodb:DeleteItem; processordynamodb:DeleteItemandexecute-api:ManageConnections; cost-historydynamodb:PutItem.TestBatchQueueLaunchUsesTheScopedRole(an AST check onlaunchWithBatchQueue), run withlaunch_batchqueue.gorestored. It failed with "0 calls to batchQueueInstanceProfile (want 1), 1 to SetupSporedIAMRole (want 0)".IAM statements added (for allow and deny simulation)
Batch queue role (
spawn-instance-<hash>, plus the spored baseline):s3:GetObjectonarn:aws:s3:::<schedules-bucket>/schedules/*/params.yamls3:PutObject,s3:AbortMultipartUploadonarn:aws:s3:::<result_s3_bucket>/<result_s3_prefix>/*(only when a results bucket is set)SpawnDashboardLambdaRole, inlineSpawnDashboardLambdaPolicy. T =arn:aws:dynamodb:us-east-1:<infra>:table:ec2:DescribeInstanceson*GetItem,PutItem,UpdateItem,Query,Scanon T/spawn-user-accountsand T/spawn-user-accounts/index/email-indexGetItem,Query,Scan,UpdateItem,DeleteItemon T/spawn-sweep-orchestrationand itsteam_id-indexGetItem,PutItem,UpdateItem,DeleteItemon T/spawn-teamsGetItem,PutItem,Query,DeleteItemon T/spawn-team-membershipsand itsmember_arn-indexPutItem,DeleteItemon T/spawn-ws-ticketsPutItem,DeleteItem,Scanon T/spawn-websocket-connectionsQuery,PutItemon T/spawn-cost-historyGetItem,Queryon T/lagotto-watches, itsuser_id-index, and T/lagotto-match-history/index/user_id-indexGetItem,PutItem,Scan,UpdateItemon T/spore-bot-workspacesDescribeStream,GetRecords,GetShardIteratoron T/spawn-sweep-orchestration/stream/* and T/spawn-autoscale-groups-production/stream/*dynamodb:ListStreamson*s3:GetObjectonarn:aws:s3:::strata-registry/*;s3:ListBucketonarn:aws:s3:::strata-registry;s3:PutObjectonarn:aws:s3:::strata-registry/locks/*SpawnDashboardLambdaPolicySlack:secretsmanager:GetSecretValueon<SLACK_SECRETS_ARN>.SpawnDashboardLambdaPolicyWebSocket:execute-api:ManageConnectionsonarn:aws:execute-api:us-east-1:<infra>:<ws-api-id>/production/POST/@connections/*.SpawnDashboardCrossAccountReadRole, inlineSpawnDashboardEC2ReadAccess:ec2:DescribeInstanceson*. Its trust isarn:aws:iam::966362334030:role/Cognito_SpawnDashboard_Auth_Role. No grant toward any non-spore.host account.Three grants go beyond what the gate discovers:
s3:ListBucketon the strata registry, without which a missing key is AccessDenied, not NoSuchKey, and strata's not-found mapping breaks;ListStreamson*.Deny cases worth simulating:
<prefix>/, or to another bucket;strata-registryPut outsidelocks/;TerminateInstances.Checks
make check: green apart fromcheck-build-tags, the known /private/tmp path failure, which lists only files this PR does not touch.make lint: 0 issues in all 10 modules.semgrep scan --config=auto --error .: clean.internal/iamcoverage(all tests),cmd,lambda/dashboard-apiand thescriptsgates: all pass. Both scripts are shellcheck-clean.Not verified
No AWS calls were made: nothing is simulated, PutRolePolicy-tested or deployed. Before running either script against the live roles:
The dashboard-websocket-processor stream grants are inferred from
setup-event-source-mappings.sh.