Repository navigation
fix(organizations,iam): authorize every resource a request names (#660) - #661
Merged
Merged
Conversation
organizations:MoveAccount names three resources in one body — AccountId, SourceParentId, DestinationParentId — and the Service Authorization Reference marks all three required. orgAuthzResourceID decodes a fixed member list and returns the first non-empty; a MoveAccount body has no ParentId and the two *ParentId members were not decoded at all, so the decision saw the account alone and both parent ARNs never reached it. CheckAccess now resolves a list of (ARN, tags) pairs and requires every one to allow, with each ARN matched against its own tags so a tag on the OU cannot satisfy a condition written about the account. Every service but Organizations MoveAccount returns exactly one pair, so all other decisions are unchanged.
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 #660
The defect
organizations:MoveAccountnames three resources in one request body —AccountId,SourceParentId,DestinationParentId— and substrate authorizedagainst one of them.
orgAuthzResourceIDdecodes a fixed member list(
ResourceId,PolicyId,TargetId,AccountId,OrganizationalUnitId,RootId,ParentId) and returns the first non-empty. A MoveAccount body has noParentId— it hasSourceParentId/DestinationParentId, which that struct doesnot decode at all — so the function fell through to
AccountIdand the two parentARNs never entered the decision.
Two false-allow directions, both reproduced and both now pinned by tests that fail
before this change:
[accountArn, ouArn]anddeliberately not the root allowed a move out of and into the root. The
policy read as a confinement and was not one.
Denyscoped to a parent ARN never matched, so "this account maynever leave the sandbox OU" silently did nothing.
A correction to the issue's framing, and to my own first pass: there is no
false-deny mirror. A policy naming only
[rootArn, ouArn]is denied both beforeand after, because the account is also a required resource. The new decision is
strictly stricter, never more permissive.
The change
CheckAccessresolves[]authzResource— (ARN, tags) pairs — and requires everyone to allow, identity policies and permission boundary alike. Each ARN is matched
against its own tags: one merged tag map across three resources would let a tag
on the OU satisfy a condition written about the account, which is the exact false
allow
orgAuthzResourceID's doc comment already exists to prevent.Every service except Organizations MoveAccount returns exactly one pair, so all
other decisions are byte-for-byte what they were.
addResourceTagsbecameresourceTagsFor, returning bare-keyed tags so theaws:ResourceTag/prefix isapplied once per resource rather than into a shared map;
buildConditionContexthad no remaining callers and is gone.
Ordering is fixed — account, source parent, destination parent — so the denial is
deterministic and replay-stable, and it names the resource that failed, which is
the whole diagnostic value: a caller reading
on resource: arn:…:root/o-…/r-82e5learns which ARN to add.
Why this is narrow
All 63 Organizations action blocks in the SAR markdown source were parsed:
MoveAccount is the only action with more than one asterisked (required) resource
type — 28 have exactly one, 34 have none.
AttachPolicy/DetachPolicyasterisk onlypolicy; their target types are optional, and they are deliberately unchanged —widening them would turn AWS's own single-ARN OU example into a denial.
ec2:RunInstanceshas the same shape (five asterisked types, only the instance ARNbuilt). Out of scope here; filed as a follow-up so the general machinery has a named
next caller.
Verification
gofmt -l,go build,go vet,golangci-lint run(0 issues),make test(race),make coverage(emulator 82.7%),make docs-reference docs-reference-check docs-versions,npm --prefix docs run build,go vet -C test/e2e,go test -C test/e2e.Plus a live
awsCLI run againstsubstrate server --address :4678, whichreproduced the denial naming
arn:aws:organizations::123456789012:root/o-4r8l3hgqx4/r-82e5, the allow afterwidening the policy by exactly that ARN, and the confinement holding in reverse.
Mutation testing: 7 mutants, one genuine survivor — the permission boundary
check hoisted outside the loop, so it saw only the first resource, was invisible to
every existing test. Closed by
TestOrganizations_Authz_MoveAccountBoundaryCoversEveryResource; final tally 7/7caught. (An eighth attempt was discarded as BROKEN, not a result: it left
unreachable codethatgo vetrejected.)Provenance
The required-resource asterisks are recoverable only from the SAR markdown
source — the rendered page is JS-only and the machine-readable
servicereference.us-east-1.amazonaws.comJSON omits the required flag entirely.The "the entire statement is evaluated against every resource that is required"
rule is documented for
ec2:RunInstancesand never for Organizations. AWSpublishes no MoveAccount policy example, and its nearest OU example
(
"organizations:*"on a single OU ARN) would not authorize a three-resourceMoveAccount. Whether
SourceParentIdis authorized at all is settled by observedreal-AWS behaviour — #660's
iam simulate-custom-policyrun against a liveorganization — not by any AWS document.