Skip to content

fix(#1000): the tagging API enforces four services' tag quotas, and two shipped claims are corrected - #1078

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/1000-rgta-tag-quotas
Sep 18, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/1000-rgta-tag-quotas

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #1000.

TagResources was the one way in substrate to put a resource over its own service's published
per-resource tag quota. Four services enforce one on their own tagging operations — EC2, ELBv2, IAM
and Kinesis, all four at fifty — and all four are reachable through TaggingPlugin.resolveARN, whose
shared merge consulted none of them. So a caller could tag a resource past its quota through one API and
then find the owning service's own operation refusing every further add: a resource in a state
substrate's own reference says cannot exist, reached through substrate's own API.

API_TagResources states the rule itself — "Each resource can have up to 50 tags" — so enforcing it
here needed no borrowing from the four services by analogy, which is the #671 rule.

The issue named one service; it is four

Two of #1000's premises are false, and both were shipped in substrate's own record by #965:

  • docs/services.md (Kinesis) and CHANGELOG.md (v0.118.0) both said Kinesis was substrate's first
    per-resource tag quota for any service. EC2 (ec2_tags.go), ELBv2 (elb_tags.go) and IAM
    (iam_tag_validation.go) each had one already, and all three have a tagging-API arm. Kinesis was the
    fourth, not the first.
  • Both said the shared merge covers sixteen services. It is 23 namespace arms.

Both statements are corrected in place rather than quietly superseded — the CHANGELOG paragraph keeps its
original text with a bracketed correction naming this issue, since the entry is a historical record of
what shipped, and the docs/services.md paragraph is rewritten, since it describes current behaviour.

Three readings this makes

1. The refusal carries the owning service's own code, not one of FailureInfo's two enumerated ones.
That member publishes Valid Values: InternalServiceException | InvalidParameterException and, in the
same member's prose, that it "can also include any valid error code returned by the AWS service that
hosts the resource that the ARN key represents"
— offering AccessDeniedException, which is in neither
enumerated value, as its example. The prose is the half that fits here: neither enumerated code says
this resource is full, and InternalServiceException tells the caller it is "safe to retry", which is
the same wrong answer #939 moved the not-found case off. Every other failure still reports an enumerated
code, because for those the enumeration loses nothing.

2. The quota is enforced on the RGTA path and on neither CloudFormation path, and the two deployer
sites are skipped for two different reasons:

  • cfnStampResourceTags writes only aws:cloudformation:* keys, and EC2 and ELBv2 state outright that
    "[t]ags with the aws: prefix do not count against your tags per resource limit". Counting the stamp
    would refuse a deploy on a rule AWS states about something else.
  • cfnPropagateRecordStackTags writes the caller's own stack tags, which a quota could legitimately
    refuse. It is skipped because nothing published says what CloudFormation does when propagation would
    exceed a resource's quota — CloudFormation publishes a 50-tag limit on the stack, and the
    resource-side interaction is in neither its quotas page nor any operation's Errors section. Refusing
    there would also turn a tag overflow into a failed deploy, which is a larger decision than this issue
    asks for. Filed as CloudFormation stack-tag propagation can push a resource past its service's tag quota, and nothing published says what AWS does there #1077 rather than guessed.

All three writers go through mergeResourceTags, which is the point of that function, so the difference
is a tagQuotaMode parameter rather than a second merge.

3. Each service's own checker is called rather than a shared count, because the four disagree in ways
a shared count would have to flatten:

Service Code Status Reserved aws: keys
EC2 TagLimitExceeded 400 Excluded from the count
ELBv2 TooManyTags 400 Excluded from the count
IAM LimitExceeded 409 Counted
Kinesis LimitExceededException 400 Counted

The reserved-key column is what each service publishes, not a choice — no IAM or Kinesis page says
anything like EC2's and ELB's sentence — so it is recorded rather than unified. It is unobservable
through this API either way, since a reserved key is refused upstream and only the stamp path writes one.

Shape

  • New emulator/tagging_tag_quota.go: tagQuotaMode, the *taggingQuotaError carrier, and
    taggingCheckTagQuota with one arm per service. Each arm does a minimal decode of the stored
    record's tag member alone rather than the arm's own concrete type, so this file needs no knowledge of
    which of a namespace's several record shapes a key names; nothing is written back, so it cannot
    truncate anything. An undecodable record is passed rather than refused, because the merge arm below
    is about to fail on the same bytes with a message naming the actual problem.
  • The gate sits in mergeResourceTags immediately after the raw == nil check and before the
    switch, so a refused request writes nothing — the rule kinesis: AddTagsToStream enforces no per-stream tag quota, and AWS's reference publishes two different limits #965 established for the service-side quotas
    this reuses — and so a service that gains a quota later needs only a case in the checker.
  • tagMergeFailure gains a first arm that errors.As-matches the carrier and renders its code, message
    and status into the FailedResourcesMap entry. The per-resource map already existed.
  • iamTagLimitError now derives from a new iamTagLimitAWSError, so IAM's code, message and 409 live in
    one place across the *AWSResponse and *AWSError shapes; iamCheckTagLimitAWSError is the second
    shape of the same threshold.
  • MergeResourceTagsForTest is added because both deployer sites pass skipTagQuota and no template in
    the tree brings a resource near a quota, so nothing over the wire distinguishes a scoped gate from an
    absent one.

Verification

Six new tests in emulator/tagging_tag_quota_test.go, every one of which writes through
TagResources and reads back through the owning service's own call
— the #863 both-directions proof,
and the only assertion that separates a quota honoured from a code answered beside a completed write:

  • the fifty-first tag is refused with each service's own code and status, and the read-back still
    reports fifty;
  • a rewrite of an existing key is not an addition, so it succeeds at the quota (the direction a
    len(existing)+len(incoming) count gets wrong);
  • UntagResources is never refused, and the slot it frees is usable;
  • one refusal does not stop the other ARNs in the same request, and the request still answers 200;
  • SQS at sixty tags is unaffected, since substrate models no SQS tag quota on TagQueue either and
    inventing one here alone would make the two APIs disagree in the opposite direction;
  • the CloudFormation stamp is not counted, asserted on Kinesis because it is one of the two services
    that counts aws: keys — so it is the case where the two modes give different answers, where on EC2
    and ELBv2 the test would pass against a gate that had no mode at all.

Short-circuiting taggingCheckTagQuota to return nil fails seven of them, including all four service
subtests.

Full gate green: gofmt/go build/go vet, golangci-lint run ./... (0 issues), go test -race ./...
on both toolchains, test/e2e, scripts/check-discarded-unmarshal.sh,
scripts/check-doc-versions.sh, gen-service-reference -check, gen-authz-reference -check, and the
docs site build.

…wo shipped claims are corrected

TagResources was the one way in substrate to put a resource over its own service's
published per-resource tag quota. EC2, ELBv2, IAM and Kinesis each enforce one at
fifty on their own tagging operations, and all four are reachable through the
tagging API's resolver, whose shared merge consulted none of them — so a caller
could tag a resource into a state substrate's own reference says cannot exist,
through substrate's own API. API_TagResources states the rule itself.

The refusal carries the owning service's own code rather than one of FailureInfo's
two enumerated ones, on that member's own prose admitting "any valid error code
returned by the AWS service that hosts the resource". The four codes are not
unified: IAM answers 409 where the others answer 400, and EC2 and ELBv2 exclude
aws:-prefixed keys from the count on their own published statement where IAM and
Kinesis publish nothing of the kind.

Neither CloudFormation writer enforces it, for two different reasons: the stamp
writes only aws: keys, which two of the four exclude, and stack-tag propagation is
filed as #1077 because nothing published says what CloudFormation does when
propagation would exceed a resource's quota.

Corrects two claims #965 shipped: Kinesis was the fourth quota, not the first, and
the shared merge covers 23 arms, not sixteen.

Closes #1000.
@scttfrdmn
scttfrdmn merged commit bd8fed5 into main Sep 18, 2026
16 checks passed
@scttfrdmn
scttfrdmn deleted the fix/1000-rgta-tag-quotas branch September 18, 2026 20:43
@codecov

codecov Bot commented Sep 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.03571% with 19 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/tagging_tag_quota.go 77.64% 17 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

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.

tagging: TagResources bypasses the Kinesis per-stream tag quota, and no service's quota is enforced on that path

1 participant