Skip to content

fix(organizations,iam): authorize every resource a request names (#660) - #661

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/660-moveaccount-authorizes-every-resource
Aug 16, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/660-moveaccount-authorizes-every-resource

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #660

The defect

organizations:MoveAccount names three resources in one request body —
AccountId, SourceParentId, DestinationParentId — and substrate authorized
against one of them. orgAuthzResourceID decodes a fixed member list
(ResourceId, PolicyId, TargetId, AccountId, OrganizationalUnitId,
RootId, ParentId) and returns the first non-empty. A MoveAccount body has no
ParentId — it has SourceParentId/DestinationParentId, which that struct does
not decode at all — so the function fell through to AccountId and the two parent
ARNs never entered the decision.

Two false-allow directions, both reproduced and both now pinned by tests that fail
before this change:

  1. A delegated-admin confinement policy naming [accountArn, ouArn] and
    deliberately not the root allowed a move out of and into the root. The
    policy read as a confinement and was not one.
  2. An explicit Deny scoped to a parent ARN never matched, so "this account may
    never 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 before
and after, because the account is also a required resource. The new decision is
strictly stricter, never more permissive.

The change

CheckAccess resolves []authzResource — (ARN, tags) pairs — and requires every
one 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. addResourceTags became
resourceTagsFor, returning bare-keyed tags so the aws:ResourceTag/ prefix is
applied once per resource rather than into a shared map; buildConditionContext
had 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-82e5
learns 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/DetachPolicy asterisk only
policy; 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:RunInstances has the same shape (five asterisked types, only the instance ARN
built). 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 aws CLI run against substrate server --address :4678, which
reproduced the denial naming
arn:aws:organizations::123456789012:root/o-4r8l3hgqx4/r-82e5, the allow after
widening 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/7
caught. (An eighth attempt was discarded as BROKEN, not a result: it left
unreachable code that go vet rejected.)

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.com JSON omits the required flag entirely.
The "the entire statement is evaluated against every resource that is required"
rule is documented for ec2:RunInstances and never for Organizations. AWS
publishes no MoveAccount policy example, and its nearest OU example
("organizations:*" on a single OU ARN) would not authorize a three-resource
MoveAccount. Whether SourceParentId is authorized at all is settled by observed
real-AWS behaviour — #660's iam simulate-custom-policy run against a live
organization — not by any AWS document.

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

codecov Bot commented Aug 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.48148% with 15 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/authz.go 74.57% 15 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 373d973 into main Aug 16, 2026
16 checks passed
@scttfrdmn
scttfrdmn deleted the fix/660-moveaccount-authorizes-every-resource branch August 16, 2026 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Organizations: MoveAccount does not authorize against SourceParentId/DestinationParentId, only AccountId

1 participant