Repository navigation
feat(iam): the six tagging operations for policies and instance profiles (#796) - #812
Merged
Merged
Conversation
…les (#796) TagPolicy, UntagPolicy, ListPolicyTags, TagInstanceProfile, UntagInstanceProfile and ListInstanceProfileTags reached the dispatcher's default arm and answered InvalidAction/400, so only two of the four taggable IAM types could accept a tag at all. The twelve tagging operations now share one implementation of the merge-by-key, the removal and the listing, in a new emulator/iam_tagging.go, which also fixes ListUserTags and ListRoleTags: AWS documents "The returned list of tags is sorted by tag key" on all six listings, and the two that predate this change reported tags in whatever order they were stored — a marker names a key rather than an offset, so an unsorted order made a second page arbitrary. Six iamAuthzOperationResource rows gate all six against the resource they name, validated against the vendored Service Reference Information snapshot by the existing both-directions test. An AWS managed policy is deliberately not resolved: AWS documents the policy family for a customer managed policy, and the bundled catalog is read-only. There is no group family, on four citations recorded in the new file.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…body paths A store failure, an undecodable record and a failed write are each distinct from the caller's NoSuchEntity: the first two are transient or corrupt-store conditions a consumer must retry rather than delete-and-recreate over, and a write that failed must not answer 200 — which is the #639 failure mode exactly (TagUser answered 200 and stored nothing). Brings emulator/iam_tagging.go to 203/205 statements. The two remaining are json.Marshal error branches for structs that always marshal.
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 #796.
The second and final half of #796. #811 made an entity read report its tags; this adds the six tagging operations that did not exist, so all four taggable IAM types can be tagged and read back.
TagPolicy,UntagPolicy,ListPolicyTags,TagInstanceProfile,UntagInstanceProfileandListInstanceProfileTagsreached the dispatcher's default arm and answeredInvalidAction/400. That is the other half of the same drift: a consumer's tag aspect tags every entity it creates, and only the user and role families could accept one — so tagging a customer-managed policy failed outright rather than drifting.Two departures from the plan, both disclosed
1. The six existing user/role handlers were refactored onto shared helpers. The plan said the new six would be "exact parallels of
tagUser/untagUser/listUserTags". Writing them that way would have produced a fourth and fifth copy of the merge-by-key, the removal and theIsTruncated/Markershape. Instead the semantics live in the newemulator/iam_tagging.go(iamMergeTagSet,iamRemoveTagKeys,iamTagListingResponse) and the six existing handlers call them — ~120 lines of four-way duplication removed, and the four families now cannot answer differently because there is one implementation to be wrong.2. That refactor turned up an existing defect, fixed here. AWS documents "The returned list of tags is sorted by tag key" on
ListUserTagsandListRoleTagstoo, and neither sorted: they reported tags in whatever order they were stored — the order aTags.member.Narrived in, or a Go map's. The responseMarkernames a key rather than an offset, so an unsorted underlying order made a second page arbitrary.TestIAMTagging_AListingIsSortedByKeyfails onmainfor all four types, not just the two this PR adds.What AWS says, and where
TagPolicy:PolicyArn(Required: Yes, 20–2048) andTags.member.N(Required: Yes, max 50);ConcurrentModification/409,InvalidInput/400,LimitExceeded/409,NoSuchEntity/404,ServiceFailure/500. "Adds one or more tags to an IAM customer managed policy. If a tag with the same key name already exists, then that tag is overwritten with the new value."ListPolicyTags/ListUserTags: "The returned list of tags is sorted by tag key."MaxItemsdefaults to 100 (1–1000).Tagsis a required response member — "If no tags are attached to the specified resource, the response contains an empty list" — which is the opposite of the entity shapes, whereTagsisRequired: Noand an untagged entity omits it (fix(iam): an entity read reports its tags (#796) #811). ResponseMarkeris present only whenIsTruncatedis true.UntagInstanceProfile:InstanceProfileName(Required: Yes, 1–128) andTagKeys.member.N(Required: Yes, max 50).Groupdata type documents noTags, the Actions index publishes noTagGroup/UntagGroup/ListGroupTags, the vendored SAR snapshot has noiam:*Grouptagging action, and the User Guide says it directly — "You can tag most IAM resources, but not groups, assumed roles, access reports, or hardware-based MFA devices." All three keep answeringInvalidAction, which is the honest report that substrate models no such operation; aNoSuchEntitywould tell a consumer the group was the problem.An AWS managed policy cannot be tagged.
loadTaggedPolicydeliberately does not consult the bundled catalog: AWS documents the family for an "IAM customer managed policy", a managed policy belongs to theawsaccount, and substrate's catalog is read-only for the same reason. Tagging one answersNoSuchEntity/404 even thoughGetPolicyresolves the same ARN — which the test asserts explicitly, so the 404 is a decline rather than a lookup miss.Authorization
Six
iamAuthzOperationResourcerows (policy→PolicyArn,instance-profile→InstanceProfileName). The existingTestIAMAuthzOperationResource_EveryRowMatchesWhatAWSPublishesvalidates them against the vendored Service Reference Information snapshot in both directions for free, andTestIAMAuthzResource_BothDoorsAgreederives a case from every row, so both doors naming the same resource is asserted without a line of new test code.TestIAMTagging_TheNewOperationsAreGatedAtThePluginDooris the part that needed writing: it wires noAuthController, so every verdict is the handler's own — the only way to assert that a new handler calls a gate at all. Tagging is privilege-relevant rather than bookkeeping: anaws:ResourceTag-conditioned statement is decided on the resource's tags, so a caller who can retag an instance profile can move it in or out of the reach of every such statement.Validation is deliberately not folded in
InvalidInput/400 (empty key,aws:prefix),LimitExceeded/409 (the 50-tag cap) andConcurrentModification/409 are documented and not emitted; a key is compared case-sensitively where AWS treats user and role tag keys case-insensitively. Each rejection is a behavior change for a consumer on today's permissive path and earns its own compatibility note, so it stays as #806.iam_tagging.go's file comment records this so the gap reads as a decision rather than an oversight.One thing the permissive path must still not do:
UntagPolicywith noTagKeysremoves nothing rather than clearing the set — the one answer that cannot lose a consumer's tags. Pinned by a test.Tests
emulator/iam_tagging_test.go, 9 test functions. 8 of the 9 fail onmain(the ninth,ThereIsNoGroupEquivalent, is a pinning test and passes by design):APolicyTagRoundTrip/AnInstanceProfileTagRoundTrip— empty listing, tag, list, overwrite a key, untag, untag an absent key, untag with no keys, then the entity read, so both halves of iam: tags are stored but no entity read reports them #796 are asserted to agree about one record. Separate tests rather than table rows because the two load from different state keys.CreateTimeTagsAreListed— fix(iam): an entity read reports its tags (#796) #811's create-timeTags.member.Nread back through the new listings.AListingIsSortedByKey— all four types, tags supplied out of order. Fails onmainfor all four.AListingPaginates— three tags atMaxItems=2, follow theMarker, assertMarkeris absent on the last page, and that the default page reports all three.AnAbsentResourceIsNoSuchEntity— absent ARN, absent profile, and an AWS managed policy ARN, plus a non-vacuity subtest showingGetPolicyresolves that same ARN.AMissingIdentifierIsAValidationError— all six.ThereIsNoGroupEquivalent— the three group operations answerInvalidAction/400, with the four citations in the comment and a non-vacuity check thatCreateGroup/GetGroupdo answer.TheNewOperationsAreGatedAtThePluginDoor— 12 cases, allowed-resource vs. other-resource for each of the six.iam_tagging.go: 181/205 statements covered. The remaining 24 are state-Get,Unmarshal,MarshalandPuterror propagation, unreachable through the HTTP surface with a memory state manager — the same shape as the rest of the plugin.Verification
gofmt -l . && go build ./... && go vet ./... && golangci-lint run ./...make test(go1.27.1)GOTOOLCHAIN=go1.26.6 make testGOTOOLCHAIN=go1.26.6 make coveragemake docs-reference docs-reference-check docs-versions authz-reference-checknpm --prefix docs run buildgo vet -C test/e2e ./... && go test -C test/e2e ./...Fail-before confirmed in a throwaway
git worktreeatmain.Docs
docs/services.mdgains the six rows in the IAM operations table and a new The tagging operations, and what a listing reports section: the four families and their identifiers, the sort rule and why it is not cosmetic, the required-empty-list contrast against the entity shapes, why tagging is privilege-relevant, why an AWS managed policy cannot be tagged, and the validation gap pointing at #806.