Skip to content

feat(iam): implement UpdateAssumeRolePolicy (#594) - #600

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/594-update-assume-role-policy
Aug 9, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/594-update-assume-role-policy

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #594

Why

UpdateAssumeRolePolicy was absent from the IAM operation switch — grep found zero occurrences in emulator/ — so CreateRole was the only way a role's trust policy could ever be set. That was harmless while the document was inert. #593 (v0.95.0) made it load-bearing at AssumeRole time, and after that the update-in-place shape CDK and Terraform both emit on a second pass had nowhere to land: a consumer tightening a trust policy silently kept the original, so the tightening its test existed to verify was unobservable.

The operation

Verified against the botocore IAM model rather than recalled:

  • RoleName and PolicyDocument are both required, unlike CreateRole's optional AssumeRolePolicyDocument. There is therefore no "clear the trust policy" form of this call, and an absent document is a ValidationError/400 rather than a silent unenforcing of the role.
  • Unknown role → NoSuchEntity/404, with createRole's message wording.
  • Unparseable document → MalformedPolicyDocument/400.
  • The model declares no output shape, so success is the empty-envelope response (iamXMLEmptyResponse).

The document is stored unmarshalled into PolicyDocument exactly as createRole stores it, so #593's gate and GetRole's read-back both see the replacement with no further plumbing. Because that gate reads the stored policy at AssumeRole time, the replacement takes effect on the next assume and leaves already-minted sessions alone — which is what AWS does too, and both halves are pinned by tests.

GetRole now reports the trust policy

The issue's acceptance criterion "read-back through GetRole reflects the new document" was unmeetable: iamRoleXMLFields omitted AssumeRolePolicyDocument entirely. It now emits it, which affects GetRole, ListRoles and the roles embedded in instance-profile responses.

  • Plain JSON, not URL-encoded, matching how GetRolePolicy already returns an inline document. botocore's after-call.iam handler unquotes then json.loads every policyDocumentType member, and unquoting plain JSON is a no-op, so both SDK families see valid JSON. Confirmed against a live server: aws iam get-role --query 'Role.AssumeRolePolicyDocument' prints a parsed object.
  • Re-marshalled from the stored parsed form, not returned verbatim — the same normalization GetRolePolicy/GetUserPolicy already apply. A semantically equivalent form can therefore come back: a {"AWS":"1234"} principal reads back as "1234", the other form AWS accepts for the same meaning. A consumer that parses the document is unaffected; one comparing bytes against what it submitted sees a difference. Pinned by ..._ReadBackIsNormalized so it is a documented property rather than something rediscovered.
  • Omitted for a role with no statements, because a role created without a trust policy has a zero PolicyDocument and marshalling that would report {"Version":"","Statement":null} where AWS reports nothing. The emptiness test is the same one the STS gate uses to decide a role is unenforced.

Tests

Seven unit tests in emulator/iam_update_assume_role_policy_test.go plus one SDK-level journey. The decisive one is ..._TakesEffectOnNextAssume: assume successfully, tighten to another account, assume again and get AccessDenied — #594's criterion exercised through an update rather than through a second role. ..._DoesNotRevokeExistingSessions covers the other half, with a fresh-assume control proving the replacement did land.

Verification

gofmt · go build · go vet · golangci-lint run ./... → 0 issues · make test (race) · make docs-reference-check docs-versions · go test -C test/e2e ./... · npm --prefix docs run build. Also end-to-end against substrate server with the AWS CLI (AWS_MAX_ATTEMPTS=1): assume succeeds, update, get-role shows the new document, assume is refused with AccessDenied, NoSuchEntity/MalformedPolicyDocument on the error paths, and list-roles unaffected.

A role's trust policy could only ever be set by CreateRole — the operation
was absent from the IAM switch entirely. That was invisible until #593 made
the document load-bearing at AssumeRole time; after it, the update-in-place
shape CDK and Terraform both emit on a second pass had nowhere to land, so a
consumer tightening a trust policy silently kept the original one.

Both RoleName and PolicyDocument are required by the model, unlike
CreateRole's optional AssumeRolePolicyDocument, so there is no "clear the
trust policy" form of the call and an absent document is a ValidationError
rather than a silent unenforcing. Unknown role is NoSuchEntity/404, an
unparseable document MalformedPolicyDocument/400. The document is stored
unmarshalled into PolicyDocument exactly as createRole stores it, so #593's
gate and GetRole's read-back both see the replacement with no new plumbing:
it takes effect on the next assume and leaves already-minted sessions alone,
which is what AWS does too.

GetRole never rendered AssumeRolePolicyDocument at all, which made the
issue's read-back criterion unmeetable, so iamRoleXMLFields now emits it —
affecting GetRole, ListRoles and the roles embedded in instance-profile
responses. Emitted as plain JSON rather than URL-encoded: botocore's
after-call.iam handler unquotes then json.loads every policyDocumentType
member and unquoting plain JSON is a no-op. It is re-marshalled from the
stored parsed form, the same normalization GetRolePolicy already applies, so
a semantically equivalent form can come back — a {"AWS":"1234"} principal
reads back as "1234" — and it is omitted for a role with no statements
rather than reporting a document AWS never sends.
@codecov

codecov Bot commented Aug 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 72.97297% with 10 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/iam_plugin.go 68.75% 5 Missing and 5 partials ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 35fc5a3 into main Aug 9, 2026
15 of 16 checks passed
@scttfrdmn scttfrdmn mentioned this pull request Aug 9, 2026
@scttfrdmn
scttfrdmn deleted the feat/594-update-assume-role-policy branch August 9, 2026 17:48
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.

IAM: UpdateAssumeRolePolicy is unimplemented, so a role's trust policy cannot be changed after CreateRole

1 participant