Skip to content

fix(kinesis): enforce both published tag limits on AddTagsToStream (#965) - #1001

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/kinesis-tag-quota
Sep 17, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/kinesis-tag-quota

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #965.

API_AddTagsToStream publishes two different limits inside a single parameter entry. The Tags member'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, and API_ListTagsForStream's Limit maxes out at exactly fifty while its response array publishes 0–200.

Substrate enforced neither, so a stream could hold three hundred tags and ListTagsForStream would 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:

Request Answer Why
More than 200 entries in one call InvalidArgumentException / 400 The request's own shape bound. Its description — "a specified parameter exceeds its restrictions, is not supported, or can't be used" — is this case exactly. Checked first, against the request alone.
More than 50 tags on the stream once applied LimitExceededException / 400 The resource's quota. Its description is "the requested resource exceeds the maximum number allowed". Checked against the merged result.

Both codes are published on AddTagsToStream at 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 ordering listTagsForStream already 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:

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 Tags is refused, being the operation's one Required: Yes member 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 sibling RemoveTagsFromStream's TagKeys publishes "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 FailedResourcesMap semantics TagResources publishes — a partial-failure shape substrate's tagging helper does not model. So a caller can still push a stream past fifty tags through TagResources, filed as #1000 rather than half-done here; AddTagsToStream then refuses every further add, which is the right answer for a stream over quota however it got there. docs/services.md says so rather than leaving the reader to find out.

Also left alone, deliberately: RemoveTagsFromStream enforces neither its TagKeys' 1–50 bound nor its per-key 1–128 length, and CreateStream enforces neither StreamName'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 answer InvalidArgumentException, and 51/100/200 must answer LimitExceededException — 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.

)

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.
@scttfrdmn scttfrdmn added this to the v0.118.0 milestone Sep 17, 2026
@codecov

codecov Bot commented Sep 17, 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 0ccd346 into main Sep 17, 2026
17 checks passed
@scttfrdmn
scttfrdmn deleted the fix/kinesis-tag-quota branch September 17, 2026 07:57
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.

kinesis: AddTagsToStream enforces no per-stream tag quota, and AWS's reference publishes two different limits

1 participant