Repository navigation
fix(organizations): a member account sees the organization it belongs to (#623, #619) - #631
Merged
Merged
Conversation
… to (#623, #619) Organizations state is keyed by the caller's account, and ensureOrganization auto-created a whole organization — root, management account, FullAWSAccess — for any account it had not seen. A member account calling any Organizations operation was therefore handed a private organization of its own, with a different o- ID, a different root, and a member list holding only itself. saveAccount now writes a member→management reverse index, and the caller's organization is resolved once at dispatch rather than per read: resolving per read would let two reads in one request disagree about which organization they concern, and would leave every future handler having to remember to do it. An account the index does not name still auto-creates its own organization, which is what keeps a fresh emulator usable with no CreateOrganization call. With the index in place, DescribeResourcePolicy answers a member the policy names with the identical Content/Id/Arn, and refuses one it does not with AccessDeniedException — 403, not the 400 every other Organizations error carries, because it is a common error the model does not declare. Put/DeleteResourcePolicy stay management-only. Delegation is decided by the Principal, not the Action: DescribeResourcePolicy appears in none of AWS's example delegation policies, so requiring an Allow for it would deny every member those examples intend to admit. Reaching a member identity at all needed a test seam, since no in-repo test could authenticate as a second account. StartTestServerWithAccounts is a separate entry point rather than an option on StartTestServer because wiring a credential registry also switches SigV4 verification on repository-wide (#630). Closes #623 Closes #619
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
Organizations state is keyed by the caller's account, and
ensureOrganizationauto-created an entire organization — root, management account,FullAWSAccess— for any account it had not seen. So a member account calling any Organizations operation was silently handed a private organization of its own: a differento-ID, a differentr-root, and a member list holding only itself. A consumer walking the hierarchy from a member credential saw an organization management had never created, and nothing in the response said so.With that fixed, #619's two remaining bullets become reachable, so both issues land together — Lane B is unreachable without Lane A's index.
How
The reverse index (#623).
saveAccountwritesmember_owner:<id>in both directions. Both writes live in that one function because every path that creates or joins an account already goes through it, so an index written by one operation and not another — worse than no index at all — is not a reachable state.Resolution happens once, at dispatch. A new
orgCallercarries a*RequestContextwhoseAccountIDhas been resolved to the management account, plus the signing account. Resolving insideensureOrganizationalone was not enough: a member'sListRootscallsloadRootdirectly and would hard-error withroot missing for account …, and two reads in one request could disagree about which organization they concern. Only the handlers that model a management-versus-member asymmetry readcallerAccount.An account the index does not name still auto-creates its own organization. That is not a fallback — it is what keeps a fresh emulator usable with no
CreateOrganizationcall, and the distinction the index preserves is "a member of that organization" versus "a member of nothing", not "known" versus "unknown".The resource-policy asymmetry (#619). Three answers, all distinguishable, which is the point of the issue — a tool must tell "nothing was delegated to me" from "something was, and I cannot read it":
ResourcePolicyNotFoundException(400)Content,Id,ArnAccessDeniedException(403)Put/DeleteResourcePolicystay management-only. Delegation is decided by thePrincipal, not theAction: every delegation policy AWS documents names the member asarn:aws:iam::<account>:root, andorganizations:DescribeResourcePolicyappears in none of theirActionlists — the delegated actions are the policy-management ones a delegated administrator goes on to call. Requiring anAllowfor the read itself would deny every member AWS's own examples intend to admit, and a guessed denial fails a request AWS accepts.A member is refused before the absence is reported, so it cannot use the operation to learn whether a policy exists at all.
Corrections to the issues' own framing
AccessDeniedExceptionis 403, not 400. Every other Organizations error substrate emits is 400 viaorgErr. This one is a common error the service model does not declare, and the API Reference's Common Errors page gives it 403 — which is what an SDK's retry classifier reads. It builds an*AWSErrordirectly rather than going throughorgErr.The test seam
No in-repo test could authenticate as a second account:
StartTestServerwires noCredentialRegistry, andextractAccountmaps everyAKIA…key to123456789012. That is precisely why #623 survived every Organizations test — all of them are one caller by construction.StartTestServerWithAccountsis a separate entry point rather than an option onStartTestServer, because wiring a registry also switches SigV4 verification on: the server verifies signatures exactly whenServerOptions.Credentialsis non-nil, and a key the registry does not hold isInvalidClientTokenId403. Turning that on repository-wide inside a feature change is not a trade worth making. Decoupling the two is #630. It takestesting.TBfrom the outset so #605 gets smaller rather than more conflicted.Keys and secrets are derived from the account ID rather than generated, so a recorded run replays with the same credentials in it.
Verification
make test(race detector) — green;golangci-lint run ./...— 0 issues;gofmt/go vetclean.resolveOrgCaller→ 3 tests failsaveAccount→ 4 tests failorgPolicyDelegatesToforced true → the asymmetry test failsCompatibility
A member account calling Organizations no longer receives a private organization of its own. A fixture that relied on that isolation will now see management's
o-/r-IDs and its member list. This affects only a test that authenticates as an account Organizations vended, which was not possible before this change.Closes #623
Closes #619