Skip to content

feat(organizations): validate inline tags on every create path (#578) - #613

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/org-tag-on-create-validation
Aug 9, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/org-tag-on-create-validation

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

CreateOrganizationalUnit, CreatePolicy and CreateAccount all accept an inline
Tags list, and each stored it without running it through the validation
TagResource applies. A key TagResource refuses could therefore be planted
through a create instead — and an aws:-prefixed one would then be readable as
aws:ResourceTag by a policy condition, so a tag-gated privilege boundary could be
crossed with a key AWS reserves for itself and never lets a caller write.

This was the one genuine gap the tagging lane disclosed when it landed: the three
create handlers belong to other clusters, and the validation helpers were written to
be called from them but were not wired up.

What changed

  • validateOrgCreateTags in organizations_tags.go — the shared entry point. Same
    key/value shapes as TagResource plus the per-resource count quota. The count is
    checked against the request alone rather than a merge, since a resource being
    created carries no tags yet.
  • All three creates call it before writing anything, so a refusal leaves nothing
    behind and a retry does not collide with a duplicate-name exception for a resource
    the caller does not believe it created. For CreateAccount the refusal is
    synchronous even though the success is not — a malformed request has nothing to
    vend.
  • Each Tags field moves from []OrgTag to []orgTagInput, so an absent value is
    distinguishable from an empty string (the first is refused, the second is legal).
  • orgValidateOUTags, which duplicated a weaker subset of the checks, is deleted.

Testing

TestOrganizations_CreateOperationsShareTagValidation runs one refusal table across
all three operations rather than a per-operation copy, so a create that drifts more
permissive than TagResource fails rather than being asserted only where someone
remembered to: system tag key, duplicate key, empty key, over-length key, key
outside the pattern, over-length value, over-quota count, plus a legal tag that must
still be accepted.

Mutation check: dropping the MAX_TAG_LIMIT_EXCEEDED guard from
validateOrgCreateTags fails the new test on all three operations — CAUGHT.

Gate: gofmt -l . clean, go build ./..., go vet ./...,
golangci-lint run ./... (0 issues), make test (race detector) all green.

Verified against the botocore Organizations model at
organizations/2016-11-28/service-2.json: the Tags member of all three create
shapes is the same Tags list TagResource takes.

Part of #578.

CreateOrganizationalUnit, CreatePolicy and CreateAccount all accept an
inline Tags list, and each stored it without running it through the
validation TagResource applies. A key TagResource refuses could therefore
be planted through a create instead — and an "aws:"-prefixed one would
then be readable as aws:ResourceTag by a policy condition, so a tag-gated
privilege boundary could be crossed with a key AWS reserves for itself
and never lets a caller write.

All three now share validateOrgCreateTags, which applies the same key and
value shapes plus the per-resource count quota. The count is checked
against the request alone, not a merge, since a resource being created
carries no tags yet. The refusal comes before anything is written, so a
retry does not collide with a duplicate-name exception for a resource the
caller does not believe it created; for CreateAccount that means the
refusal is synchronous even though the success is not, because a
malformed request has nothing to vend.

Each Tags field moves from []OrgTag to []orgTagInput so an absent value
is distinguishable from an empty string — the first is refused, the
second is legal — and orgValidateOUTags, which duplicated a weaker subset
of the checks, is deleted.

The new test runs one refusal table across all three operations rather
than a per-operation copy, so a create that drifts more permissive than
TagResource fails rather than being asserted only where someone
remembered to. Verified against the botocore Organizations model: the
Tags member of all three shapes is the same Tags list TagResource takes.

Part of #578.
@codecov

codecov Bot commented Aug 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.55172% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/organizations_policy.go 90.00% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 1e58e57 into main Aug 9, 2026
13 checks passed
@scttfrdmn
scttfrdmn deleted the fix/org-tag-on-create-validation branch August 9, 2026 17:07
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.

1 participant