Repository navigation
fix(iam): authorize an IAM request against the entity it names (#770) - #802
Merged
Merged
Conversation
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.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
5 tasks
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.
Every IAM request was authorized against
arn:aws:iam::<account>:*— a literal*in theresource position, which no statement naming a user, a role or a path can match. A policy scoped
to
arn:aws:iam::123456789012:user/alicewas therefore inert, and so was every AWS managedpolicy for letting a user manage their own credentials: the bundled
IAMUserChangePasswordgranted 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):
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 —
AddUserToGrouppublishes onlygroup,AttachUserPolicyonlyuser—and that is read off AWS's data rather than chosen.
An IAM ARN embeds the entity's path and only the
Create*operations carryPathon the wire,so a request naming an entity costs one state read to recover it: the
iamAuthzRolePathpattern#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 theaccount 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 isdeliberately
arn:aws:iam::<account>:*and not a bare*, because a bare*in the resourceposition matches every statement — harmless for an
Allow, wrong for aDeny.The six instance-profile gates
CreateInstanceProfile,GetInstanceProfile,DeleteInstanceProfile,AddRoleToInstanceProfile,RemoveRoleFromInstanceProfileandListInstanceProfilescalled theplugin door zero times. Beyond #770's literal text, and included because
AddRoleToInstanceProfileis the classic privilege-escalation step and because "both doorsagree" cannot be asserted for
instance-profilewhile one door is not there. The test provingthem runs against a server built with no
AuthController, since with the generic gate presenta refusal proves nothing about the plugin's.
iamInstanceProfileARNjoins the four minters it should have shipped with, so the profile's ARNgoes through
normalisePathinstead of an inlinefmt.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 defaultpath, 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 testand
GOTOOLCHAIN=go1.26.6 make testgreen; coverage emulator 83.6% / total 83.0% (baseline83.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:GetUseronarn:aws:iam::123456789012:user/alice:The same script against
mainrefuses both, onarn:aws:iam::123456789012:*— the fail-before,in the opposite direction.
Closes #770.