Skip to content

feat(iam): the six tagging operations for policies and instance profiles (#796) - #812

Merged
scttfrdmn merged 2 commits into
mainfrom
feat/796-tagging-operations
Sep 12, 2026
Merged

scttfrdmn merged 2 commits into
mainfrom
feat/796-tagging-operations

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

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, UntagInstanceProfile and ListInstanceProfileTags reached the dispatcher's default arm and answered InvalidAction/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 the IsTruncated/Marker shape. Instead the semantics live in the new emulator/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 ListUserTags and ListRoleTags too, and neither sorted: they reported tags in whatever order they were stored — the order a Tags.member.N arrived in, or a Go map's. The response Marker names a key rather than an offset, so an unsorted underlying order made a second page arbitrary. TestIAMTagging_AListingIsSortedByKey fails on main for all four types, not just the two this PR adds.

What AWS says, and where

  • TagPolicy: PolicyArn (Required: Yes, 20–2048) and Tags.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." MaxItems defaults to 100 (1–1000). Tags is 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, where Tags is Required: No and an untagged entity omits it (fix(iam): an entity read reports its tags (#796) #811). Response Marker is present only when IsTruncated is true.
  • UntagInstanceProfile: InstanceProfileName (Required: Yes, 1–128) and TagKeys.member.N (Required: Yes, max 50).
  • No group family, and there will not be: the Group data type documents no Tags, the Actions index publishes no TagGroup/UntagGroup/ListGroupTags, the vendored SAR snapshot has no iam:*Group tagging 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 answering InvalidAction, which is the honest report that substrate models no such operation; a NoSuchEntity would tell a consumer the group was the problem.

An AWS managed policy cannot be tagged. loadTaggedPolicy deliberately does not consult the bundled catalog: AWS documents the family for an "IAM customer managed policy", a managed policy belongs to the aws account, and substrate's catalog is read-only for the same reason. Tagging one answers NoSuchEntity/404 even though GetPolicy resolves the same ARN — which the test asserts explicitly, so the 404 is a decline rather than a lookup miss.

Authorization

Six iamAuthzOperationResource rows (policy→PolicyArn, instance-profile→InstanceProfileName). The existing TestIAMAuthzOperationResource_EveryRowMatchesWhatAWSPublishes validates them against the vendored Service Reference Information snapshot in both directions for free, and TestIAMAuthzResource_BothDoorsAgree derives a case from every row, so both doors naming the same resource is asserted without a line of new test code.

TestIAMTagging_TheNewOperationsAreGatedAtThePluginDoor is the part that needed writing: it wires no AuthController, 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: an aws: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) and ConcurrentModification/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: UntagPolicy with no TagKeys removes 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 on main (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-time Tags.member.N read back through the new listings.
  • AListingIsSortedByKey — all four types, tags supplied out of order. Fails on main for all four.
  • AListingPaginates — three tags at MaxItems=2, follow the Marker, assert Marker is 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 showing GetPolicy resolves that same ARN.
  • AMissingIdentifierIsAValidationError — all six.
  • ThereIsNoGroupEquivalent — the three group operations answer InvalidAction/400, with the four citations in the comment and a non-vacuity check that CreateGroup/GetGroup do 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, Marshal and Put error propagation, unreachable through the HTTP surface with a memory state manager — the same shape as the rest of the plugin.

Verification

Check Result
gofmt -l . && go build ./... && go vet ./... && golangci-lint run ./... clean, 0 issues
make test (go1.27.1) pass
GOTOOLCHAIN=go1.26.6 make test pass
GOTOOLCHAIN=go1.26.6 make coverage emulator 83.6%, total 83.0% — at baseline
make docs-reference docs-reference-check docs-versions authz-reference-check pass
npm --prefix docs run build pass
go vet -C test/e2e ./... && go test -C test/e2e ./... pass

Fail-before confirmed in a throwaway git worktree at main.

Docs

docs/services.md gains 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.

…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

codecov Bot commented Sep 12, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.11894% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/iam_tagging.go 99.04% 2 Missing ⚠️

📢 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.
@scttfrdmn
scttfrdmn merged commit 491d918 into main Sep 12, 2026
17 checks passed
@scttfrdmn
scttfrdmn deleted the feat/796-tagging-operations branch September 12, 2026 00:59
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: tags are stored but no entity read reports them

1 participant