Repository navigation
fix(iam): an entity's path is part of its ARN's name, and the caller's ARN carries it (#801) - #808
Merged
Merged
Conversation
…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 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.
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.
The defect
AWS's identifiers reference
gives an IAM entity ARN as
arn:${Partition}:iam::${Account}:user/${UserNameWithPath}— the path andthe friendly name are one component, and the name is the last segment.
parsePrincipalARNsplit the resource part on the first slash, so
arn:aws:iam::123456789012:user/division/engineering/aliceresolved to an entity named
division/engineering/alice. No such record exists, and becauseenforcement 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
resolvePrincipalbuilt the principal ARN without the entity's path, from the access key'sUserName. So a signed IAM-user call was enforced today — by accident — while publishing an ARNthat named no entity, which
aws:PrincipalArnconditions andGetCallerIdentity'sArnboth read.aws:PrincipalArnandGetCallerIdentitywrong.Both had to move together, which is what this PR does.
What reached the false allow live
CloudFormation.
cfnAttribution.resolvebuilds&Principal{ARN: a.roleARN}from the stack's--role-arnverbatim, and AWS's own console creates CloudFormation service roles at/service-role/. Every resource call such a stack made was unenforced.sts:AssumeRole.assumeRolelooked the role up by the first-slash name, so a role at any pathcould 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}— twosegments, and it excludes the role's path. So
iamEntityForPrincipalARN'sassumed-rolearmtakes 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 cannotmint (it builds one from a role name, which cannot contain a slash).
No extra state read
resolvePrincipaldocuments a two-Getcost for a signed request. The record read for the caller'saws:PrincipalTag/<key>values is now read once for both, through a newiamEntityPathAndTags, socarrying the path costs nothing. An absent record (a deleted user, a key minted before #737) yields
an empty path, which
normalisePathrenders as the same single slash the oldfmt.Sprintfwrote —so that case resolves byte-for-byte as before.
Live proof
Both directions, same script (
/tmp/live801.sh), amainbuild vs. this branch:mainsts assume-role --role-arn …:role/service-role/CfnRoleNoSuchEntityException: The role … cannot be found.arn:aws:sts::123456789012:assumed-role/CfnRole/sess1get-caller-identityas a user at/division/engineering/…:user/alice(names no entity)…:user/division/engineering/alice--role-arn'd to that role, whose policy grants no S3CREATE_COMPLETE(unenforced)ROLLBACK_COMPLETE—AccessDenied: User: …:role/service-role/CfnRole is not authorized to perform: s3:CreateBucketTests
emulator/iam_principal_path_test.gois new: 10 tests, 8 of which fail on amainbuild —including the CloudFormation false allow and the un-assumable role. The two that pass on
mainarethe allow-direction rows and the missing-record fallback, as expected.
Two deviations from the plan, both because the source disagreed with it
/. The plan said to give it a path. Doing so breaksTestCheckAccess_IAMUserChangePasswordGrantsTheCallersOwnPasswordfor the right reason — apathful 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.
IAMUserChangePassworddoes cover a pathful user. The plan said it grants themnothing on AWS either. It names two resources —
arn:aws:iam::*:user/${aws:username}andarn:aws:iam::*:user/*/${aws:username}— so it grants a pathful user their own password. Thetest,
docs/services.mdand the CHANGELOG all record the corrected reading.Verification
gofmtclean;go build,go vet,golangci-lint run ./...(0 issues);make test(race) ongo1.27.1 and go1.26.6;
make coverageat 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_ThePolicyMatcherRefusesWhatAdmitsNothingwithread tcp [::1]:… read: connection reset by peer— that is #798 reproducing verbatim, in theshared test harness and unrelated to this change; a re-run was clean. It is fixed later in this
milestone.
Compatibility
CloudFormation stack whose
--role-arnnames a role at/service-role/had every resource callallowed, and now has its policies applied.
Principal.ARN, and thereforeaws:PrincipalArnandGetCallerIdentity'sArn, now carry theentity's path. A policy matching
…:user/aliceexactly stops matching a caller at/division/engineering/— AWS's behaviour.sts:AssumeRoleon a role at a path starts working where it answered "role not found".GetCallerIdentity'sUserIdstill reports a friendly name; that divergence from AWS's documentedunique ID is fix(sts): GetCallerIdentity reports an entity name where AWS reports a unique ID #805, next in this milestone.
Closes #801