Skip to content

iam: policy variables are compared literally, so a negated ${aws:username} is more permissive than on AWS #745

Closed

Description

@scttfrdmn

What

Substrate does not substitute IAM policy variables. A Resource of arn:aws:s3:::mybucket/${aws:username}/* is compared literally, and ${aws:username} has no producer — nothing in the emulator ever sets that key in a condition context.

docs/services.md records this as a deliberate non-implementation (#730) rather than an oversight, along with the reason it is not currently observable and the one place it diverges.

Why it is mostly not observable today

AWS's rule for an unresolved variable is that it "will not match any resource". Substrate's literal comparison gives the same answer for the only bundled policy that uses a variable (emulator/iam_managed.go — the single ${ across 47 policies): the statement matches nothing either way, so the decision agrees.

The divergence that is real

NotResource, and negated operators. AWS documents that an unresolved variable in a NotResource — or under StringNotEquals and friends — does match, so the negation excludes everything. Substrate's literal comparison makes it match nothing, so the negation excludes nothing, and a policy written that way is more permissive here than on AWS. That is the direction that matters.

The ordering constraint

Substitution cannot land before aws:username has an honest producer, and the obvious candidates are both wrong:

  • The ARN's last component. For an assumed role that is the session name (emulator/sts_plugin.go), and AWS documents aws:username as absent for a role session — so this would invent a value where AWS has none.
  • buildCallerARN's input (emulator/credentials.go). That is the access key ID, not a user name.

The honest producer is a new Principal.UserName, set where the name is already in hand and currently discarded — emulator/credentials.go, in the path that resolves a signed request's key to its IAM user. aws:userid and aws:PrincipalTag/ have the same shape of prerequisite.

Acceptance criteria

  • Principal carries the resolved IAM user name, set from the credential lookup rather than parsed back out of an ARN, and left empty for a role session.
  • aws:username is produced from it, and is absent (not empty) for an assumed role, matching AWS.
  • ${…} substitution runs on Resource, NotResource and condition values, with an unresolved variable matching nothing in the positive forms and everything in the negated ones — the AWS rule, pinned by a test for each direction.
  • docs/services.md stops describing this as a non-implementation and records which variables resolve.

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