Skip to content

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

Closed

Description

@scttfrdmn

AuthController.buildResourceARNs' iam arm returns a flat arn:aws:iam::<account>:* for
every IAM operation (emulator/authz.go, the req.Service == "iam" arm reached from
buildResourceARN). Whatever the request names — a user, a role, a policy, an instance
profile — the resource substrate authorizes against is a bare wildcard scoped to the account.

That is wrong in the safe direction for a broad statement and wrong in the unsafe direction
for a narrow one: a policy whose Resource is arn:aws:iam::123456789012:user/alice cannot
match arn:aws:iam::123456789012:*, so the statement grants nothing; and a NotResource or a
negated tag condition scoped the same way excludes nothing. Both are the pattern the bundled
AWS managed policies use.

It became observable with #745. Policy-variable substitution now resolves
IAMUserChangePassword's arn:aws:iam::*:user/${aws:username} to
arn:aws:iam::*:user/alice — the correct ARN — and the statement still grants nothing,
because there is no user-shaped resource on the request side to match it. The variable was
never the only thing missing.

docs/services.md states this under the policy-variables section, so a reader is not left
assuming the bundled policy works.

#747 mints the service-linked-role ARN it needs and no more, deliberately: the general
per-operation IAM resource is its own piece of work.

What this needs

A per-operation resource derivation for iam:, in the shape the ec2 and s3 arms already have:
the operation's own parameter (UserName, RoleName, PolicyArn, InstanceProfileName,
GroupName, PolicyName for an inline policy, …) resolved to the ARN AWS documents for that
resource type in the Service Authorization Reference. Operations AWS documents as not
supporting resource-level permissions — ListUsers, ListRoles, and the rest of the account-wide
listings — keep *, and that has to be read off AWS's own table rather than guessed, since a
narrowed resource on an operation AWS scopes to * is a refusal substrate would be inventing.

Both IAM authorization doors must agree. IAMPlugin.authorize passes "*" at all 37 of its
call sites, so narrowing only buildResourceARNs reproduces the one-ARN-two-answers class of
#411 and #714 in reverse — CheckAccess refuses and the handler allows, or the other way round.

Acceptance criteria

  • A test asserts IAMUserChangePassword lets alice change her own password and refuses
    bob's, end to end through CheckAccess, with no hand-written policy
  • Each IAM resource type substrate models resolves to the ARN the Service Authorization
    Reference documents for it, cited per type
  • Operations AWS documents as *-only stay *, with the citation
  • IAMPlugin.authorize's 37 call sites name the same resource as buildResourceARNs, or
    the divergence is stated and tested
  • docs/services.md replaces the "filed on its own" note with what now resolves

Activity

  1. added this to the v0.111.0 milestone on Sep 11, 2026
  2. scttfrdmn commented on Sep 11, 2026

    @scttfrdmn
    OwnerAuthor

    Scheduled for v0.111.0. A full inventory of the second door first, because the sizing in the issue
    body is low and one of the resource types has no door at all.

    IAMPlugin.authorize has 49 call sites, not 37. authorize (emulator/iam_plugin.go:1544-1548)
    is a shim over authorizeWith (:1564-1724), whose resource argument reaches only
    EvaluationRequest.Resource at :1682 and :1706.

    count
    p.authorize( sites 49 — iam_plugin.go 37, iam_groups.go 6, iam_simulate.go 2, iam_policy_versions.go 2, iam_list_policies.go 1, iam_slr_handlers.go 1
    of those, passing a literal "*" 48 (the exception is iam_slr_handlers.go:291, which computes one)
    authorizeWith sites already passing a real ARN 2 — iam_slr_handlers.go:113, :194 (#747)
    distinct operations behind them ~66 — six handlers are polymorphic and fan out to 16 operations

    The 37 in the doc comment at iam_plugin.go:1561-1563 is the count for that one file.

    Grouped by the resource type the operation names, which is how the work divides:

    • user — 13 sites: :237 CreateUser, :285 GetUser, :326 DeleteUser, :960/:1010/:1056
      Attach/Detach/ListAttachedUserPolicies, :1368/:1439/:1492 Create/Delete/ListAccessKeys,
      :2184/:2242/:2294 Tag/Untag/ListUserTags, iam_groups.go:111 ListGroupsForUser
    • role — 10 sites: :446, :514, :559, :607, :1094, :1144, :1190, :2363, :2421, :2473
    • group — 8 sites: :736, :788, :851, iam_groups.go:49, :78, :175, :225, :271
    • policy — 5 sites: :1226, :1294, :1333, iam_policy_versions.go:60, :109
    • polymorphic user/role/group — 4 sites → 12 operations: the inline-policy handlers at :1804,
      :1883, :1924, :1981, which already build the action by concatenation
    • polymorphic user/role — 2 sites → 4 operations: the permissions-boundary handlers at :2040, :2113
    • entity ARN already in hand — 1 site: iam_simulate.go:112 validates PolicySourceArn two
      lines above the gate and then passes "*". Cheapest fix in the set.
    • legitimately * — 5 sites: :387 ListUsers, :686 ListRoles, :909 ListGroups,
      iam_list_policies.go:87 ListPolicies, iam_simulate.go:154 SimulateCustomPolicy

    Separately, and arguably worse than the "*": the six instance-profile handlers call the plugin
    door zero times
    — createInstanceProfile :2717, getInstanceProfile :2763,
    deleteInstanceProfile :2791, addRoleToInstanceProfile :2827,
    removeRoleFromInstanceProfile :2884, listInstanceProfiles :2970. The generic
    AuthController gate still runs upstream, but AddRoleToInstanceProfile is
    privilege-escalation-relevant and has no plugin-side gate. "Both doors must agree" is vacuous for
    instance-profile until they exist, so the gate is being added as part of this work, with its own
    CHANGELOG entry.

    On the citation criterion. The Service Authorization Reference pages for both IAM and EC2 render
    their tables in JavaScript and are unreachable to a fetch — docs/services.md already records this
    for the two ELB pages, which is why Names.member.N was left at *. AWS's Service Reference
    Information endpoint carries the same data as JSON
    (https://servicereference.us-east-1.amazonaws.com/v1/iam/iam.json, currently Version v1.4):
    Actions[].Resources[].Name per action, Resources[].ARNFormats per type, and an action with no
    Resources key supports no resource-level permissions. That snapshot is being vendored and a Go
    table generated from it with an offline drift check, so every row is cited by construction and a
    test — not a comment — asserts that each operation's resource type is one AWS publishes for it, and
    that every operation AWS scopes to * is absent from the table.

    Confirmed from that source: user is arn:${Partition}:iam::${Account}:user/${UserNameWithPath},
    and role/group/policy/instance-profile follow the same …NameWithPath shape. That path is
    the one wrinkle — unlike EC2, where an ID's prefix determines its ARN, an IAM ARN needs the
    entity's stored Path, and only the Create* operations carry it on the wire. Resolution
    therefore costs one state.Get, following iamAuthzRolePath (iam_authz.go:163-176), and falls
    back to * rather than minting an ARN that only looks specific, per iam_authz.go:135-138.

  3. scttfrdmn commented on Sep 11, 2026

    @scttfrdmn
    OwnerAuthor

    Surveyed this against main before starting. The defect reproduces exactly as filed, but the call-site inventory in the issue is low — it is 49 sites, not 37 — and the survey turned up a second, more serious finding the issue does not mention. Both are worth recording before the work lands.

    The defect, confirmed

    buildResourceARN's iam arm (emulator/authz.go:934-941) returns a flat arn:aws:iam::<account>:* for every IAM operation, so a statement whose Resource is arn:aws:iam::123456789012:user/alice matches nothing. This is why #745's policy-variable substitution still leaves the bundled IAMUserChangePassword granting nothing — the variable resolves correctly and then compares against the wrong resource (docs/services.md:1658-1665).

    The real inventory

    p.authorize is a shim over authorizeWith (iam_plugin.go:1544-1548, :1564-1724); the resource argument reaches only EvaluationRequest.Resource at :1682 and :1706.

    count
    p.authorize( sites 49 across 6 files — iam_plugin.go 37, iam_groups.go 6, iam_simulate.go 2, iam_policy_versions.go 2, iam_list_policies.go 1, iam_slr_handlers.go 1
    of those, passing a literal "*" 48
    authorizeWith sites already passing a real ARN 2 (iam_slr_handlers.go:113, :194)
    distinct operations behind them ~66 — 6 handlers are polymorphic and fan out to 16 operations

    Grouped by the resource type the operation names: user 13 sites, role 10, group 8, policy 5, polymorphic user/role/group 4 sites → 12 ops (putInlinePolicy and friends, iam_plugin.go:1804,1883,1924,1981), polymorphic user/role 2 → 4 ops (permissions-boundary handlers, :2040, :2113), and entity ARN already in hand 1 (iam_simulate.go:112 validates PolicySourceArn two lines above the gate — the cheapest fix in the set).

    Five sites legitimately keep "*": ListUsers (:387), ListRoles (:686), ListGroups (:909), listPolicies (iam_list_policies.go:87), simulateCustomPolicy (iam_simulate.go:154). AWS publishes no resource types for those actions, so * is the correct answer, not a placeholder — and that will be asserted by test rather than left to a comment.

    The second finding: six handlers call the plugin door zero times

    createInstanceProfile (:2717), getInstanceProfile (:2763), deleteInstanceProfile (:2791), addRoleToInstanceProfile (:2827), removeRoleFromInstanceProfile (:2884) and listInstanceProfiles (:2970) have no plugin-side gate at all. The generic AuthController gate still runs upstream, so this is not an open door, but AddRoleToInstanceProfile is privilege-escalation-relevant and "both doors agree" is vacuous for instance-profile while one of them never runs. Gating those six is beyond this issue's literal text; it will land here with its own CHANGELOG bullet rather than as a silent extra.

    Also noted and filed separately as #796: Tags is stored on IAMUser/IAMRole but never rendered — iamUserXMLFields and iamRoleXMLFields emit no <Tags> member.

    The path problem, and where the citations come from

    Unlike EC2, where an ID's prefix determines its ARN, an IAM ARN needs the entity's stored Path (${UserNameWithPath}), and only the Create* operations carry Path on the wire. So resolution costs one state.Get per resource-naming operation. There is precedent: iamAuthzRolePath (iam_authz.go:163-176) already does exactly this for DeleteServiceLinkedRole. PolicyArn-keyed operations need no read — the ARN is on the wire. Existing minters iamUserARN/iamRoleARN/iamGroupARN (iam_types.go:264-278) and iamPolicyARN are reused; there is no instance-profile minter, since :2747 inlines the fmt.Sprintf and skips normalisePath, so one gets extracted.

    The per-operation classification will not be hand-transcribed from the Service Authorization Reference — those HTML pages render their tables in JavaScript and are unreachable, which docs/services.md already records for both ELB pages. It comes from AWS's machine-readable Service Reference Information endpoint, vendored and code-generated with an offline drift check (landed in #797). A test then asserts, for every row in the table, that its resource type is one AWS publishes for that action, and that every action with no published resource types is absent from the table. That is this issue's second and third acceptance criteria checked mechanically rather than claimed in prose.

    Assigned to v0.111.0 alongside #771 and #762 — the same defect seen from three sides.

  4. scttfrdmn commented on Sep 11, 2026

    @scttfrdmn
    OwnerAuthor

    Shipped in v0.111.0 (#802). Against the acceptance criteria as filed:

    • A per-operation resource, at both doors. 59 operations in iamAuthzOperationResource, plus the three service-linked-role operations iamAuthzSLRResourceARN already resolved (iam: CreateServiceLinkedRole, so iam:AWSServiceName has a producer #747). Both doors call iamAuthzRequestResource on the same AWSRequest, so the answer cannot differ by call site — the plugin door's 48 literal "*" gates are gone, and a table test drives CheckAccess and IAMPlugin.authorize over every row asserting one ARN, computed from the fixture rather than from the resolver.
    • The citation is mechanical in both directions, read from the vendored Service Reference Information snapshot (feat(authz): vendor AWS's per-operation authorization data, generated and drift-checked #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; and every ARN substrate mints equals AWS's published format string for that type. A row that drifts from AWS's data fails the build.
    • The headline case, with no hand-written policy. The bundled IAMUserChangePassword now grants the caller their own password and nothing else. Verified live too, with the AWS CLI: alice, holding a customer-managed policy allowing iam:GetUser on arn:aws:iam::123456789012:user/alice, reads her own user and is refused bob's. The same script against the previous main refused both, on arn:aws:iam::123456789012:*.
    • ListUsers under a policy scoped to user/alice still grants nothing. Five operations that name no resource keep the account wildcard — ListUsers, ListRoles, ListGroups, ListPolicies, SimulateCustomPolicy — which is AWS's own answer for them. It is deliberately arn:aws:iam::<account>:* rather than a bare *, because a bare * in the resource position matches every statement: harmless for an Allow, wrong for a Deny.

    Two things beyond the issue's text, both recorded in the CHANGELOG:

    • The six instance-profile operations are now gated at the plugin door, where they called it zero times. AddRoleToInstanceProfile is the classic privilege-escalation step, and "both doors agree" is vacuous for instance-profile while one door is missing. 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.

    One limit surfaced while writing these tests and filed rather than folded in: #801 — the same divergence on the principal side, where a caller whose own entity lives at a non-default path is not enforced at all. The tests here authorize as a caller stored at the default path, and say why in place, so none of them can pass vacuously.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions