Repository navigation
fix: --account / SPORE_ACCOUNT is enforced, not just accepted (#1118) - #1175
Merged
Merged
Conversation
The root --account flag ("Expected AWS account ID (optional guard)"),
SPORE_ACCOUNT and `account =` in the spore config were recorded and read
only by spawn doctor, so `spawn --account X launch` with credentials for
another account launched anyway.
pkg/config.CheckAccount now runs where credentials are resolved: every AWS
config the spawn binary builds from a credential chain is checked with STS
GetCallerIdentity (cached per access key) before it is handed out, and a
mismatch, an STS error or an empty account is a refusal naming both
accounts. Commands that build no AWS config make no STS call. A dedicated
infra profile (spawn's control-plane account) is exempt; infra through the
user's own profile and the compute profile are always checked. spawn doctor
reports the refusal as a failed account check.
Gates: a command-level test proves burst, which reaches RunInstances
through the recorder, sends no AWS request at all under a mismatch; and
TestEveryCLIConfigLoadIsAccountGuarded discovers every LoadDefaultConfig
call in the packages linked into the spawn binary (per release GOOS) and
fails if one is not guarded.
Fixes #1118
scttfrdmn
force-pushed
the
fix/1118-account-guard
branch
from
October 19, 2026 06:26
1622fd7 to
c491e64
Compare
…ndows-only module doesn't fail it
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 #1118
What was wrong
--account("Expected AWS account ID (optional guard)"),SPORE_ACCOUNTandaccount =in~/.config/spore/config.tomlall resolve intoSharedConfig().Account. Onlyspawn doctorread that value, sospawn --account 111111111111 launch …with credentials for another account launched anyway.Where the check lives, and why there
pkg/config.CheckAccount(ctx, cfg)(new filepkg/config/account_guard.go) runs at the credential roots, not in a cobra hook:spawnaws.NewClientWithRegion. This coversNewClientandcmd'sloadAWSConfig.pkg/config.LoadComputeAWSConfig, always.pkg/config.LoadInfraAWSConfig, when infra resolves through the user's own profile (see below).LoadDefaultConfigsites linked into the spawn binary:pkg/dns.NewClient, thepkg/costpricer, the X-Ray exporter,pkg/provider(ec2/local),pkg/registryandpkg/pipeline. On an instance no expected account is set, so the guard does nothing there.A config is checked before it is returned, so no command can make an AWS call with refused credentials, mutating or not. A command that never builds a config (
version,completion,help) never calls STS. A rootPersistentPreRunE(what truffle and lagotto do) would makeSPORE_ACCOUNTin a shell profile cost an STS round trip on everyspawn version. It also couldn't check the compute profile, which is a different credential set from the shared one.Semantics (matched to truffle#208 / lagotto#180)
--account 111111111111: the current AWS credentials belong to account 222222222222; refusing to continue (check --profile / SPORE_PROFILE / AWS_PROFILE). The prefix names the source:--account,SPORE_ACCOUNTor the config file. The error is typed (*AccountMismatchError).… could not determine the AWS account of the current credentials: …).GetCallerIdentityper access key per process, cached. STS getsus-east-1when no region is set.SPORE_ACCOUNTand the config file. Those two enforce only the flag, and truffle#206 leaves that question open suite-wide. spawn doctor already presented all three sources as the guard, so enforcing just one would have been a new inconsistency.The two-account model
LoadInfraAWSConfigwith a dedicated infra profile (SPAWN_INFRA_PROFILE, defaultspore-host-infra) is spawn's control-plane account, a different account by design. Guarding it would refuse every sweep/schedule/pipeline/cancel command that pins--account. It is checked only when infra resolves through the same profile as everything else (SPAWN_INFRA_PROFILE="", or equal to the shared profile), because then it is the user's account. Compute, where instances launch, is always checked. This is a judgement call; please push back if you want infra guarded unconditionally.spawn doctor
A refusal used to show up as "AWS credentials ✗ … run
aws login", which is misleading. It now renders as credentials ✓ and account ✗ with both IDs and the source, then stops instead of probing an account the user said they didn't mean. I checked this by reading the code only: doctoros.Exit(1)s on failure, so it has no command-level test here.Gates
cmd/account_guard_test.go(existing fakes:isolateAWSEnv,recordAWS,runRootForTest,burstArgs,assertBurstRegion):TestAccountGuardRefusesBeforeAnyAWSCall:spawn --account 111… burst …(and theSPORE_ACCOUNTvariant) with the lookup stubbed to222…returns anAccountMismatchErrorwith the right want/got/source, and the recorder sees zero AWS requests. burst is the commandTestBurstHonoursTheRegionFlagalready proves reachesRunInstancesthrough this recorder.TestAccountGuardLetsAMatchThrough: the same burst with a matching account reachesRunInstances.TestOfflineCommandsDoNotCallSTS:version,completion bashandhelpwith--accountmake no lookup. Subcommand help is left out deliberately, becauselaunch --helpmakes cobra add a--helpflag to launchCmd's flag set and that tripsTestEveryLaunchFlagHasAWindowsRule.account_guard_coverage_test.go(module root): the discovery gate. It runsgo list -deps -json .for each release GOOS (linux/darwin/windows) to find every spawn-module package linked into the spawn binary. In each, every SDKconfig.LoadDefaultConfigcall must either sit in a function that also callsCheckAccount, or passconfig.WithCredentialsProvider. The second case is explicit credentials, i.e. the sweep code's assumed-role credentials minted from an already-guarded config. Calls are matched by resolved import path, not text. The gate fails if it finds no loads at all.aws.Configassembled by hand (aws.Config{Credentials: …}/aws.NewConfig()) in CLI code. I found none in non-test CLI code.pkg/config/account_guard_test.go: all three sources refuse a mismatch, a match passes, it fails closed on an STS error or an empty account, no pin means no call, compute is guarded, and infra is guarded only through the shared profile. The real STS lookup (not the seam) isGetCallerIdentityagainst an STS host and is cached per access key.Watched failing against reverts that compile:
if err := error(nil); err != nil && spawnconfig.CheckAccount != nil {: the coverage gate FAILS atpkg/dns/client.go:103.NewClientWithRegion's guard replaced byfunc(context.Context, aws.Config) error { return nil }(ctx, cfg): the coverage gate FAILS atpkg/aws/client.go:92, andTestAccountGuardRefusesBeforeAnyAWSCallFAILS (both subtests). Burst went on toRunInstancesand got the recorder's 403, which is the --account / SPORE_ACCOUNT is accepted but never checked (only spawn doctor reads it) #1118 behaviour.LoadComputeAWSConfig:TestLoadComputeAWSConfig_EnforcesTheGuardFAILS and the coverage gate FAILS atpkg/config/endpoints.go:227.true: thededicated infra profilesubtest FAILS. Forcedfalse: theinfra through the shared profilesubtest FAILS.if err != nil && false):TestCheckAccount_FailsClosedFAILS (both cases).CheckAccountcall in the rootPersistentPreRunE:TestOfflineCommandsDoNotCallSTSFAILS (version, completion bash, help).CHANGELOG
I put this under
### Fixed, not### Security. The guard protects against operator error (wrong profile), not against an adversary. No trust boundary was crossed and nobody else could exploit its absence. It is a documented safety control that didn't work, which is a bug fix.Checks
GOTOOLCHAIN=go1.26.9 make check: fmt and vet (all GOOS) are clean. It stops at the known darwin-only SA4023, so I ranGOOS=linux staticcheck ./...(clean) and then the remaining steps one by one: test-hermetic, check-nested and check-tidy all pass. check-build-tags fails here exactly as it does on an unmodifiedorigin/mainworktree (I diffed the output and it is identical apart from paths), so that failure is local-only noise.semgrep scan --config=auto --erroron the changed files: clean.Docs follow-up
After release,
docs/guides/aws-auth.md(the "account guard is only partly enforced" warning) anddocs/reference/environment-variables.mdin spore-host/spore-host can say spawn enforces all three sources.