Skip to content

fix(tagging): scope every scanned resource to the caller's account and Region (#937) - #944

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/tagging-scan-region-scope
Sep 16, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/tagging-scan-region-scope

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

GetResources "[r]eturns all the tagged or previously tagged resources that are located in the
specified AWS Region
for the account" (API_GetResources, opening sentence). Substrate did not
scope 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-1 caller was reported a us-west-2 EC2
instance, 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 reported
ARN's own account and Region segments (taggingResourceInScope), rather than once per scanner. This
is 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 (ecsScanPrefix renamed taggingScanPrefix,
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:

  • An empty account or Region segment means the ARN states no such scope, and the resource is in
    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.
  • It does not replace CloudFront's own us-east-1 gate. A CloudFront ARN is Region-less too, but
    AWS publishes CloudFront tagging through that one Region, which is narrower than an empty segment
    can express.
  • An ARN that does not parse stays in scope rather than being dropped, per cfn: Ref returns the physical ID for every type, but AWS returns an ARN for an ELBv2 load balancer and target group #827: a malformed ARN
    substrate built should show up as a wrong row, not hide behind a missing one.

S3Bucket gains an AccountID, written at creation. A bucket ARN is arn:aws:s3:::{name} — S3's
bucket 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.go and tagging_ssm_test.go), 4 (met and exceeded — the account test runs over
all 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:

  • 1 asked that every scanner's prefix carry the account and Region, with CloudFront the sole
    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.
  • 5 asked that the S3, Lambda and DynamoDB key shapes either gain the missing components with a
    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 S3Bucket gained 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.md as 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 resource
created through its owning operation against the target Region's endpoint (no putTest* helper,
per #765's rule):

  • a resource created in one Region is not reported to a caller in the other — both directions from
    both Regions
    ;
  • a resource created by one account is not reported to the other, over all 17 rows;
  • an IAM user is reported in every Region and not to the foreign account. Left untested, a
    filter that read an empty Region as "not my Region" would make every IAM entity invisible to
    GetResources everywhere, and no per-Region test would notice.

Proven non-vacuous. With tagging_plugin.go reverted to HEAD, the new suite produces 22
failures: 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 GetResources reports an
untagged 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, because
AMI IDs are minted per Region and a literal answers InvalidAMIID.NotFound — which is itself why a
Region-scoped launch is assertable.

Verification

The nine-command gate passes: gofmt/go build/go vet clean, golangci-lint 0 issues, make test
and GOTOOLCHAIN=go1.26.6 make test ok, coverage 84.2% emulator / 83.7% total (baseline held
exactly), make docs-reference docs-reference-check docs-versions authz-reference-check ok,
npm --prefix docs run build ok, e2e vet and test ok.

Closes #937.

…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

codecov Bot commented Sep 16, 2026

Copy link
Copy Markdown

Codecov Report

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

Files with missing lines Patch % Lines
emulator/tagging_plugin.go 97.67% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 96b7bec into main Sep 16, 2026
17 checks passed
@scttfrdmn
scttfrdmn deleted the fix/tagging-scan-region-scope branch September 16, 2026 04:57
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.

fix(tagging): GetResources reports resources from other Regions, and three scanners from other accounts

1 participant