Skip to content

EC2 tag key (128) and value (256) length limits are not enforced #490

Closed

Description

@scttfrdmn

What

v0.86.0 added the 50-tag-per-resource limit
and reserved aws: key rejection on every tag-on-create path.
Two documented restrictions from the same Tag restrictions table are still not
enforced:

  • Maximum key length – 128 Unicode characters
  • Maximum value length – 256 Unicode characters

Substrate accepts a key or value of any length, so a consumer that would hit AWS's
ceiling gets success here and a rejection there — the same silent-success shape #469
closed for the count.

Notes on getting it right

  • The limits are in Unicode characters, not bytes. A key of 128 emoji is legal at
    128 characters and illegal if counted as UTF-8 bytes. Use utf8.RuneCountInString,
    not len — this is the detail a test with ASCII-only fixtures will not catch, so the
    test table needs a multi-byte row.
  • aws:-prefixed keys: the count exemption in EC2: the 50-tag-per-resource limit is unmodelled (TagLimitExceeded never fires) #469 does not obviously extend to
    length, and substrate's own aws:ec2:fleet-id is far under both limits either way.
    Check the documentation rather than assuming, and state which way it went.
  • The error code needs research. InvalidParameterValue is the likely candidate by
    analogy with the reserved-key rejection, but per
    #487 the message text needs its
    own source — a capture, or moto/LocalStack — or it ships as substrate's own text,
    labelled as such in the comment.
  • The check belongs beside the existing two in ec2_tags.go, so it applies to
    CreateTags, DeleteTags, and every tag-on-create path at once, and before
    anything is created — same rollback property EC2: RunInstances and other tag-on-create paths accept reserved aws: tag keys #468 established.
  • A launch template's instance-scoped tags are checked at CreateLaunchTemplate /
    CreateLaunchTemplateVersion as well as at launch, following EC2: a launch template's TagSpecifications and IamInstanceProfile are not parsed #471.

Acceptance criteria

  • A 129-character key and a 257-character value are each rejected, HTTP 400; 128 and
    256 are accepted.
  • Length is counted in Unicode characters — a multi-byte fixture at exactly the
    limit is accepted.
  • The rejection lands before any resource is created or tagged, on every
    tag-on-create path.
  • Launch-template tags are covered at template creation and at launch.
  • docs/services.md replaces its "Two documented restrictions substrate does not
    enforce" paragraph, and the message's provenance is stated.

Referenced as tracked separately from docs/services.md's
50-tag-per-resource limit section
and the v0.86.0 CHANGELOG.

Activity

  1. added this to the v0.87.0 milestone on Aug 2, 2026
  2. scttfrdmn commented on Aug 2, 2026

    @scttfrdmn
    OwnerAuthor

    Fixed in 468e785 (#505), shipping in v0.87.0. Your open question is settled, and the answer is the opposite of the convenient one.

    The aws: exemption does not extend to length. You flagged this as needing research. The tag restrictions list scopes the exemption to the count alone — "Tags with the aws: prefix do not count against your tags per resource limit" — and nothing on that page exempts a reserved key from the length limits. So reserved keys are length-checked. That makes ec2CheckTagLengths deliberately narrower than #469's ec2CheckTagLimit, which does exempt them, and since the two functions sit adjacent the comment carries the quote — a reader finding one function exempting aws: and its neighbour not is going to assume one is a bug. Substrate's own aws:ec2:fleet-id is far under both limits, so nothing this emulator stamps is affected.

    Two other details from the same list, both worth a test row:

    • Unicode characters, not bytes. "Maximum key length – 128 Unicode characters in UTF-8" (256 for a value). The check counts runes, so a 128-emoji key is legal and a 129-rune multi-byte key is not. The suite has an emoji row precisely because an ASCII-only table passes under len by accident — which is the implementation a reader would write first.
    • An empty value is legal — "You can set the value of a tag to an empty string, but you can't set the value of a tag to null" — so the check is upper-bound only. A naive > 0 && guard would have rejected it.

    DeleteTags names keys with an optional value, so it checks what is supplied and no more.

    On provenance, this is the weakest claim in the release and is marked as such. InvalidParameterValue (400) is by analogy with ec2ReservedTagKeyError — as your report says, that is the strongest available basis, and no capture of a real length rejection exists (moto and LocalStack were checked and neither enforces it either). The message is substrate's own, naming which limit was exceeded and by how much, following sqsMessageTooLong's precedent, and the comment says so. #487 covers the general problem.

    Wiring, per your third criterion: the check runs wherever ec2CheckReservedTagKeys runs — CreateTags, DeleteTags, and every tag-on-create path through ec2LaunchTagsForResource / ec2TagSpecificationTags — before any resource is created, per #468's rollback rule. So RunInstances with an over-long tag creates no instance, and CreateImage and CreateNatGateway create nothing. It also runs in ec2CheckTemplateTags, so a launch template's instance-scoped tags are rejected at CreateLaunchTemplate and CreateLaunchTemplateVersion as well as at launch, following #471.

    The #468 and #469 suites pass unchanged.

  3. added a commit that references this issue on Aug 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: taggingfidelitytype: feature

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions