Repository navigation
feat(iam): validate a tag against the rules AWS publishes (#806) - #822
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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 #806
All twelve IAM paths that accept a tag — the four
Tag*, the fourUntag*and the fourCreate*— accepted anything at all: fifty-one tags, an empty key, a key or value beginningwith the reserved
aws:prefix, a character outside the set AWS publishes. A consumer testingthe error branch its tagging code has for each of those got a
200and a stored tag, so thebranch 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.
Tag— "Minimum length of 1. Maximum length of 128"ValidationError/400Tag— "Minimum length of 0. Maximum length of 256"ValidationError/400[\p{L}\p{Z}\p{N}_.:/=+\-@]+Tag— PatternValidationError/400[\p{L}\p{Z}\p{N}_.:/=+\-@]*Tag— PatternValidationError/400Tags.member.N/TagKeys.member.N— "Array Members: Maximum number of 50 items"ValidationError/400aws:aws:"InvalidInput/400LimitExceeded/409The 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 ofArabic-Indic digits are accepted, where the ASCII whitelist the User Guide's prose rendering
suggests ("letters, numbers, spaces, and
_ . : / = + - @") would refuse them. Lengths arecounted 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
ec2CheckTagLimitdoes: rewriting a key'svalue 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 matchedcase-sensitively, so
AWS:billingstays 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:
ValidationError/400 — the code the IAM pluginalready returns for every other shape violation, and the only 400 the four
Untag*operationsdeclare at all (their lists carry
ConcurrentModification,NoSuchEntityandServiceFailure,and not
InvalidInput).InvalidInput/400, which every tag-writing and create operation documents.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 andServiceFailure/500 are declared on all twelve and areunreachable by construction (#806's fourth criterion): a tagging handler's read-modify-write
runs synchronously inside one request against a
StateManagerthat serializes its own access, sonothing 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.
Department=financethendepartment=hryieldsDepartment=hr— one tag, stored spelling, new valueCase 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:ResourceTagcondition 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 anentity cannot be born holding two keys no later
Tag*could produce.Ordering
Validation runs after
p.authorizeand before the entity load on all twelve paths. So anunauthorized caller with an illegal payload is told
AccessDenied— the same answer a legal onegets — 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 noentity behind, per
CreateUser's "If any one of the tags is invalid or if you exceed theallowed maximum number of tags, then the entire request fails and the resource is not created."
iamMemberTagsbecomes a pure decoder and stops dropping a wholly empty member. Dropping itsilently accepted a request AWS refuses outright, and would now hide it from the validator. It
still answers
nilfor a genuinely absent list, which is what the JSON fallback depends on; twoTestIAMMemberTagscases are rewritten with comments recording the reversal.Not enforced, deliberately
Tag.ValueisRequired: Yes, but an omittedTags.member.N.Valuearrives on the query wire asthe 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 ="), soit is accepted rather than guessed at. An empty key is refused, by the minimum length of 1 and
the pattern's
+alike.docs/services.mdsays so.Tests
Nine tests, 93 subtests, in a new
emulator/iam_tag_validation_test.go, driven through theform 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
Tagdata type and a rule enforced on a user but not an instance profile is the same defect.Department/departmentcollapsing on a user and role, distinct on a policy and profileDEPARTMENThitting on a user and missing on a policyNoSuchEntitybehindFail-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 vetclean,golangci-lint run ./...reports0 issues.,make testandGOTOOLCHAIN=go1.26.6 make testpass, coverage holds at emulator 83.7% / total 83.1%,make docs-reference docs-reference-check docs-versions authz-reference-checkclean,npm --prefix docs run buildclean,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
Departmentanddepartmentstop being distinct on a user or a role — a second differently-cased key nowcollapses into the first — while staying distinct on a policy or instance profile; an untag is
case-insensitive for the same two types.