Repository navigation
fix(kinesis): enforce both published tag limits on AddTagsToStream (#965) - #1001
Merged
Merged
Conversation
) API_AddTagsToStream publishes two different limits inside one parameter entry: the Tags member's description says fifty twice ("up to 50 tags per resource") and the constraint lines beneath it say "Map Entries: Maximum number of 200 items". Substrate enforced neither, so a stream could hold three hundred tags and ListTagsForStream would answer an array longer than its own published maximum — a response substrate's own reference says cannot exist. #954 recorded the disagreement as unenforced rather than deciding it. Both figures are real and bound different things, so both are enforced under different codes. More than 200 entries in one request violates the request's own shape and answers InvalidArgumentException/400, checked first against the request alone: a request that does not satisfy its own shape cannot be evaluated against account state. More than 50 tags on the stream once the request is applied is a quota violation and answers LimitExceededException/400. Both codes are published on the operation, at 400, as every Kinesis error is. The quota is a property of the stream, so it is counted against the merged set rather than the incoming map — two accepted requests of thirty tags each are refused on the second. A key already present does not count twice, since AddTagsToStream "overwrites any existing tags that correspond to the specified tag keys", so re-tagging a full stream with a key it already has is a rewrite and succeeds. The check runs before the merge, so a refused request writes nothing, and RemoveTagsFromStream freeing slots admits later adds. Since #966 the count follows the ARN's account. The Tags member's other constraints are enforced under the same code: key 1-128 characters, value at most 256. An empty value is accepted where an empty key is not, per "a tag consists of a required key and an optional value". An absent Tags member is refused; an empty map is a no-op, which is substrate's reading — the map publishes a maximum and no minimum where RemoveTagsFromStream's TagKeys publishes "Minimum number of 1 item". This is substrate's first per-resource tag quota for any service. The Resource Groups Tagging API does not enforce it, because that path merges tags for sixteen services through one helper and refusing there needs TagResources' per-resource FailedResourcesMap semantics; filed as #1000 rather than half-done here. Closes #965.
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 #965.
API_AddTagsToStreampublishes two different limits inside a single parameter entry. TheTagsmember's description reads "A set of up to 50 key-value pairs to use to create the tags. A tag consists of a required key and an optional value. You can add up to 50 tags per resource." — and the constraint lines directly beneath it read "Map Entries: Maximum number of 200 items." The operation's lede says fifty a third time, andAPI_ListTagsForStream'sLimitmaxes out at exactly fifty while its response array publishes 0–200.Substrate enforced neither, so a stream could hold three hundred tags and
ListTagsForStreamwould answer an array longer than its own published maximum — substrate emitting a response its own reference says cannot exist. #954 recorded the disagreement as unenforced rather than deciding it, which is what this closes.The decision, which the issue required before any code
Both figures are real, they bound different things, and both are enforced — under different codes. That is what makes them consistent rather than contradictory:
InvalidArgumentException/ 400LimitExceededException/ 400Both codes are published on
AddTagsToStreamat HTTP 400, as every Kinesis error is. The shape check runs before the stream is loaded, because a request that does not satisfy its own shape cannot be evaluated against account state at all — the same orderinglistTagsForStreamalready uses. The distinction is observable, and a consumer's retry path may reasonably care which it hit: a request it can split versus a stream it must prune.What the quota is counted against
The quota is a property of the stream, not of the request, so it is counted against the merged result:
AddTagsToStreamoverwrites any existing tags that correspond to the specified tag keys" — so re-tagging a stream already at fifty with a key it already has is a rewrite, and it succeeds. Countinglen(existing) + len(request)would refuse it.ListTagsForStream(cfn: the aws:cloudformation:* stamp covers EC2 only, so the rest of a stack is unstamped #765) rather than inspecting state, following kms: EnableKeyRotation and DisableKeyRotation succeed against a disabled key, where AWS publishes DisabledException/400 #949's ordering.RemoveTagsFromStreamfreeing slots admits later adds, so the limit is read off current state rather than off anything the stream remembers.The rest of the member's published constraints
Enforced in the same pass, each under
InvalidArgumentException: a key of 1–128 characters, a value of at most 256. An empty value is accepted where an empty key is not, per "a tag consists of a required key and an optional value" and the published minimums that say the same.An absent
Tagsis refused, being the operation's oneRequired: Yesmember other than the stream reference. An empty map is accepted as a no-op, which is substrate's reading: the map publishes a maximum entry count and no minimum, where the siblingRemoveTagsFromStream'sTagKeyspublishes "Minimum number of 1 item" — AWS states a minimum where it means one, and reading one in here anyway would refuse a request the shape admits.A refusal names the offending key, the current count and the limit, because a caller whose one bad tag is among fifty cannot act on a message that will not say which.
Not fixed here, and filed
This is substrate's first per-resource tag quota for any service, and the Resource Groups Tagging API does not enforce it. That path merges tags for sixteen services through one helper, and refusing there needs the per-resource
FailedResourcesMapsemanticsTagResourcespublishes — a partial-failure shape substrate's tagging helper does not model. So a caller can still push a stream past fifty tags throughTagResources, filed as #1000 rather than half-done here;AddTagsToStreamthen refuses every further add, which is the right answer for a stream over quota however it got there.docs/services.mdsays so rather than leaving the reader to find out.Also left alone, deliberately:
RemoveTagsFromStreamenforces neither itsTagKeys' 1–50 bound nor its per-key 1–128 length, andCreateStreamenforces neitherStreamName's length nor its pattern. Both are separate findings, not this issue's.Tests
emulator/kinesis_tag_quota_test.go— 22 subtests, all over the wire. The load-bearing ones are the accumulation cases, since a single oversized request cannot show the limit is a property of the stream: fifty then one, thirty then thirty, and forty-eight then five read back to show nothing landed. The two codes are kept apart on both sides — 201 entries on an empty stream (where no quota is in play at all) must answerInvalidArgumentException, and 51/100/200 must answerLimitExceededException— so a test would notice the two being collapsed into one code. The boundary is asserted on both sides at fifty and at 128/129 and 256/257. Status and code, per #923.Verification
All nine gate commands green. Coverage holds the baseline at 84.6% emulator / 84.1% total.