Skip to content

fix(iam): batch-queue results role; dashboard role scripts match the code (#1344) - #1352

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/1344-iam-gaps
Oct 27, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/1344-iam-gaps

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Stacked on #1347: the base is its branch, test/254-iam-drift-guard, because #1347 has not merged yet. Retarget to main once 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-queue with no --iam-role or --instance-profile now gets a spawn-instance-* role from CreateOrGetInstanceProfile. That role carries the spored baseline, SSM, and the spawn:managed=true tag, so the reaper deletes it once no instance uses it (#1300). It also carries cmd.batchQueuePolicy. spored-instance-role is unchanged. Explicit --iam-role and --instance-profile are still attached verbatim. A result_s3_bucket that is not a plain bucket name, or a result_s3_prefix containing *, ? 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 to create-policy a 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:

  • the Slack secret: SLACK_SECRETS_ARN from the env or from the deployed spawn-dashboard-api configuration;
  • the WebSocket API: WS_API_ID from the env or from apigatewayv2 get-apis by 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 inline ec2:DescribeInstances, the only EC2 call made on it, by dashboard-api and by the browser (spore-host/web/js/main.js). The script detaches AmazonEC2ReadOnlyAccess and AmazonDynamoDBReadOnlyAccess, which let every dashboard user read every EC2 resource and every DynamoDB table in the member account. The trust is narrowed from arn:aws:iam::966362334030:root to …:role/Cognito_SpawnDashboard_Auth_Role, which is what cross_account.go says 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-user ownership check. The sweep-cancel path has a related problem: it assumes SpawnSweepCrossAccountRole, whose trust names only the orchestrator. Both are in #1349 with three options. Until then, a denied dashboard terminate returns a 403 naming spawn terminate <id> instead of a raw 500.

Item 1, X-Ray. Left in the ledger. #1337 is not on main yet, so xray.go is still reachable.

Ledger

13 entries removed:

  • spored run-queue ×2
  • SpawnDashboardLambdaRole ×10 (everything except sts:AssumeRole)
  • the read role's ec2:DescribeInstances wildcard

Three 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-queue s3:PutObject and s3:AbortMultipartUpload; dashboard-api dynamodb:PutItem, dynamodb:DeleteItem, secretsmanager:GetSecretValue, s3:GetObject, s3:PutObject, and ec2:DescribeInstances on the read role; websocket dynamodb:PutItem and dynamodb:DeleteItem; processor dynamodb:DeleteItem and execute-api:ManageConnections; cost-history dynamodb:PutItem.
  • TestBatchQueueLaunchUsesTheScopedRole (an AST check on launchWithBatchQueue), run with launch_batchqueue.go restored. 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):

  • Allow s3:GetObject on arn:aws:s3:::<schedules-bucket>/schedules/*/params.yaml
  • Allow s3:PutObject, s3:AbortMultipartUpload on arn:aws:s3:::<result_s3_bucket>/<result_s3_prefix>/* (only when a results bucket is set)

SpawnDashboardLambdaRole, inline SpawnDashboardLambdaPolicy. T = arn:aws:dynamodb:us-east-1:<infra>:table:

  • ec2:DescribeInstances on *
  • GetItem, PutItem, UpdateItem, Query, Scan on T/spawn-user-accounts and T/spawn-user-accounts/index/email-index
  • GetItem, Query, Scan, UpdateItem, DeleteItem on T/spawn-sweep-orchestration and its team_id-index
  • GetItem, PutItem, UpdateItem, DeleteItem on T/spawn-teams
  • GetItem, PutItem, Query, DeleteItem on T/spawn-team-memberships and its member_arn-index
  • PutItem, DeleteItem on T/spawn-ws-tickets
  • PutItem, DeleteItem, Scan on T/spawn-websocket-connections
  • Query, PutItem on T/spawn-cost-history
  • GetItem, Query on T/lagotto-watches, its user_id-index, and T/lagotto-match-history/index/user_id-index
  • GetItem, PutItem, Scan, UpdateItem on T/spore-bot-workspaces
  • DescribeStream, GetRecords, GetShardIterator on T/spawn-sweep-orchestration/stream/* and T/spawn-autoscale-groups-production/stream/*
  • dynamodb:ListStreams on *
  • s3:GetObject on arn:aws:s3:::strata-registry/*; s3:ListBucket on arn:aws:s3:::strata-registry; s3:PutObject on arn:aws:s3:::strata-registry/locks/*

SpawnDashboardLambdaPolicySlack: secretsmanager:GetSecretValue on <SLACK_SECRETS_ARN>.

SpawnDashboardLambdaPolicyWebSocket: execute-api:ManageConnections on arn:aws:execute-api:us-east-1:<infra>:<ws-api-id>/production/POST/@connections/*.

SpawnDashboardCrossAccountReadRole, inline SpawnDashboardEC2ReadAccess: ec2:DescribeInstances on *. Its trust is arn:aws:iam::966362334030:role/Cognito_SpawnDashboard_Auth_Role. No grant toward any non-spore.host account.

Three grants go beyond what the gate discovers:

  • the stream reads, which the Lambda event-source mapping needs;
  • s3:ListBucket on the strata registry, without which a missing key is AccessDenied, not NoSuchKey, and strata's not-found mapping breaks;
  • ListStreams on *.

Deny cases worth simulating:

  • the batch role writing outside <prefix>/, or to another bucket;
  • the dashboard role on any other table, or strata-registry Put outside locks/;
  • the read role TerminateInstances.

Checks

  • make check: green apart from check-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-api and the scripts gates: 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:

  • diff the live role's policies, since the role is hand-managed;
  • confirm the strata-registry bucket's owner and bucket policy;
  • confirm the production read-role trust really is the Cognito role.

The dashboard-websocket-processor stream grants are inferred from setup-event-source-mappings.sh.

@scttfrdmn
scttfrdmn changed the base branch from test/254-iam-drift-guard to main October 26, 2026 23:25
…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
@codecov

codecov Bot commented Oct 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.14286% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/launch_batchqueue.go 0.00% 6 Missing ⚠️
cmd/iam_coverage_exports.go 0.00% 1 Missing ⚠️
cmd/launch_batchqueue_iam.go 96.42% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant