Skip to content

fix(iam): an entity's path is part of its ARN's name, and the caller's ARN carries it (#801) - #808

Merged
scttfrdmn merged 2 commits into
mainfrom
fix/801-principal-path
Sep 11, 2026
Merged

scttfrdmn merged 2 commits into
mainfrom
fix/801-principal-path

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

The defect

AWS's identifiers reference
gives an IAM entity ARN as arn:${Partition}:iam::${Account}:user/${UserNameWithPath} — the path and
the friendly name are one component, and the name is the last segment. parsePrincipalARN
split the resource part on the first slash, so arn:aws:iam::123456789012:user/division/engineering/alice
resolved to an entity named division/engineering/alice. No such record exists, and because
enforcement is opt-in by existence, a principal that resolves to nothing is governed by no policy:
every request such a caller made was allowed.

Two defects that masked each other

resolvePrincipal built the principal ARN without the entity's path, from the access key's
UserName. So a signed IAM-user call was enforced today — by accident — while publishing an ARN
that named no entity, which aws:PrincipalArn conditions and GetCallerIdentity's Arn both read.

  • Fixing the parse alone leaves aws:PrincipalArn and GetCallerIdentity wrong.
  • Fixing the ARN alone turns the accident into the false allow, for every signed call.

Both had to move together, which is what this PR does.

What reached the false allow live

CloudFormation. cfnAttribution.resolve builds &Principal{ARN: a.roleARN} from the stack's
--role-arn verbatim, and AWS's own console creates CloudFormation service roles at
/service-role/. Every resource call such a stack made was unenforced.

sts:AssumeRole. assumeRole looked the role up by the first-slash name, so a role at any path
could not be assumed at all — a hard NoSuchEntityException.

The assumed-role exception, kept deliberately

The same AWS page gives arn:aws:sts::${Account}:assumed-role/${RoleName}/${RoleSessionName} — two
segments, and it excludes the role's path. So iamEntityForPrincipalARN's assumed-role arm
takes the first segment, which is correct; it now carries the citation and a pinning test rather
than a change. assumed-role/<path>/<role>/<session> is an ARN AWS never mints and substrate cannot
mint (it builds one from a role name, which cannot contain a slash).

No extra state read

resolvePrincipal documents a two-Get cost for a signed request. The record read for the caller's
aws:PrincipalTag/<key> values is now read once for both, through a new iamEntityPathAndTags, so
carrying the path costs nothing. An absent record (a deleted user, a key minted before #737) yields
an empty path, which normalisePath renders as the same single slash the old fmt.Sprintf wrote —
so that case resolves byte-for-byte as before.

Live proof

Both directions, same script (/tmp/live801.sh), a main build vs. this branch:

main this branch
sts assume-role --role-arn …:role/service-role/CfnRole NoSuchEntityException: The role … cannot be found. arn:aws:sts::123456789012:assumed-role/CfnRole/sess1
get-caller-identity as a user at /division/engineering/ …:user/alice (names no entity) …:user/division/engineering/alice
a stack --role-arn'd to that role, whose policy grants no S3 CREATE_COMPLETE (unenforced) ROLLBACK_COMPLETE — AccessDenied: User: …:role/service-role/CfnRole is not authorized to perform: s3:CreateBucket

Tests

emulator/iam_principal_path_test.go is new: 10 tests, 8 of which fail on a main build —
including the CloudFormation false allow and the un-assumable role. The two that pass on main are
the allow-direction rows and the missing-record fallback, as expected.

Two deviations from the plan, both because the source disagreed with it

  1. iam: authorize against the resource a request names, not arn:aws:iam::<acct>:* #770's fixture caller stays at /. The plan said to give it a path. Doing so breaks
    TestCheckAccess_IAMUserChangePasswordGrantsTheCallersOwnPassword for the right reason — a
    pathful caller's own resource ARN carries the path, so user/${aws:username} does not match it —
    which would make iam: authorize against the resource a request names, not arn:aws:iam::<acct>:* #770's headline case assert this rule instead of its own. The pathful cases
    live in the new file; the fixture's comment now records the new reason.
  2. The bundled IAMUserChangePassword does cover a pathful user. The plan said it grants them
    nothing on AWS either. It names two resources — arn:aws:iam::*:user/${aws:username} and
    arn:aws:iam::*:user/*/${aws:username} — so it grants a pathful user their own password. The
    test, docs/services.md and the CHANGELOG all record the corrected reading.

Verification

gofmt clean; go build, go vet, golangci-lint run ./... (0 issues); make test (race) on
go1.27.1 and go1.26.6; make coverage at baseline (emulator 83.6%, total 83.0%);
make docs-reference docs-reference-check docs-versions authz-reference-check;
npm --prefix docs run build; go vet -C test/e2e ./... && go test -C test/e2e ./....

One go1.26.6 run failed TestConfigChannel_ThePolicyMatcherRefusesWhatAdmitsNothing with
read tcp [::1]:… read: connection reset by peer — that is #798 reproducing verbatim, in the
shared test harness and unrelated to this change; a re-run was clean. It is fixed later in this
milestone.

Compatibility

  • A caller whose IAM entity lives at a path is now enforced. The largest change: a
    CloudFormation stack whose --role-arn names a role at /service-role/ had every resource call
    allowed, and now has its policies applied.
  • Principal.ARN, and therefore aws:PrincipalArn and GetCallerIdentity's Arn, now carry the
    entity's path.
    A policy matching …:user/alice exactly stops matching a caller at
    /division/engineering/ — AWS's behaviour.
  • sts:AssumeRole on a role at a path starts working where it answered "role not found".
  • GetCallerIdentity's UserId still reports a friendly name; that divergence from AWS's documented
    unique ID is fix(sts): GetCallerIdentity reports an entity name where AWS reports a unique ID #805, next in this milestone.

Closes #801

…s ARN carries it (#801)

AWS's identifiers reference gives an IAM entity ARN as
`arn:aws:iam::{account}:user/{user-name-with-path}` — the path and the friendly
name are one component, and the name is the *last* segment. `parsePrincipalARN`
split on the first slash, so `…:user/division/engineering/alice` resolved to a
nonexistent entity named `division/engineering/alice`. Because enforcement is
opt-in by existence, a principal that resolves to nothing is governed by no
policy: every request such a caller made was allowed.

A second defect masked the first. `resolvePrincipal` built the principal ARN
without the entity's path, so a signed IAM-user call was enforced by accident
while publishing an ARN that named no entity — which `aws:PrincipalArn` and
`GetCallerIdentity` both read. Fixing the parse alone leaves those wrong; fixing
the ARN alone turns the accident into the false allow. Both move together.

Two callers reach the false allow live: CloudFormation, which builds a principal
from `--role-arn` verbatim (AWS's console creates service roles at
`/service-role/`, so such a stack's resource calls were entirely unenforced),
and `sts:AssumeRole`, which could not find a role at any path at all.

The assumed-role ARN is the documented exception —
`arn:aws:sts::{account}:assumed-role/{role-name}/{role-session-name}` has exactly
two segments and excludes the role's path — so its first-slash split is correct
and is now pinned by a test and a citation rather than changed.

`resolvePrincipal` reads no extra state: the record read for the caller's tags
now returns the `Path` beside them, so a signed request stays at two Gets.

Closes #801
@codecov

codecov Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

… distinguishes

codecov's patch gate was short of target on three added paths, each of which is
worth a test rather than a waiver:

- iamCallerUserName, the implicit UserName that GetUser, CreateAccessKey and
  ListAccessKeys document — including the end-to-end `aws iam get-user` with no
  argument as a pathful caller, and an assumed role having no implicit name.
- The ARN forms iamEntityForPrincipalARN distinguishes, pinned in both directions.
  A decision test cannot see this: an ARN resolving to nothing is *allowed*,
  exactly like one resolving to an entity a policy permits, which is what let
  #801 live.
- An entity record that cannot be decoded, on both readers of the same Get: the
  tags come out empty and the principal falls back to the path-less ARN.
@scttfrdmn
scttfrdmn merged commit 5830f6b into main Sep 11, 2026
16 checks passed
@scttfrdmn
scttfrdmn deleted the fix/801-principal-path branch September 11, 2026 23:49
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.

A caller whose IAM entity has a path is never enforced: the path is read as part of the name

1 participant