Skip to content

iam: produce aws:userid and aws:PrincipalTag/, the two caller keys still without a producer #771

Closed

Description

@scttfrdmn

authzPrincipalContext (emulator/authz.go) publishes two keys that name the caller:
aws:PrincipalArn (#714) and, as of #745, aws:username. Two more of the global keys
substrate's own bundled AWS managed policies condition on still have no producer, so a policy
naming either is evaluated against a context that does not hold it:

  • aws:userid — the unique ID of the caller. AWS publishes <account-id> for the account
    root, the user's own AIDA… for an IAM user, and <role-id>:<role-session-name> for an
    assumed role.
  • aws:PrincipalTag/<key> — the tags on the calling entity.

docs/services.md lists both under the keys with no producer, and #745 left a note there
saying what it would take: "the derivation that made [aws:username] honest was to record
the name at the credential lookup, not to parse it back out of an ARN. The same shape of
prerequisite is what the other two still need."
This issue is that work.

Why each needs a prerequisite rather than a derivation

aws:userid needs an ID substrate does not mint. CreateUser and CreateRole store no
AIDA…/AROA…, and AssumeRole records no role ID, so there is nothing to publish. Deriving
one from the name would make it stable per-name rather than per-entity, which is the opposite of
what a unique ID is for, and a policy comparing aws:userid against a real AIDA… from a
recorded AWS run would never match either way. The honest fix is to mint the ID at create time —
AWS documents the prefixes and the 21-character shape — store it on the entity, and carry it on
Principal the way UserName now is. The assumed-role form then composes from the stored role
ID and the session name AssumeRole already records.

aws:PrincipalTag/ needs the tags read at resolution time. IAM user and role tags are
modelled (TagUser, TagRole), so unlike aws:userid the data exists — what is missing is that
resolvePrincipal does not read them and Principal has nowhere to put them. It is a lookup on a
path that currently costs one Get, so the cost of the extra read is worth stating in the issue's
own terms rather than assumed away.

Both are more valuable now than before #745, because a produced key is also a variable: with
aws:PrincipalTag/team published, ${aws:PrincipalTag/team, 'company-wide'} — AWS's own
documented example — starts resolving.

Acceptance criteria

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. Two corrections before the work starts, because the first acceptance
    criterion is already met on main (2decd7f).

    CreateUser/CreateRole do mint and store a unique ID, and GetUser/GetRole do report it.

    • emulator/iam_plugin.go:257 — UserID: generateIAMID("AIDA")
    • emulator/iam_plugin.go:480 — RoleID: generateIAMID("AROA")
    • generateIAMID (emulator/iam_types.go:301-311) produces AWS's 21-character prefix+random shape
    • emulator/iam_xml.go:79 and :121 render <UserId>/<RoleId> from the stored record, which
      loadUser/loadRole (iam_plugin.go:2525-2552) read back with no field synthesis or zeroing

    Substrate mints one for every entity kind, not just these two: AGPA group (:756), ANPA
    policy (:1259), AKIA access key (:1393), AIPA instance profile (:2746), ASIA STS
    session (sts_plugin.go:197, :363), and AROA for a service-linked role
    (iam_slr_handlers.go:132).

    So the prerequisite this issue describes is not minting — it is carrying the ID to the
    decision
    , which is genuinely missing:

    • resolvePrincipal (emulator/credentials.go:162-210) builds Principal{ARN, Type, UserName}
      from IAMAccessKey, and that record stores no UserID.
    • AssumeRole computes role.RoleID + ":" + sessionName at sts_plugin.go:213 for the response
      and throws it away; STSSessionCredentials (sts_plugin.go:423-429) stores neither the role ID
      nor the session name.

    The fix keeps this issue's own rule — record at the credential, don't derive — by adding the ID to
    IAMAccessKey at CreateAccessKey and to STSSessionCredentials at AssumeRole/GetSessionToken,
    so resolvePrincipal still needs one Get for the ID.

    Tags cannot be recorded the same way, because they change after the key is created. They live
    inline on the entity record (IAMUser.Tags/IAMRole.Tags, iam_types.go:19-42, merged and
    rewritten by tagUser/tagRole at iam_plugin.go:2197-2219 and :2345-2401), so
    resolvePrincipal has to read the entity — one extra Get on the path that costs one today. That
    cost will be stated in its doc comment rather than assumed away, as this issue asks.

    One narrowing to record now: AssumeRole reads no Tags parameter at all (there is no
    occurrence of Tags anywhere in emulator/sts_plugin.go), so session tags are not modelled and an
    assumed role's aws:PrincipalTag/<key> will be the role's tags alone. AWS publishes both. That
    will be documented as a deliberate gap rather than left to look like completeness.

    The first acceptance-criteria checkbox will be ticked as already-satisfied with these citations
    rather than by changing code that is already correct.

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