Repository navigation
feat(iam): implement UpdateAssumeRolePolicy (#594) - #600
Merged
Merged
Conversation
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 Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #594
Why
UpdateAssumeRolePolicywas absent from the IAM operation switch —grepfound zero occurrences inemulator/— soCreateRolewas 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 atAssumeRoletime, 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:
RoleNameandPolicyDocumentare bothrequired, unlikeCreateRole's optionalAssumeRolePolicyDocument. There is therefore no "clear the trust policy" form of this call, and an absent document is aValidationError/400 rather than a silent unenforcing of the role.NoSuchEntity/404, withcreateRole's message wording.MalformedPolicyDocument/400.iamXMLEmptyResponse).The document is stored unmarshalled into
PolicyDocumentexactly ascreateRolestores it, so #593's gate andGetRole's read-back both see the replacement with no further plumbing. Because that gate reads the stored policy atAssumeRoletime, 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.GetRolenow reports the trust policyThe issue's acceptance criterion "read-back through
GetRolereflects the new document" was unmeetable:iamRoleXMLFieldsomittedAssumeRolePolicyDocumententirely. It now emits it, which affectsGetRole,ListRolesand the roles embedded in instance-profile responses.GetRolePolicyalready returns an inline document. botocore'safter-call.iamhandler unquotes thenjson.loadseverypolicyDocumentTypemember, 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.GetRolePolicy/GetUserPolicyalready 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..._ReadBackIsNormalizedso it is a documented property rather than something rediscovered.PolicyDocumentand 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.goplus one SDK-level journey. The decisive one is..._TakesEffectOnNextAssume: assume successfully, tighten to another account, assume again and getAccessDenied— #594's criterion exercised through an update rather than through a second role...._DoesNotRevokeExistingSessionscovers 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 againstsubstrate serverwith the AWS CLI (AWS_MAX_ATTEMPTS=1): assume succeeds, update,get-roleshows the new document, assume is refused withAccessDenied,NoSuchEntity/MalformedPolicyDocumenton the error paths, andlist-rolesunaffected.