Skip to content

fix(parser,config): one server serves one account (#734) - #740

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/734-single-account
Aug 22, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/734-single-account

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #734

The defect

ParseAWSRequest decided the account from the shape of the access key. extractAccount returned 123456789012 iff the key began with AKIA, and 000000000000 otherwise — so substrate's own documented test/test, an unsigned request, and an ASIA session key all landed in a different account from AKIAIOSFODNN7EXAMPLE. One process served two accounts, chosen by which of two documented credentials the client happened to pick, and nothing on the wire told a caller which one they had.

The reporter hit it by using two credentials in one live run.

A correction to the issue body

The issue diagnoses this as "the IAM plugin mints ARNs under 000000000000; the authorization path builds ARNs under 123456789012". That is refuted: both read RequestContext.AccountID and always have — IAM through iamUserARN and friends, authorization at authz.go. The split was upstream of both, in the parser, which is why it reached every service at once and why fixing either plugin would have fixed nothing.

The issue also cites ec2AuthzAccount as evidence that "the rest of the emulator uses 123456789012". That is a test constant, not production code. The conclusion was right for the wrong reason.

The fix

One account, resolved in one place, in one order — each step knowing strictly more than the one above it:

Source When it applies
123456789012 Always, as the starting point
account.default in substrate.yaml Whenever set and 12 digits
A CredentialRegistry entry When signed with a key the registry holds
An STS session record When signed with credentials AssumeRole minted

The session record is last because it is the only thing that can know the account a cross-account AssumeRole landed in: a temporary credential's account is recorded when the session is minted and appears nowhere on the wire.

extractAccount and fallbackAccountID are deleted, along with the duplicate seedSSMAccountID. Config.Validate refuses an account.default that is not 12 digits rather than letting a typo through to every ARN the server mints.

Two tests, doing different jobs

The tripwire parses every non-test Go file and fails on any string literal carrying an account-shaped run of twelve digits, with exactly one exemption: the declaration of defaultAccountID itself. That is stronger than "no 000000000000" — a second literal 123456789012 would be just as wrong, because the property this buys is that the account is resolved in one place and overridable. A digit run bounded by anything other than :, / or the end of the string is not an account, which keeps shardId-000000000000 and MSK's UUID fragments out of it.

It catches the one genuine offender: ListEventBuses returned arn:aws:events:us-east-1:000000000000:event-bus/default, ignoring both of its request context's fields.

The agreement test asks three services who the caller is and compares the answers, for two accounts — because a producer that returns a constant agrees with itself. The three are not arbitrary: sts:GetCallerIdentity is the only operation whose whole purpose is to answer the question, the CloudFormation deployer mints a stack ARN from an identity it carries separately (#517's split), and the Resource Groups Tagging API reaches a DynamoDB table through an account-prefixed state key — so its answer proves the account the write used and the account the read used are the same string, which is the failure mode that leaves a resource created and then invisible.

A second defect the live run found

Verifying the above with the aws CLI, every EventBridge call answered ServiceNotAvailable: service not emulated: awsevents. The target prefix in EventBridge's model is AWSEvents, not AmazonEventBridge, and only the host alias (events.* → eventbridge) was registered. That is enough on a real endpoint and useless on the one way substrate is actually reached: with --endpoint-url the host is localhost and X-Amz-Target is the only signal.

So the plugin was registered, green, and unreachable — the #561/#580 failure mode — which means ListEventBuses returning the wrong account had never been observable in the first place. Aliased, with a three-path test mirroring Config's. A systematic sweep of the other 66 plugins is filed as #739.

Live verification

Against a built binary, substrate server --address :4678:

  • sts get-caller-identity under AKIAIOSFODNN7EXAMPLE and under test/test → both 123456789012, arn:aws:iam::123456789012:root
  • dynamodb create-table as test/test, then list-tables and describe-table as AKIAIOSFODNN7EXAMPLE → the table is there (two accounts before)
  • resourcegroupstaggingapi get-resources → arn:aws:dynamodb:us-east-1:123456789012:table/probe
  • events list-event-buses in us-east-1 and eu-west-1 → arn:aws:events:{region}:123456789012:event-bus/default, both fields the caller's
  • iam create-user as one credential, get-user as the other → the same arn:aws:iam::123456789012:user/probe-user
  • restarted with account.default: "555566667777" → STS, EventBridge, IAM, the tagging API and a CloudFormation StackId all move together
  • account.default: "12345" → substrate: load config: account.default "12345" is not valid; an AWS account ID is 12 digits

Mutation check: reintroducing the 000000000000 literal in listEventBuses turns the tripwire red at the exact line, and reverting it green.

A deviation from the approved plan, stated plainly

The plan's PR 1 specified wiring ServerOptions.Credentials in cmd/substrate/main.go, as half of #630. I did not, and I think the plan was wrong here.

Wiring a registry also switches SigV4 enforcement on: server.go's step 1.5 (registry account lookup) and step 1.6 (signature verification) both gate on s.opts.Credentials != nil. So the shipped substrate server would start answering InvalidClientTokenId 403 to the test/test credentials substrate documents — a regression far larger than the gap it closes. And the plan's justification for the wiring was that the binary is "permanently stuck on the sniff", which stops being true the moment the account comes from config, as it now does.

#630 stays open and is commented rather than closed; the decoupling is the real work. substrate.yaml.example's credentials: and auth: sections are marked as not-yet-read rather than left reading as though they work (#736).

Deliberately out of scope, each documented and filed

Compatibility

Every ARN returned to an unsigned or non-AKIA caller changes account, so a fixture asserting on 000000000000 now sees 123456789012. Several plugins prefix their state keys with the account (table:{account}/{name}, instance:{account}/{id}), so persisted SQLite state written under the old account is unreachable after upgrading: re-seed it, or set account.default: "000000000000" to read it back.

Verification

gofmt -l .                          clean
go build ./... && go vet ./...      clean
golangci-lint run ./...             0 issues
make test                           ok (race)
make coverage                       emulator 83.3%, total 82.6%
make docs-reference{,-check} docs-versions   clean
npm --prefix docs run build         clean; no dangling in-page anchors
go vet -C test/e2e ./... && go test -C test/e2e ./...   ok

Roughly 268 occurrences across 62 test files moved to the single account. A dozen asserted the split as the contract and were rewritten rather than replaced: four test files that used the AKIA sniff as their way of being two callers now wire a real CredentialRegistry and sign genuine SigV4 signatures as an explicitly named second account, leaving the other caller unsigned — which still reaches its plugin as the default account, because VerifySigV4 passes a request with no Authorization header.

ParseAWSRequest decided the account from the shape of the access key: a key
beginning with "AKIA" was attributed to 123456789012, and everything else —
substrate's own documented test/test, an unsigned request, an ASIA session key —
to 000000000000. One substrate process served two accounts, chosen by which of
two documented credentials the client happened to pick, and nothing on the wire
told a caller which one they had.

The issue diagnosed this as the IAM plugin and the authorization path
disagreeing about a constant. That is refuted: both read
RequestContext.AccountID and always have. The split was upstream of both, in the
parser, which is why it reached every service at once.

The account now comes from one place, in one order, each step knowing more than
the last: the built-in default, then account.default from substrate.yaml, then a
CredentialRegistry entry, then an STS session record — the last being the only
thing that can know the account a cross-account AssumeRole landed in.
extractAccount and fallbackAccountID are gone, with the duplicate
seedSSMAccountID.

A test parses every non-test Go file and fails on any string literal carrying an
account-shaped run of twelve digits, exempting only the declaration of the
default itself. It caught ListEventBuses returning
arn:aws:events:us-east-1:000000000000:event-bus/default, ignoring both of its
request context's fields. A second test asks three services who the caller is —
GetCallerIdentity, the CloudFormation deployer's stack ARN, and a DynamoDB table
reached through the tagging API's account-prefixed state key — and compares the
answers, for two accounts.

Verifying that live with the aws CLI turned up a second defect: every
EventBridge call answered ServiceNotAvailable. The target prefix in
EventBridge's model is AWSEvents, not AmazonEventBridge, and only the host alias
was registered — enough on a real endpoint, useless with --endpoint-url where
the host is localhost. So the wrong-account bug had never been observable.
Aliased, with a three-path routing test.

Deliberately not covered, documented and filed: IAM's account-blind state keys
(#737), substrate.yaml's unparsed credentials:/auth: sections (#736), and the
registry still not wired into cmd/substrate/main.go — wiring one also switches
SigV4 enforcement on and would 403 substrate's own documented credentials
(#630).

Closes #734
@codecov

codecov Bot commented Aug 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.88889% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/config.go 66.66% 1 Missing and 1 partial ⚠️
emulator/servicequotas_plugin.go 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 569cc16 into main Aug 22, 2026
16 checks passed
@scttfrdmn
scttfrdmn deleted the fix/734-single-account branch August 22, 2026 17:56
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.

iam: CreateUser mints ARNs under account 000000000000 while authorization uses 123456789012

1 participant