Skip to content

fix(iam): authorize an IAM request against the entity it names (#770) - #802

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/iam-per-operation-resource
Sep 11, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/iam-per-operation-resource

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Every IAM request was authorized against arn:aws:iam::<account>:* — a literal * in the
resource position, which no statement naming a user, a role or a path can match. A policy scoped
to arn:aws:iam::123456789012:user/alice was therefore inert, and so was every AWS managed
policy for letting a user manage their own credentials: the bundled IAMUserChangePassword
granted nothing at all, which #745's policy-variable substitution made visible without being
able to fix it.

What decides the resource now

A table of 59 operations, plus the three service-linked-role operations resolved separately
since #747. The citation is mechanical in both directions, read from the vendored Service
Reference Information snapshot (#797):

  • every row's resource type is one AWS publishes for that action;
  • every IAM action AWS publishes no resource types for is absent from the table;
  • every ARN substrate mints equals AWS's published format string for that type.

So a row that drifts from AWS's own data fails the build rather than quietly deciding requests
against the wrong resource. Where AWS lists several types for one action, the row names the one
the action is about — AddUserToGroup publishes only group, AttachUserPolicy only user —
and that is read off AWS's data rather than chosen.

An IAM ARN embeds the entity's path and only the Create* operations carry Path on the wire,
so a request naming an entity costs one state read to recover it: the iamAuthzRolePath pattern
#747 established, generalized to all five entity types. On a state miss the request stays on the
account path rather than being decided against an ARN that only looks specific.

Both doors call one resolver

The plugin door passed a literal "*" at 48 of its 57 gates while the generic gate answered the
account wildcard — one request, two resources, the divergence behind #411, #714 and #745 arrived
at from a third side. A table test drives both doors over every row and asserts one ARN, computed
from the fixture rather than from the resolver, so a resolver that is consistently wrong still
fails.

Five operations that name no resource keep the account wildcard, which is AWS's own answer for
them: ListUsers, ListRoles, ListGroups, ListPolicies, SimulateCustomPolicy. It is
deliberately arn:aws:iam::<account>:* and not a bare *, because a bare * in the resource
position matches every statement — harmless for an Allow, wrong for a Deny.

The six instance-profile gates

CreateInstanceProfile, GetInstanceProfile, DeleteInstanceProfile,
AddRoleToInstanceProfile, RemoveRoleFromInstanceProfile and ListInstanceProfiles called the
plugin door zero times. Beyond #770's literal text, and included because
AddRoleToInstanceProfile is the classic privilege-escalation step and because "both doors
agree" cannot be asserted for instance-profile while one door is not there. The test proving
them runs against a server built with no AuthController, since with the generic gate present
a refusal proves nothing about the plugin's.

iamInstanceProfileARN joins the four minters it should have shipped with, so the profile's ARN
goes through normalisePath instead of an inline fmt.Sprintf.

Filed, not folded in

#801 — the same divergence on the principal side: a caller whose own user or role lives at a
non-default path is not enforced at all, because a principal ARN is parsed back to a name by
reading everything after user/. The tests here authorize as a caller stored at the default
path, and say why in place, so none of them can pass vacuously.

Verification

gofmt -l ., go build ./..., go vet ./..., golangci-lint run ./... (0 issues); make test
and GOTOOLCHAIN=go1.26.6 make test green; coverage emulator 83.6% / total 83.0% (baseline
83.5% / 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 ./....

Live, with the AWS CLI against a running emulator — alice holding a customer-managed policy
allowing iam:GetUser on arn:aws:iam::123456789012:user/alice:

--- as alice: get-user --user-name alice (expect ALLOW) ---
{"User": {"Path": "/", "UserName": "alice", "Arn": "arn:aws:iam::123456789012:user/alice", ...}}
--- as alice: get-user --user-name bob (expect AccessDenied) ---
AccessDenied: User: arn:aws:iam::123456789012:user/alice is not authorized to perform:
iam:GetUser on resource: arn:aws:iam::123456789012:user/bob
--- as alice: list-users ---
AccessDenied: ... on resource: arn:aws:iam::123456789012:*

The same script against main refuses both, on arn:aws:iam::123456789012:* — the fail-before,
in the opposite direction.

Closes #770.

Every IAM request was decided against `arn:aws:iam::<account>:*`, a literal
`*` in the resource position that no statement naming a user, a role or a
path can match — so a narrowly scoped IAM statement was inert, and the
bundled IAMUserChangePassword granted nothing at all.

The resource now comes from a 59-operation table whose every row is checked
against AWS's own published data: each row's resource type is one AWS
publishes for the action, every IAM action AWS publishes no resource types
for is absent from the table, and each minted ARN matches AWS's published
format string. Both authorization doors call one resolver on the same
request, so the plugin door's 48 literal `"*"` gates and the generic gate's
account wildcard can no longer answer one request two ways.

Also adds the plugin-side gate to the six instance-profile operations, which
had none — AddRoleToInstanceProfile is the classic privilege-escalation step
— and extracts iamInstanceProfileARN so the profile's ARN is minted through
normalisePath like the other four.
@scttfrdmn scttfrdmn added this to the v0.111.0 milestone Sep 11, 2026
@codecov

codecov Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.42857% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/iam_authz_resources.go 92.30% 5 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 04a30f1 into main Sep 11, 2026
17 checks passed
@scttfrdmn
scttfrdmn deleted the feat/iam-per-operation-resource branch September 11, 2026 04:42
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.

iam: authorize against the resource a request names, not arn:aws:iam::<acct>:*

1 participant