Skip to content

IAM: AttachRolePolicy/AttachUserPolicy accept a PolicyArn that GetPolicy cannot resolve #499

Closed

Description

@scttfrdmn

AttachRolePolicy and AttachUserPolicy accept any PolicyArn without checking that it
resolves. attachRolePolicy (iam_plugin.go:843-887) validates the role exists, then
appends the ARN to role_policies:<name> unconditionally. GetPolicy on the same ARN
returns NoSuchEntity 404. So a consumer can attach a policy that does not exist and only
find out later, through a different operation.

Reported as part of #484, which hit the concrete case: five service-role ARNs an
SSM/Lambda/ECS consumer attaches were not in the bundled catalog. v0.87.0 seeded those five,
which fixes the reported symptom. This issue is the general case, kept open deliberately.

Why rejecting was refused in v0.87.0

Real IAM validates the policy exists and returns NoSuchEntity if it does not, so refusing
is the faithful behaviour. Substrate bundles 52 of roughly 1,200 AWS managed policies.
Rejecting an unresolvable ARN today would refuse every attach of the other ~1,150 — a
consumer attaching AmazonRDSFullAccess would get a hard failure where AWS succeeds. That
trades a confusing success for a wrong failure, and the wrong failure is worse: it breaks
working consumer code rather than merely failing to catch a typo.

#484's reporter offered both directions and would have accepted either. The decision is
recorded here rather than left implied by the code.

Possible middle paths

  1. Validate shape, not existence. Refuse an ARN that is not a well-formed policy ARN —
    wrong service, wrong resource type, missing policy/ — which catches typo-shaped
    mistakes without requiring the catalog to be complete. Does not catch
    arn:aws:iam::aws:policy/AmazonRDSFullAccesss.
  2. Warn. Log at WARN on an attach whose ARN neither resolves in the catalog nor exists
    in state, naming the ARN. Costs nothing, changes no observation, and is the same shape as
    SQS message-attribute rules are not applied to attributes already in state #491's receive-time warning.
  3. Seed the full managed-policy ARN list without documents. Roughly 1,200 name/ARN/ID
    triples let existence checks be exact while documents stay seeded for the ones that
    matter. Sizeable data addition, and it makes GetPolicy resolve a policy whose document
    is empty, which then needs its own caveat.
  4. Make it seedable. A control-plane switch for strict attach validation, off by default,
    so a consumer who wants the error branch tested can arm it.

(2) and (4) compose and neither breaks an existing consumer; that pairing is the likely
answer, but the decision belongs in this issue rather than pre-empted here.

Acceptance criteria

  • Decide between the paths above and record the reasoning.
  • AttachUserPolicy, AttachGroupPolicy and PutRolePolicy's managed equivalents get
    the same treatment — the asymmetry is not specific to roles.
  • Whatever ships, an ARN that GetPolicy resolves must never be refused.
  • docs/services.md states which check an attach performs.
  • Tests cover an unbundled-but-real managed ARN and a malformed one, and pin that they
    are treated differently.

Activity

  1. added
    type: bug
    area: iam
    on Aug 2, 2026
  2. added this to the v0.100.0 milestone on Aug 14, 2026
  3. scttfrdmn commented on Aug 14, 2026

    @scttfrdmn
    OwnerAuthor

    Scheduled for v0.100.0. The issue leaves the decision open and lists four paths; the
    decision is (1) + (2): validate the ARN's shape, and warn rather than refuse on one that
    substrate cannot resolve.

    • An ARN that is not a well-formed IAM policy ARN — wrong service, wrong resource type,
      missing policy/ — is refused with InvalidInput 400. This is the case that catches a
      typo, which is what makes the current silent success confusing.
    • An ARN that is well-formed but resolves in neither the bundled catalog nor policy:
      state logs at WARN naming the ARN, and succeeds. Refusing it would break every
      attach of the ~1,150 real AWS managed policies substrate does not bundle: a consumer
      attaching AmazonRDSFullAccess would hit a hard failure where AWS succeeds, which is
      worse than the confusing success. That is the issue's own reasoning and it still holds.
    • An ARN that GetPolicy resolves is never refused — the issue's hard acceptance
      criterion.

    Rejected, for the record:

    • (3) ship the full ~1,200-ARN table. It would make GetPolicy resolve policies whose
      documents do not exist, trading one confusing answer for a worse one: a policy that
      reports itself real and grants nothing.
    • (4) a seedable strict mode. A second behaviour for the same call, with no consumer
      asking for it. Reconsider if one does.

    Also fixing the asymmetry the issue names, rather than recreating it: the check applies to
    AttachUserPolicy, AttachRolePolicy and the new AttachGroupPolicy arriving in the
    same milestone with the IAM group operations (#579's prerequisite).

    This changes existing behaviour. A fixture that attaches a malformed PolicyArn
    starts failing where it used to silently succeed. It goes under ## Compatibility in the
    v0.100.0 release notes.

  4. scttfrdmn commented on Aug 15, 2026

    @scttfrdmn
    OwnerAuthor

    Decision recorded, implemented in #647 for v0.100.0.

    What ships: paths (1) + (2) — validate the ARN's shape, warn on one that resolves nowhere.

    • A PolicyArn that is not a well-formed policy ARN is refused with InvalidInput (400), the code the model declares for all three attach operations. The pattern is derived from the model's own accountIdType (\d{12}), policyPathType and policyNameType ([\w+=,.@-]+), and the arnType 20–2048 bound is checked first so an oversized value is refused on its size rather than run through a regex.
    • A well-formed ARN that resolves in neither the bundled catalog nor state succeeds, and logs at WARN naming it. Two messages, not one: an unbundled AWS managed policy is the expected case, while a customer-managed ARN that no CreatePolicy ever created is a likelier real mistake.
    • The partition is deliberately permissive (aws, aws-cn, aws-us-gov, the aws-iso variants, and whatever follows). Refusing an unknown partition would refuse an ARN that is perfectly well-formed for a region substrate does not model.
    • An ARN GetPolicy resolves is never refused, and never warns. That is this issue's hard acceptance criterion and it is asserted for a bundled ARN and a created one, across all three operations.

    Why existence is not required. Substrate bundles 52 of roughly 1,200 AWS managed policies. Requiring existence would refuse every attach of the other ~1,150 — attaching AmazonAthenaFullAccess would hard-fail where AWS succeeds. That trades a confusing success for a wrong failure, and the wrong failure is worse: it breaks working consumer code rather than merely failing to catch a typo. This issue's own reasoning on that point still holds.

    Paths not taken:

    • (3) seed the full ~1,200-ARN table. It would make GetPolicy resolve policies whose documents are empty — a resolvable ARN whose document is a lie needs its own caveat, and it is a large data addition serving only to make an existence check possible.
    • (4) a seedable strict mode. A second behaviour for the same call, with no consumer asking for it yet. Both remain open if one does.

    Applied to all three operations, not two: AttachGroupPolicy ships in the same release (part of #579's group prerequisite), so leaving it out would recreate the asymmetry this issue reports inside a brand-new operation.

    Ordering: the shape check runs before authorization (it needs no state, and a malformed request is invalid whatever the caller may do); the existence warning runs after the entity lookup, so an attach that is going to fail with NoSuchEntity does not also warn about a policy nothing was attaching.

    This changes existing behaviour and is called out under ## Compatibility in the v0.100.0 release: a fixture attaching a made-up, non-ARN-shaped PolicyArn starts failing with InvalidInput; one attaching a real-but-unbundled AWS managed ARN keeps working.

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

    area: iamfidelitytype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions