Skip to content

fix(organizations): a member account sees the organization it belongs to (#623, #619) - #631

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/623-member-organization-view
Aug 14, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/623-member-organization-view

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

What

Organizations state is keyed by the caller's account, and ensureOrganization auto-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 different o- ID, a different r- 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). saveAccount writes member_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 orgCaller carries a *RequestContext whose AccountID has been resolved to the management account, plus the signing account. Resolving inside ensureOrganization alone was not enough: a member's ListRoots calls loadRoot directly and would hard-error with root 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 read callerAccount.

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 CreateOrganization call, 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":

Caller Answer
Management the policy, or ResourcePolicyNotFoundException (400)
A member the policy names the identical Content, Id, Arn
A member it does not name AccessDeniedException (403)

Put/DeleteResourcePolicy stay management-only. Delegation is decided by the Principal, not the Action: every delegation policy AWS documents names the member as arn:aws:iam::<account>:root, and organizations:DescribeResourcePolicy appears in none of their Action lists — the delegated actions are the policy-management ones a delegated administrator goes on to call. Requiring an Allow for 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

  • AccessDeniedException is 403, not 400. Every other Organizations error substrate emits is 400 via orgErr. 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 *AWSError directly rather than going through orgErr.
  • "A caller outside the organization" is not reachable through this API. None of the three resource-policy operations takes an input naming an organization, so there is nowhere to put another organization's ID. The reachable third case is a member the policy does not name, which is what is modelled.

The test seam

No in-repo test could authenticate as a second account: StartTestServer wires no CredentialRegistry, and extractAccount maps every AKIA… key to 123456789012. That is precisely why #623 survived every Organizations test — all of them are one caller by construction.

StartTestServerWithAccounts is a separate entry point rather than an option on StartTestServer, because wiring a registry also switches SigV4 verification on: the server verifies signatures exactly when ServerOptions.Credentials is non-nil, and a key the registry does not hold is InvalidClientTokenId 403. Turning that on repository-wide inside a feature change is not a trade worth making. Decoupling the two is #630. It takes testing.TB from 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 vet clean.
  • Five new tests, including the storage-layer index assertions and the only Organizations test file that signs its requests (the SigV4 algorithm is reimplemented in the test rather than called into, so a mistake in substrate's own signing cannot make it pass by agreeing with itself).
  • Mutation-tested, all CAUGHT:
    • resolution dropped from resolveOrgCaller → 3 tests fail
    • the index write dropped from saveAccount → 4 tests fail
    • orgPolicyDelegatesTo forced true → the asymmetry test fails

Compatibility

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

… 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

codecov Bot commented Aug 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.48387% with 18 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/testing.go 82.85% 3 Missing and 3 partials ⚠️
emulator/organizations_plugin.go 76.47% 2 Missing and 2 partials ⚠️
emulator/organizations_resourcepolicy.go 87.87% 2 Missing and 2 partials ⚠️
emulator/organizations_state.go 66.66% 2 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit cc43f68 into main Aug 14, 2026
13 checks passed
@scttfrdmn
scttfrdmn deleted the fix/623-member-organization-view branch August 14, 2026 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant