Skip to content

fix(sts): GetCallerIdentity reports the caller's unique ID, not their name (#805) - #810

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/805-caller-identity-unique-id
Sep 12, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/805-caller-identity-unique-id

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #805.

AWS's identifiers reference
documents three forms for GetCallerIdentity's UserId, and names that operation as the way to
read one: AIDA… for an IAM user, AROA…:<role-session-name> for an assumed role, and the
account ID for the account root. Substrate reported the caller's friendly name — alice, and
worker/sess1 for a session, which is the ARN's last two segments and not a shape AWS produces
anywhere. A consumer asserting on UserId, or splitting an assumed-role ID on : to recover the
session name, read a value it could not have got from AWS.

It also disagreed with substrate's own aws:userid, which has published the right value from
Principal.UserID since #771 and was simply not read here. Both surfaces now come from that one
recorded field, so a policy conditioned on aws:userid and a test asserting on UserId cannot
disagree about who the caller is.

What it does

  • Prefer Principal.UserID, per iam: policy variables are compared literally, so a negated ${aws:username} is more permissive than on AWS #745's record-don't-derive rule: resolvePrincipal copies it off
    the access key's or the session's own record, so the common path performs no lookup.
  • Fall back to the entity's recorded UserId/RoleId for a credential minted before iam: produce aws:userid and aws:PrincipalTag/, the two caller keys still without a producer #771, whose
    record has the field empty — one state read on an operation that is not hot. For an assumed role
    the documented {role-id}:{session-name} pairing is rebuilt from the role's record plus the
    session name the ARN carries, which is the same string assumeRole composes today.
  • Where there is no ID to be had, keep the value substrate published before: the account root
    reports the account ID (AWS's own third form), and a principal that resolves to no IAM entity
    reports its friendly name. That last case is substrate's choice rather than AWS's — every caller
    on AWS has a unique ID — and the reasoning is recorded on the function: a name identifies the
    caller, where an empty member could not be told from a bug.

Also tightens the UserId assertion #801 deliberately left loose (NotContains "/") to assert
the AIDA… form, which is what its comment said was waiting on this issue.

Verification

Fail-before, pass-after — five of the eight new cases fail on main, and the three that pass are
pinning behaviour this deliberately does not change:

--- FAIL: TestGetCallerIdentity_AnIAMUserReportsTheirUniqueID          expected AIDA…, got "alice"
--- FAIL: TestGetCallerIdentity_AgreesWithAWSUserID                    "AIDAAV6CTHYCWSF297872" vs "alice"
--- FAIL: TestGetCallerIdentity_AnAssumedRoleReportsTheRoleIDAndSession no ":" in "worker/sess1"
--- FAIL: TestGetCallerIdentity_ACredentialMintedBefore…               expected "AIDAOLDCREDENTIAL123", got "legacy"
--- FAIL: TestGetCallerIdentity_ASessionMintedBefore…                  expected "AROAOLD…:oldsess", got "worker/oldsess"

Live against a real aws CLI, all three documented forms in one run — and the user's UserId
agrees with what iam get-user reports for her, which is a consistency AWS has too:

$ aws sts get-caller-identity                      # unsigned / no IAM entity
{ "UserId": "123456789012", "Arn": "arn:aws:iam::123456789012:root" }

$ aws iam get-user --user-name alice --query User.UserId    → AIDACSGGRYV3MNHQAWUVI
$ aws sts get-caller-identity                      # signed as alice
{ "UserId": "AIDACSGGRYV3MNHQAWUVI", "Arn": "arn:aws:iam::123456789012:user/alice" }

$ aws iam get-role --role-name worker --query Role.RoleId   → AROAS9BC4D733R6A7P7YD
$ aws sts get-caller-identity                      # as the assumed role
{ "UserId": "AROAS9BC4D733R6A7P7YD:sess1", "Arn": "arn:aws:sts::123456789012:assumed-role/worker/sess1" }

Full gate green: gofmt/go build/go vet/golangci-lint (0 issues), make test on Go 1.27 and
1.26.6, make coverage (emulator 83.6%, total 83.0% — unchanged), make docs-reference docs-reference-check docs-versions authz-reference-check, npm --prefix docs run build, and
go vet -C test/e2e ./... && go test -C test/e2e ./.... Patch coverage measured at 100% locally.

Compatibility

UserId changes value from a friendly name to the documented unique ID. A test asserting
UserId == "alice" must now assert the AIDA… form or read it from GetUser. Arn, Account
and the response shape do not move, and the account-root answer is unchanged.

Notes

  • entityUniqueID reads one key for both fields because a record is a user or a role, and
    iamEntityKey already keys them apart by kind.
  • Dropped a p.state == nil guard I had written into that read: no other operation in this plugin
    checks it, and an unreachable branch is worse than following the local convention.
  • docs/services.md gains a short table of the three forms under the STS section, since this is a
    value consumers assert on.

… name (#805)

AWS's identifiers reference documents three forms for UserId and names
GetCallerIdentity as the way to read one: AIDA… for an IAM user,
AROA…:<role-session-name> for an assumed role, and the account ID for the
account root. Substrate reported the friendly name, and 'worker/sess1' for a
session — the ARN's last two segments, which is no documented shape.

Principal.UserID has held the right value since #771 and publishes aws:userid
from it, so the two surfaces disagreed as well as diverging from AWS. Prefer
the recorded value per #745; fall back to the entity's own UserId/RoleId for a
credential minted before #771, rebuilding the role-id:session pairing for a
session.

Closes #805
@codecov

codecov Bot commented Sep 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 4e40bab into main Sep 12, 2026
17 checks passed
@scttfrdmn
scttfrdmn deleted the fix/805-caller-identity-unique-id branch September 12, 2026 00:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(sts): GetCallerIdentity reports an entity name where AWS reports a unique ID

1 participant