Skip to content

feat(iam): validate a tag against the rules AWS publishes (#806) - #822

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/806-iam-tag-validation
Sep 12, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/806-iam-tag-validation

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #806

All twelve IAM paths that accept a tag — the four Tag*, the four Untag* and the four
Create* — accepted anything at all: fifty-one tags, an empty key, a key or value beginning
with the reserved aws: prefix, a character outside the set AWS publishes. A consumer testing
the error branch its tagging code has for each of those got a 200 and a stored tag, so the
branch was never reached, and a run that would fail on AWS passed here.

After v0.112.0's consolidation every one of the twelve funnels through three helpers, so this is
one validator with twelve callers rather than twelve checks.

What is enforced, and from where

Every rule is quoted rather than inferred.

Rule Source Answer
Key 1–128 characters Tag — "Minimum length of 1. Maximum length of 128" ValidationError/400
Value 0–256 characters Tag — "Minimum length of 0. Maximum length of 256" ValidationError/400
Key matches [\p{L}\p{Z}\p{N}_.:/=+\-@]+ Tag — Pattern ValidationError/400
Value matches [\p{L}\p{Z}\p{N}_.:/=+\-@]* Tag — Pattern ValidationError/400
At most 50 members per request Tags.member.N / TagKeys.member.N — "Array Members: Maximum number of 50 items" ValidationError/400
Neither key nor value begins with aws: Tagging IAM resources — "You cannot create a tag key or value that begins with the text aws:" InvalidInput/400
At most 50 tags on a resource, post-merge the same array cap applied to the resulting set LimitExceeded/409

The two patterns are AWS's regexes compiled verbatim rather than a hand-rolled whitelist,
which is what #671's "only what the API model states" requires — and it changes behaviour, not
just style: the classes are Unicode, so Abteilung=Zürich, 部門=エンジニアリング and a value of
Arabic-Indic digits are accepted, where the ASCII whitelist the User Guide's prose rendering
suggests ("letters, numbers, spaces, and _ . : / = + - @") would refuse them. Lengths are
counted in characters rather than bytes for the same reason. The anchors are substrate's, since
AWS publishes the patterns unanchored and an unanchored match would accept any string containing
one legal character.

The cap is counted over the post-merge set, as ec2CheckTagLimit does: rewriting a key's
value on an entity already holding fifty tags succeeds, adding a fifty-first is refused.
Reserved keys are not exempt from the count — EC2's restrictions list states that exemption
and no IAM page does, and a caller cannot create such a key here in any case. aws: is matched
case-sensitively, so AWS:billing stays an ordinary caller tag.

Which code answers which rule is substrate's mapping

Worth stating plainly, because AWS publishes no per-rule code. The split follows what each
operation's own Errors list makes available:

  • A constraint stated on the shape answers ValidationError/400 — the code the IAM plugin
    already returns for every other shape violation, and the only 400 the four Untag* operations
    declare at all (their lists carry ConcurrentModification, NoSuchEntity and ServiceFailure,
    and not InvalidInput).
  • A rule stated only in prose and inexpressible in the shape — the reserved prefix — answers
    InvalidInput/400, which every tag-writing and create operation documents.
  • The over-limit total answers LimitExceeded/409.

So no operation emits a code its own Errors list does not carry. The messages are substrate's
wording; no page publishes message text, and an SDK dispatches on the code.

ConcurrentModification/409 and ServiceFailure/500 are declared on all twelve and are
unreachable by construction (#806's fourth criterion): a tagging handler's read-modify-write
runs synchronously inside one request against a StateManager that serializes its own access, so
nothing can interleave to produce the simultaneous-change condition; and a state failure is
returned as a Go error and answered as an internal error rather than as an IAM-shaped body.

Case sensitivity follows the entity type

AWS's split, not substrate's: "Tag key values for IAM users and roles are not case sensitive,
but case is preserved. […] For other IAM resource types, tag key values are case sensitive."

Every key was compared case-sensitively before this.

Entity Comparison Department=finance then department=hr yields
User, role not case sensitive Department=hr — one tag, stored spelling, new value
Customer managed policy, instance profile case sensitive both keys

Case being preserved is the load-bearing half: the surviving key keeps the spelling already
stored, because adopting the incoming one would silently rename a key an aws:ResourceTag
condition may be matching on. The rule reaches the removal for a reason beyond symmetry — if
the two spellings cannot both exist on a user, an untag that missed on case would leave a caller
holding a tag no spelling it can send would delete. A Create* applies the same rule, so an
entity cannot be born holding two keys no later Tag* could produce.

Ordering

Validation runs after p.authorize and before the entity load on all twelve paths. So an
unauthorized caller with an illegal payload is told AccessDenied — the same answer a legal one
gets — rather than learning which of its tags was malformed on a resource it cannot touch, and a
refusal does not depend on whether the resource exists. A bad tag on a Create* leaves no
entity behind
, per CreateUser's "If any one of the tags is invalid or if you exceed the
allowed maximum number of tags, then the entire request fails and the resource is not created."

iamMemberTags becomes a pure decoder and stops dropping a wholly empty member. Dropping it
silently accepted a request AWS refuses outright, and would now hide it from the validator. It
still answers nil for a genuinely absent list, which is what the JSON fallback depends on; two
TestIAMMemberTags cases are rewritten with comments recording the reversal.

Not enforced, deliberately

Tag.Value is Required: Yes, but an omitted Tags.member.N.Value arrives on the query wire as
the empty string, indistinguishable from an explicitly empty one — and an empty value is
documented as legal ("You can create a tag with an empty value such as phoneNumber = "), so
it is accepted rather than guessed at. An empty key is refused, by the minimum length of 1 and
the pattern's + alike. docs/services.md says so.

Tests

Nine tests, 93 subtests, in a new emulator/iam_tag_validation_test.go, driven through the
form protocol rather than a JSON body — that is the wire every real client uses and the one
the drift lived on. Each sweeps all four taggable entity types, since the rules are properties of
the Tag data type and a rule enforced on a user but not an instance profile is the same defect.

  • one refusal per rule, with its code and status, and the listing empty afterwards
  • the Unicode character set accepted, including an empty value and every literal in the class
  • the fifty-first key refused and a fifty-key overwrite accepted
  • Department/department collapsing on a user and role, distinct on a policy and profile
  • an untag of DEPARTMENT hitting on a user and missing on a policy
  • untag keys validated too, with the seeded tag surviving a refusal
  • a create with a bad tag leaving NoSuchEntity behind
  • a create collapsing a duplicate key under the type's case rule
  • an unauthorized caller learning nothing about its payload, through the plugin-door harness

Fail-before: with the three validators and the case rule neutralized, 74 of the 93 subtests
fail; restored, all 93 pass.

Verification

gofmt/go build/go vet clean, golangci-lint run ./... reports 0 issues., make test and
GOTOOLCHAIN=go1.26.6 make test pass, coverage holds at emulator 83.7% / total 83.1%,
make docs-reference docs-reference-check docs-versions authz-reference-check clean,
npm --prefix docs run build clean, go vet -C test/e2e ./... && go test -C test/e2e ./... pass.

Compatibility

An IAM tag request substrate accepts today can now be refused: more than 50 tags, an aws:
prefix on a key or a value, an empty key, a character outside AWS's set. And Department and
department stop being distinct on a user or a role — a second differently-cased key now
collapses into the first — while staying distinct on a policy or instance profile; an untag is
case-insensitive for the same two types.

@scttfrdmn scttfrdmn added this to the v0.113.0 milestone Sep 12, 2026
@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 248418c into main Sep 12, 2026
17 checks passed
@scttfrdmn
scttfrdmn deleted the feat/806-iam-tag-validation branch September 12, 2026 06:44
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(iam): tag validation is absent — no 50-tag cap, no aws: prefix rejection, wrong key case rules

1 participant