Repository navigation
refactor(#1609): tagging providers, with CloudWatch, EC2 and S3 as pilots - #1673
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…lots Plugins that own tagged resources can answer the Resource Groups Tagging API through two unexported optional interfaces in tagging_providers.go: taggableResourceLister (GetResources) and resourceTagger (TagResources, UntagResources and CloudFormation's stamps through mergeResourceTags), found through the registry the way ResetPlugins and RunClockDriven find theirs. The tagging plugin prefers an implementer and falls back to its direct paths. CloudWatch (replacing routeAlarmTags' RouteRequest), EC2 and S3 implement both. Their scan, resolve, merge and quota code moves to cloudwatch_tags.go, ec2_tags.go and s3_tagging.go, and their tag writes run under the lock their own tag operations hold: CloudWatch's mu, a new EC2 tagMu taken by CreateTags/DeleteTags, and the bucket's slot in S3's key locks taken by PutBucketTagging/DeleteBucketTagging.
- CloudFormation's EC2 stamp and stack-tag propagation go through the EC2 plugin's tag lock (ec2ApplyTagsThroughOwner, EC2Plugin.applyTagsByID). - TagResources/UntagResources refuse aws: keys: EC2 and S3 apply their own key rules (ec2CheckTagRules, s3CheckTagSet), every other service gets the tagging API's InvalidParameterException. tagRecord keeps the allowance for internal stamps. - S3 tagRecord enforces the 50-tag bucket limit, aws: keys uncounted. - Alarms have a state-taking merge (cwMergeAlarmTags) the direct path uses, and it merges additions and removals together before cwCheckTags. - The lock comments say what is serialized and no more; per-record locking is #1674. - AnswersMatchTheDirectPath diffs every response body, pages and tokens included; new tests for reserved keys, owner key rules, the S3 limit, the alarm merge and a CFN-propagation-vs-CreateTags race.
scttfrdmn
force-pushed
the
refactor/v0132-tagging-providers
branch
from
November 24, 2026 03:35
19491cc to
74701d8
Compare
- The tagging plugin's direct path applies EC2's and S3's own key rules (ec2TagKeyRefusal, s3TagKeyRefusal) and S3's bucket limit (taggingCheckTagQuota's new s3 arm), so a resource gets one answer whether or not its plugin is registered. - One reserved-prefix rule, taggingReservedKey, case-sensitive per EC2's tag restrictions, which S3's tagging pages defer to. S3 no longer refuses AWS:-prefixed keys. - Order: an unresolvable ARN, then a refused key, then a missing resource, on both paths. - S3's 50-tag rule is one rule, user tags only, cited on s3BucketTagQuotaRefusal. - AnswersMatchTheDirectPath covers reserved, uppercase, over-long and over-50 keys and a reserved key on a missing resource.
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.
Part of #1609 — this is part 3 (tagging behind a plugin interface), framework plus three pilots. The other services are tracked in #1672 (v0.137.0, five batches plus retiring the direct paths). Part 1 (#1667) has merged; this is rebased onto it. Part 2 (the comment rule, gates and trims) is W3's PR.
Rebased onto main at bcff881 (after W1 #1668 and W4 #1670).
emulator/tagging_providers.go): two unexported optional interfaces.taggableResourceLister.listTaggedResources(ctx, reqCtx)serves GetResources.resourceTagger.tagResourceByARN(reqCtx, arn, add, remove, quota)serves TagResources and UntagResources.resourceTagger.tagRecord(ctx, key, add, remove, quota)is whatmergeResourceTagscalls, so CloudFormation'saws:cloudformation:*stamps and stack-tag propagation reach the same writer. Neither method refuses anaws:key.PluginRegistry, the wayResetPluginsandRunClockDrivenfind theirs. The type assertion runs under the read lock, and the lock is released before any plugin is called.scanAllResourcesruns ascanPlan. It asks an owner's lister once, in place of its first descriptor, and drops that owner's other descriptors.tagResourcesanduntagResourcesgo throughtagARN. It calls the owner'stagResourceByARNwhen there is one, and otherwise callsresolveARNand thenmergeResourceTags. A resolution failure from either path is wrapped astaggingResolveError, sotagFailurestill sends it throughtagResolveFailure. Every published code and status is unchanged.mergeResourceTagstakes the registry, socfnStampResourceTagsandcfnPropagateStackTagspassd.registry, and it delegates to the namespace owner'stagRecord.taggingCheckTagQuotanow runs only on the fallback path. Each pilot checks its own quota insidetagRecord.cloudwatch_tags.go):routeAlarmTags'RouteRequestand themergeTagswrapper are gone. Writes run underCloudWatchPlugin.mu, with TagResource's merge,cwCheckTagsquota and tag-history stamp, and UntagResource's removal. TheMissingParameterthat a TagResources with no tags used to get from the routed UntagResource is kept.ec2_tags.go): instances, Elastic IPs, security groups, launch templates and volumes, in one lister. A newEC2Plugin.tagMuis taken byCreateTags,DeleteTagsandtagRecord. The 50-tag quota (taggingEC2QuotaRefusal) moves here.s3_tagging.go): bucket tag writes hold the bucket's slot inS3Plugin.keyLocksunder the empty object key (lockBucketTags).PutBucketTagging,DeleteBucketTaggingandtagRecordtake it.docs/reference/tagging.mdsays which services list and tag their own resources, what the lock orders, and theaws:refusal.docs/reference/monitoring.mdupdates its alarm-tag note.Review fixes (second commit, 19491cc)
stampCFNResourceTags) and stack-tag propagation (cfnPropagateEC2StackTags) now go throughec2ApplyTagsThroughOwner→EC2Plugin.applyTagsByID, which holdstagMu. It does not usetagRecord: CloudFormation addresses EC2 resources by ID across all sixteen ID shapes, with the upsert semantics ofec2ApplyTagsToResource, andtagRecord's merge covers only the five types the tagging API scans.aws:keys are refused on the public path (Compatibility).TagResourcesandUntagResourcesrefuse anaws:key for every resource.ec2CheckTagRulesto the keys it adds and removes, and answersInvalidParameterValue.s3CheckTagSet, PutBucketTagging's rules extracted to return anAWSError, and answersInvalidTag.InvalidParameterException/400. The message is substrate's own; the source is the Tagging AWS Resources guide.tagRecordkeeps the allowance, so CloudFormation's stamps still land.tagRecordholds the merged set to 50 tags, withaws:keys not counted, and answersInvalidTag.cwMergeAlarmTagstakes the state, andmergeResourceTagsuses it on the direct path. An existing alarm now merges there, and a missing one answers 400 (Fixed: it was 500 before).cwCheckTags.area: tagging,area: ec2andarea: s3.Review fixes, round 2 (3471653)
ec2TagKeyRefusal,s3TagKeyRefusal) and S3's bucket limit (a news3arm intaggingCheckTagQuota).taggingReservedKey. It is case-sensitive, following EC2's Tag restrictions ("Tag keys and values are case-sensitive"; "The aws: prefix is reserved for AWS use"), which S3's tagging pages defer to. It also matches the observed EC2 behaviour, which acceptsAWS:foo. ECS's Tag shape reserves every case of the prefix, but that is ECS's own rule.AWS:-prefixed key as an ordinary tag. One row ofs3_upload_tagging_test.gothat expected the opposite is removed.aws:tags not counted. It is cited ons3BucketTagQuotaRefusal. PutBucketTagging counts its whole set because a caller's set cannot contain a reserved key.AnswersMatchTheDirectPathnow also covers anaws:key added and removed, an uppercaseAWS:key, an over-long key, a reserved key on a missing resource, and a resource filled to 50 tags followed by a 51st.Tests
export_test.go, which gains three accessors and passesnilfor the new registry parameter inMergeResourceTagsForTest.tagging_providers_test.go:ThePilotsImplementBothInterfaces: in a default registry, the listers and taggers are exactlyec2,monitoringands3.EachPilotAnswersItsScanOnceAndNoDirectReadRuns: with a registry, each pilot's plan step islisterexactly once and is neverdirect. Without one, each isdirect, and Lambda isdirecteither way.EachPilotWritesItsOwnTags: tag writes for each pilot's ARNs go to its own tagger, and to none without a registry.AnswersMatchTheDirectPath: one script runs against both environments, and every response body must be byte-identical. That covers every FailedResourcesMap, every GetResources page withResourcesPerPage=1and its token, the type-filtered scans, and an existing alarm.ReservedKeysAreRefused, with and without a registry, andOwnerKeyRulesApply.AlarmMergesAddAndRemoveTogether.CFNStackTagsDoNotRaceCreateTags. With the lock bypassed it failed 19 runs out of 20.QuotasAreTheOwnersAnswer: EC2 answersTagLimitExceeded, CloudWatchInvalidParameterValueand S3InvalidTag, including S3's merged-set count. A refused merge writes nothing, and an empty write isMissingParameter.TagResourcesconcurrently with each pilot's own tag write: EC2CreateTags, CloudWatchTagResource, and S3 merges thenPutBucketTagging. WithtagRecord's lock removed, the EC2 and S3 tests failed 20 runs out of 20 before the lock was restored.tagResourceByARNandtaggingResolveError.Error.Gates (local)
make lint: 0 issuesmake test(race)make e2eSUBSTRATE_IAC=1 make iac-e2enondeterminism-check,docs-versions,docs-counts-check,cfn-schema-checkrm -rf docs/node_modulesFollow-ups filed: #1672 (the remaining services) and #1674 (per-record locks).