Repository navigation
test(iam): one coverage gate for every spore.host principal's AWS calls (#254) - #1347
Merged
Merged
Conversation
…ls (#254) internal/iamcoverage type-checks each principal's program, builds its call graph (RTA then VTA), discovers every AWS SDK operation reachable from its entry points, maps each to its IAM action, and fails unless the policy spore.host provisions for that role grants it by name. Wildcards never count; unmapped operations fail; every main package must be a registered principal; a ledger of known gaps (#1344) fails when an entry goes stale. pkg/reaperiam's drift gates use the same discovery instead of a regex. docs/reference/cli-iam-actions.md is the CLI's per-command inventory, generated by make cli-iam-actions (#610). Grants the gate found missing and that are clearly intended: sweep cross-account role DescribeAvailabilityZones + tag-scoped DeletePlacementGroup; pipeline-orchestrator SNS + DescribeInstanceTypes; s3:AbortMultipartUpload beside every generated s3:PutObject.
scttfrdmn
force-pushed
the
test/254-iam-drift-guard
branch
from
October 27, 2026 01:15
bb112ba to
b738f8f
Compare
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
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 #254
Refs spore-host/spore-host#610 (part 4, the CI gate; this PR does not close it)
What this does
There is now one mechanism,
internal/iamcoverage, that holds every role spore.host provisions to the AWS calls its code actually makes.Discovery. It works from the code, not from a list.
main,initand every handler passed toaws-lambda-go, then refines the result with VTA. Without VTA, oneio.Readermakes everyReadin the program reachable from everything.Opwhose signature takes a*svc.OpInput. Paginators and waiters are recognised by their<Op>APIClientparameter, and presigners by their name.stscreds.NewAssumeRoleProvider, andv4.Signer.SignHTTP. ForSignHTTPthe signing service must be a constant, andlambdamaps tolambda:InvokeFunctionUrl.pkg/bucketsweep,pkg/instancerole,pkg/spotrequest, truffle and strata. The old reaper regex missed all of these.Mapping. An SDK package goes to its IAM prefix through a closed table, and an unknown package fails. An operation goes to its actions through an exceptions table: S3
HeadBucket→ListBucket,DeleteBucketTagging→PutBucketTagging, the multipart family→PutObject,lambda:Invoke→InvokeFunction,PostToConnection→execute-api:ManageConnections,sts:GetCallerIdentity→nothing, and so on. Anything not listed maps to itself, so a wrong guess fails closed.Policies. These are read from what spore.host actually provisions:
SporedBaselinePolicyDocument,SporedInstanceRolePolicyDocument,PoolWorkerPolicy,StageDataPolicy,TaskRunPolicyFor,ScanSelfPolicyDocument.!Ifbranches and SAM policy templates. The SAM templates' action lists were copied from samtranslator 1.170.0, not from memory.put-role-policyheredocs in deploy scripts.Each principal declares its credential contexts. For example, the reaper's route53, sts and dynamodb calls run on its own role, and its ec2, fsx, ssm, s3 and iam calls run on the target-account role. A principal can also have several role variants, such as spored under
spored-instance-roleor under aspawn-instance-*role, and each variant must cover the calls on its own.The gate fails when:
*,s3:*,ec2:Describe*orNotAction); wildcards are reported separately and never count;knownGapsentry is no longer a gap.pkg/reaperiam's drift gates (TestPolicyCoversEveryReaperAPICalletc.) now use this discovery instead of their regex.grantedElsewhereis now checked in both directions, against the template and against the calls.CLI inventory (#610's other half).
docs/reference/cli-iam-actions.mdis generated bymake cli-iam-actions. It walks the live cobra tree, matches each command'sRunEto its SSA function by declaration position, and inventories it for darwin, linux and windows. It covers 122 runnable commands and 152 distinct actions, plus an "outside any command" section, which is shell completion'sec2:DescribeInstances.TestCLIActionInventoryIsCurrentfails when the committed copy is stale. The umbrella docs can consume it as-is.Gaps found
Principals checked: spored core (2 role variants), spored pool-worker, run-pipeline-stage, provenance (task and pool roles), run-queue, ttl-reaper (base role plus 3 target-account variants), sweep-orchestrator (function role and member role), scheduler-handler, dns-updater (
deploy-custom-dns.shrole), pipeline-orchestrator, dashboard-api (function role and member read role), dashboard-websocket, dashboard-websocket-processor and cost-history-collector. The alert Lambdas no longer exist (#783, #794).Fixed here (each is intended by the code and scoped):
SpawnSweepCrossAccountRoleec2:DescribeAvailabilityZonesscripts/setup-sweep-cross-account-role.shec2:DeletePlacementGroupspawn-mpi-*placement groups are never cleaned up at sweep endspawn:managed=truesns:CreateTopic,sns:Subscribe,sns:ListSubscriptionsByTopic,sns:Publishlambda/pipeline-orchestrator/template.yaml, onspawn-pipeline-*topicsec2:DescribeInstanceTypess3:AbortMultipartUploadtaskiam.ObjectWriteActions, used beside every generateds3:PutObject(taskiam,StageDataPolicy,poolWorkerPolicy)Left for you to decide. These are recorded in
internal/iamcoverage/gaps_test.goand filed as #1344 with evidence:xray:PutTraceSegments, on both role variants. Tracing is opt-in, off by default, andspawn launchcannot set it.spored-instance-role:s3:PutObjectands3:AbortMultipartUpload. A--batch-queuelaunch without--iam-rolecannot upload its results. This is a Sizing: on a price tie, prefer the smallest type that fits (hpc7g cpu=16 → hpc7g.16xlarge) #610 violation.SpawnDashboardLambdaRole(setup-dashboard-lambda-role.sh) is far behind the code. It is missing dynamodbPutItem/DeleteItem(4 Lambdas),secretsmanager:GetSecretValue,s3:GetObject/PutObject(strata registry),sts:AssumeRoleandexecute-api:ManageConnections. The live role is hand-managed.ec2:TerminateInstancesandCancelSpotInstanceRequests.The reaper, scheduler-handler and dns-updater are clean.
Watched failing (compiling reverts)
p.ec2Client.DescribeImages(...)toEC2Provider.Stop; it builds.TestEveryPrincipalCallIsGrantedfailed for both spored role variants, naming the site and the call chainrunDaemon -> Monitor -> checkAndAct -> ... -> Stop.r53.ListHostedZones(...)to the reaper'sconfigure(it builds) and addedAction: 'route53:*'to the SAM function policy. The gate failed with "only a wildcard in template.yaml#TTLReaperFunction matches it, and a wildcard does not count".pkg/reaperiam'sTestPolicyCoversEveryReaperAPICallandTestCrossAccountRoleCoversEveryReaperAPICallalso failed.Policy.GrantsreturnExactfor globs, andTestAWildcardNeverSatisfiesTheGatefailed on all four forms.TestDiscoversEveryShapeOfCallfailed (direct, method-value and transfer-manager calls disappeared).sts:GetCallerIdentityfrom the exceptions table, and both the fixture and mapping tests failed.TestEveryMainPackageIsAPrincipalnamed the unregisteredlambda/cost-history-collector.Checks
make check,make lint(0 issues),semgrep scan --config=auto --error .(clean),make api-snapshot(two additions in pkg/aws), andmake check-tidyall pass. The new package andpkg/reaperiamalso pass under the hermetic wrapper.Notes / limits
GOPROXY=off), so their deps must be cached before the root tests run.internal/iamcoverageis skipped on Windows, with the reason recorded inwindows-test-skips.txt. It analyses all GOOS builds from Linux.-short, because it is the gate.iam:PassRolefor RunInstances ors3:PutObjectTaggingfor tagged uploads, and it does not seeaws s3 cpin shell. These limits are listed in IAM coverage gaps found by the #254 gate: dashboard role script, batch-queue results upload, spored X-Ray, dashboard terminate #1344.s3:AbortMultipartUploadchanges the policy hash, so the first launch after upgrade creates newspawn-instance-*roles. That is in the CHANGELOG, including how the old roles get removed.aws.SporedBaselinePolicyDocument,aws.SporedInstanceRolePolicyDocument,cmd.PoolWorkerPolicy,cmd.RootCommand,taskiam.ObjectWriteActions.