Repository navigation
fix(iam): an IAM entity belongs to an account, not to the emulator (#737) - #769
Merged
Merged
Conversation
) Every IAM state key was account-blind, so one server held one IAM directory no matter how many accounts it served: two accounts could not both hold a role called "deploy", a listing reported every account's entities, and resolveIAMEntity discarded the account in the principal ARN it was handed. Every key now reads {kind}:{account}/{rest}, the shape DynamoDB and the other account-aware plugins already used, with the account after the kind so a per-account listing is one prefix scan. The account comes from the ARN wherever an ARN is the authority — the principal ARN for resolution and simulation, RoleArn's own account for AssumeRole, a policy ARN's account for the policy record. accesskey:{id} keeps no account deliberately: the ID determines the account, so the record carries it as a field instead.
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.
What
Every IAM state key was account-blind — a user at
user:{name}, a role's attachments atrole_policies:{name}— so one server held one IAM directory no matter how many accounts it served. Every key now reads{kind}:{account}/{rest}, the shapetable:{account}/{name}and the other account-aware plugins already used.The account goes after the kind so a per-account listing stays one prefix scan (
List("user:111122223333/")) rather than a full sweep and filter, and so aHasPrefix(key, "user:")test on the kind keeps working unchanged.Three observable defects, all fixed
Confirmed live against a two-account
credentials:block (#736), before and after:CreateRole deployin a second accountEntityAlreadyExistsarn:aws:iam::444455556666:role/deployListUsersas B after A createsalice["alice"][]ListPolicies --scope Localas B after A createsp1[]The third was a standalone bug:
ListPoliciesscanned"policy:"across every account although a policy ARN already named its owner.Where the account comes from
The ARN, wherever an ARN is the authority — never the request:
resolveIAMEntityandSimulatePrincipalPolicytake it from the principal ARN, so a cross-account principal resolves against its own account's policies rather than a same-named entity in the account the request resolved to.AssumeRolereads the role named byRoleArnfrom that ARN's account. Keying it on the caller's account would have broken the exact case cross-account assumption exists for.iamEntitygained anAccountfield for this: it is part of the entity's identity, not context about the request.The one key with no account
accesskey:{id}keeps none, and cannot have one: an access key ID is what determines an account, soresolvePrincipallooks the record up before any account is known. The account is a field onIAMAccessKeyinstead — which makes this a schema change rather than a key rename — andresolvePrincipalnow returns it as an account to adopt, the same way the STS-session arm already did withsess.AccountID. A record written before this release has the field empty and falls back to the account the request resolved to, which is the account it always used.Why the builders
The ~90 sites that concatenated these strings inline now go through
emulator/iam_state_keys.go. A missed site is invisible — it compiles, it reads and writes state, and it simply addresses a key nothing else uses — so every conversion was an exact literal match with a required occurrence count, and two mismatches caught sites an earlier grep had missed.Two sites were invisible to a grep for
iamNamespaceat all, because they spelled the namespace"iam"as a literal insideStackDeployer's drift comparison.One thing the plan flagged as a hazard turned out to be dead code:
scanIAMEntities'ContainsAny(TrimPrefix(k, "user:"), ":")guard claimed to filter index keys out of aList("user:"), but"user_policies:"never had theuser:prefix, so it never fired. Deleted with a comment saying so, rather than "fixed".Tests
emulator/iam_account_scope_test.gois new and is the fail-before proof — all four tests fail onmain:TestIAM_TwoAccountsHoldTheSameNames— user, role, group, instance profile and policy created in both accountsTestIAM_ListsSeeOnlyTheCallersAccount— five listings, 1 for A and empty for BTestIAM_ReadsDoNotCrossAccounts—GetRole/DeleteRolefrom B answerNoSuchEntityand A's role survivesTestIAM_InlineAndAttachedPoliciesAreScopedThe ~30 existing test sites that hardcoded a key now call
Xxx…ForTestbuilders exported fromexport_test.go, so when the layout changes again the tests move with the production code instead of drifting into addressing keys nothing reads.Compatibility
IAM state written before this release is unreachable. A snapshot or exported fixture holding
user:aliceis not read by a handler now looking foruser:123456789012/alice. Re-seed it through the API. This is the same class of break as v0.108.0's account-default change, for the same reason, and is recorded indocs/services.md.The
Markera paginated IAM listing returns is base64 of a state key, so a marker captured before this release does not match after it. It is opaque and per-listing, so nothing carries one across an upgrade.Verification
Closes #737