Repository navigation
fix(parser,config): one server serves one account (#734) - #740
Merged
Merged
Conversation
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
6 tasks
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.
Closes #734
The defect
ParseAWSRequestdecided the account from the shape of the access key.extractAccountreturned123456789012iff the key began withAKIA, and000000000000otherwise — so substrate's own documentedtest/test, an unsigned request, and anASIAsession key all landed in a different account fromAKIAIOSFODNN7EXAMPLE. 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 under123456789012". That is refuted: both readRequestContext.AccountIDand always have — IAM throughiamUserARNand friends, authorization atauthz.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
ec2AuthzAccountas evidence that "the rest of the emulator uses123456789012". 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:
123456789012account.defaultinsubstrate.yamlCredentialRegistryentryAssumeRolemintedThe session record is last because it is the only thing that can know the account a cross-account
AssumeRolelanded in: a temporary credential's account is recorded when the session is minted and appears nowhere on the wire.extractAccountandfallbackAccountIDare deleted, along with the duplicateseedSSMAccountID.Config.Validaterefuses anaccount.defaultthat 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
defaultAccountIDitself. That is stronger than "no000000000000" — a second literal123456789012would 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 keepsshardId-000000000000and MSK's UUID fragments out of it.It catches the one genuine offender:
ListEventBusesreturnedarn: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:GetCallerIdentityis 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
awsCLI, every EventBridge call answeredServiceNotAvailable: service not emulated: awsevents. The target prefix in EventBridge's model isAWSEvents, notAmazonEventBridge, 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-urlthe host islocalhostandX-Amz-Targetis the only signal.So the plugin was registered, green, and unreachable — the #561/#580 failure mode — which means
ListEventBusesreturning 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-identityunderAKIAIOSFODNN7EXAMPLEand undertest/test→ both123456789012,arn:aws:iam::123456789012:rootdynamodb create-tableastest/test, thenlist-tablesanddescribe-tableasAKIAIOSFODNN7EXAMPLE→ the table is there (two accounts before)resourcegroupstaggingapi get-resources→arn:aws:dynamodb:us-east-1:123456789012:table/probeevents list-event-busesinus-east-1andeu-west-1→arn:aws:events:{region}:123456789012:event-bus/default, both fields the caller'siam create-useras one credential,get-useras the other → the samearn:aws:iam::123456789012:user/probe-useraccount.default: "555566667777"→ STS, EventBridge, IAM, the tagging API and a CloudFormationStackIdall move togetheraccount.default: "12345"→substrate: load config: account.default "12345" is not valid; an AWS account ID is 12 digitsMutation check: reintroducing the
000000000000literal inlistEventBusesturns 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.Credentialsincmd/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 ons.opts.Credentials != nil. So the shippedsubstrate serverwould start answeringInvalidClientTokenId403 to thetest/testcredentials 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'scredentials:andauth:sections are marked as not-yet-read rather than left reading as though they work (#736).Deliberately out of scope, each documented and filed
user:{name}, no account), soresolveIAMEntitystill resolves an entity by name across accounts — the "works by accident" the issue correctly identifies. iam: state keys are account-blind, so an entity resolves by name across accounts #737.substrate.yaml'scredentials:andauth:sections are still not parsed byConfig. config: substrate.yaml's credentials: and auth: sections are documented but never parsed #736.DynamoDBTable.TableARNserializes under the wrong wire name (TableArnon AWS), found while writing the live script. dynamodb: TableArn is serialized as TableARN, so every SDK reads it as absent #738.Compatibility
Every ARN returned to an unsigned or non-
AKIAcaller changes account, so a fixture asserting on000000000000now sees123456789012. 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 setaccount.default: "000000000000"to read it back.Verification
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
AKIAsniff as their way of being two callers now wire a realCredentialRegistryand sign genuine SigV4 signatures as an explicitly named second account, leaving the other caller unsigned — which still reaches its plugin as the default account, becauseVerifySigV4passes a request with noAuthorizationheader.