Repository navigation
fix(tagging): scope every scanned resource to the caller's account and Region (#937) - #944
Merged
Merged
Conversation
…d Region (#937) GetResources "[r]eturns all the tagged or previously tagged resources that are located in the specified AWS Region for the account", but three scanners narrowed by nothing at all and fourteen more narrowed by account without the Region, so an S3 bucket, Lambda function or SQS queue in any account was reported to any caller and a us-east-1 caller was reported a us-west-2 instance. Scope is now decided at one choke point in the scan loop, off each reported ARN's own account and Region segments, rather than once per scanner. That is the read-side form of the rule #826 through #932 established for the write side. The state-key prefixes still narrow through one shared helper, but they narrow what gets loaded rather than holding the guarantee, so no key shape changed. An empty account or Region segment means the ARN states no such scope and the resource stays in scope everywhere, which is how an IAM entity keeps being reported in every Region without an exception; CloudFront's own us-east-1 gate stays, because it is narrower than an empty segment can express. An ARN that does not parse is left in scope rather than dropped (#827). An S3 bucket is scoped off its record instead, since its ARN carries neither segment, so S3Bucket gains an AccountID written at creation.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
GetResources"[r]eturns all the tagged or previously tagged resources that are located in thespecified AWS Region for the account" (
API_GetResources, opening sentence). Substrate did notscope that way. Three scanners — S3, Lambda, SQS — narrowed their state-key scan by nothing at all,
so a bucket, function or queue in any account was reported to any caller. Fourteen more
narrowed by account without the Region, so a
us-east-1caller was reported aus-west-2EC2instance, API, state machine, activity, ECR repository, user pool, Kinesis stream, RDS instance,
cluster or subnet group, cache cluster, file system, Glue database or DynamoDB table.
The design
Scope is decided at one choke point in
scanAllResources' accumulation loop, off each reportedARN's own account and Region segments (
taggingResourceInScope), rather than once per scanner. Thisis the read-side form of the rule #826 through #932 established for the write side: take the account
and Region from the ARN, never from the caller.
Reading the ARN is what makes it one rule instead of twenty-nine prefixes. A scanner whose key
carries no Region cannot express the scope in a prefix at all, and a scanner that can has to remember
to — which the ECS cluster scanner did not (#935). The state-key prefixes still narrow wherever the
key can carry the scope, now through one shared helper (
ecsScanPrefixrenamedtaggingScanPrefix,18 prefixes converted), but they narrow what gets loaded rather than holding the guarantee.
No state-key shapes changed, so nothing that reads state by key is affected.
Three rules the filter needs, all documented in
docs/services.md:scope everywhere. IAM depends on it — an IAM ARN carries no Region, so an IAM user is reported to a
caller in any Region, which is what a global service should do.
us-east-1gate. A CloudFront ARN is Region-less too, butAWS publishes CloudFront tagging through that one Region, which is narrower than an empty segment
can express.
substrate built should show up as a wrong row, not hide behind a missing one.
S3Bucketgains anAccountID, written at creation. A bucket ARN isarn:aws:s3:::{name}— S3'sbucket namespace is global, so neither the ARN nor the key can carry an account or a Region, and the
filter cannot reach it. Its scanner scopes off the record instead: the Region a bucket already
stored, plus the new account field. An empty value stays in scope, on the same rule an absent ARN
segment gets, so a bucket written by a path with no request context is still reported.
Acceptance criteria
Met literally: 2 (every prefix colon-terminated — already true, recorded as such), 3 (17
service rows here; ACM/CloudFront, ECS and SSM are covered in
tagging_acm_cloudfront_test.go,tagging_ecs_test.goandtagging_ssm_test.go), 4 (met and exceeded — the account test runs overall 17 rows, not only the three account-blind scanners), 6.
Criteria 1 and 5 are answered by the design reversal posted on #937 before implementation, not as
written:
exemption. It cannot: DynamoDB's key has no Region, Lambda's and S3's have neither, and IAM's is
account-only because an IAM ARN has no Region. The outcome the criterion protects — no scanner can
report another account's or Region's resource — is what the central filter guarantees, and a prefix
cannot guarantee it for a key that has nowhere to put the scope. IAM is a second documented global
exemption alongside CloudFront.
stated migration decision, or that the scan be documented as reading both shapes. Neither branch
was taken: no key changed, the ARN filter holds the scope, and
S3Bucketgained a record field.The migration question is moot for the field because memory is the only state backend (sqlite is
feat: SQLite StateManager #2), and an absent field reads as empty, which stays in scope. The reasoning is recorded in
docs/services.mdas substrate's reading, which is the part of the criterion that survives.The Lambda and DynamoDB key shapes are wrong on their own terms — a Lambda function name is unique
per account per Region and a DynamoDB table name per Region, so neither key can hold two resources
AWS would let a caller create. That is filed as #943 with wire-verified reproductions rather than
folded into a read-side fix.
Tests
emulator/tagging_scan_scope_test.go, 17 services across all three request protocols, every resourcecreated through its owning operation against the target Region's endpoint (no
putTest*helper,per #765's rule):
both Regions;
filter that read an empty Region as "not my Region" would make every IAM entity invisible to
GetResourceseverywhere, and no per-Region test would notice.Proven non-vacuous. With
tagging_plugin.goreverted toHEAD, the new suite produces 22failures: all 17 Region rows, and exactly three account rows —
s3_bucket,lambda_function,sqs_queue— which independently confirms both halves of the defect this describes.One dependency to record: none of these resources is tagged, because
GetResourcesreports anuntagged resource today. AWS omits one, which is #938; when that lands every row needs a tag
written before the assertion, and the row that fails will say which.
The EC2 row images from
emulator.BundledImageID(region, …)rather than a literal AMI ID, becauseAMI IDs are minted per Region and a literal answers
InvalidAMIID.NotFound— which is itself why aRegion-scoped launch is assertable.
Verification
The nine-command gate passes:
gofmt/go build/go vetclean,golangci-lint0 issues,make testand
GOTOOLCHAIN=go1.26.6 make testok, coverage 84.2% emulator / 83.7% total (baseline heldexactly),
make docs-reference docs-reference-check docs-versions authz-reference-checkok,npm --prefix docs run buildok, e2e vet and test ok.Closes #937.