Skip to content

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

Closed

Description

@scttfrdmn

The defect

GetResources reports resources from Regions — and in three cases accounts — other than the
caller's.

From API_GetResources:

Returns all the tagged or previously tagged resources that are located in the specified AWS
Region
for the account.

Substrate's twenty-five scanners (emulator/tagging_plugin.go:240-266) each build a state-key
prefix, and the prefix determines what the scan can see. Three tiers exist today:

Tier 1 — no account at all (3 scanners). The prefix carries neither account nor Region, so a
caller is reported every other account's resources as well as every other Region's:

Scanner Prefix Site
scanS3Buckets "bucket:" :282
scanLambdaFunctions "function:" :306
scanSQSQueues "queue:" :330

For S3 and Lambda the state key itself carries no account, so this cannot be fixed by changing the
prefix — it needs a key-shape change and a migration decision, the same one DynamoDB's missing
Region needs (below). SQS's key does carry an account and is a prefix fix.

Tier 2 — account but no Region (15 scanners). table:, instance:, api:, statemachine:,
activity, ecrrepo:, cluster:, userpool:, stream:, dbinstance:, dbcluster, subgrp,
cachecluster:, filesystem:, database:. A caller in us-west-2 is reported a us-east-1
resource. Two of these — activity and dbcluster/subgrp — are additionally not
colon-terminated
, which is the separate guard six namespaces have now needed.

DynamoDB is the hard one: "table:" + account + "/" + name (emulator/dynamodb_plugin.go) has no
Region in the key, so like S3 and Lambda it needs a key-shape change rather than a longer
prefix.

Tier 3 — account and Region (7 scanners). KMS, SNS, Secrets Manager, SSM, ACM and — after the
ECS row lands — ECS's four. CloudFront is correctly Region-less: its ARNs are global
(cfDistKeyPrefix + account + "/").

Why this is one issue and not twenty-five

The prefix is the whole mechanism, so every scanner in a tier is the same one-line change, and the
tiers differ only in whether the key already carries what the prefix needs. Splitting it per service
would file eighteen issues that share one test helper (getResourcesARNsIn, which already issues a
real request to another Region's endpoint) and one paragraph of docs/services.md.

The exception is the three key-shape changes — S3, Lambda and DynamoDB — which are a different
decision: an existing stored resource's key changes, so either the scan reads both shapes or the
stored state is migrated. Those are split into their own issue if the answer is not "read both".

Verified

The Region sentence above is GetResources' own opening line. The account scoping is not stated as
a restriction anywhere on that page — it is the tagging API's premise, since credentials name one
account — but the page's phrase "for the account" is the citation, and every one of substrate's
own resolvers takes its account from the ARN rather than from the caller precisely so the two cannot
disagree (#826, #845, #910, #918, #922, #925, #928, #932).

Acceptance criteria

  • Every scanner's prefix carries the caller's account and Region, except CloudFront, whose ARNs
    AWS publishes as global.
  • Each prefix is colon-terminated, including activity, dbcluster and subgrp.
  • A test per service asserts a resource created in one Region is not reported to a caller in
    another, through a real request to the other Region's endpoint (getResourcesARNsIn).
  • A test asserts a resource in another account is not reported, for the three account-blind
    scanners.
  • The S3, Lambda and DynamoDB key shapes either gain the missing components with a stated
    migration decision, or the scan is documented as reading both shapes — and whichever is chosen
    is recorded in docs/services.md as substrate's reading.
  • docs/services.md's GetResources section states the Region and account scoping with AWS's
    sentence as the citation.

Activity

  1. added this to the v0.118.0 milestone on Sep 16, 2026
  2. added
    type: bug
    on Sep 16, 2026
  3. scttfrdmn commented on Sep 16, 2026

    @scttfrdmn
    OwnerAuthor

    Surveyed all of it against the tree at 2026125. Five of the issue body's claims need correcting
    before any of it is acted on, and one of them changes the design.

    1. The count is 28 scanner functions, not 25. They yield 29 resource types (scanIAMEntities
    yields a user and a role), and 33 types are reachable when the four that only
    TagResources/UntagResources reach are counted — an EFS access point, and a Glue job, crawler and
    connection. ECS's four landed in #935 after this issue was written.

    2. AC 2 is already met. activity, dbcluster and subgrp are named as not colon-terminated;
    all three are colon-terminated named constants — sfnActivityKeyPrefix = "activity:"
    (stepfunctions_tags.go:42), rdsDBClusterKeyPrefix = "dbcluster:" (rds_tags.go:42) and
    rdsDBSubnetGroupKeyPrefix = "dbsubnetgroup:" (rds_tags.go:44, so the third is not spelled
    subgrp at all). Nothing to do; the checkbox is satisfied as written.

    3. AC 1's "except CloudFront" misses a second global service: IAM. An IAM ARN is
    arn:aws:iam::{acct}:user/{name} — no Region segment — and iamStatePrefix
    (iam_state_keys.go:30-32) is account-only for that reason. A Region-qualified IAM prefix would
    either invent a Region the ARN does not carry or report nothing. IAM is exempt on the same footing
    CloudFront is, and for the stronger reason: CloudFront's exemption is a published one-Region
    tagging endpoint, IAM's is that the ARN states no Region at all.

    4. Thirteen of the fifteen Tier-2 scanners need no key change — the Region is already in the key
    and only the scan prefix omits it.
    The issue reads as though the key were the problem. It is not.
    ec2 writes "instance:" + acct + "/" + region + "/" + id (ec2_plugin.go:727) and scans
    "instance:" + acct + "/"; the same split holds for api, statemachine, activity, ecrrepo,
    userpool, stream, dbinstance, dbcluster, dbsubnetgroup, cachecluster, filesystem and
    database. Every one is a one-line prefix change through the helper ecsScanPrefix already is
    (tagging_plugin.go:592-607). DynamoDB is the only Tier-2 key that genuinely lacks a Region
    (tableStateKey, dynamodb_plugin.go:114-115).

    5. AC 5's migration decision is vacuous, and the key-shape change it contemplates is the wrong
    fix anyway.
    Vacuous because no stored state outlives a process: NewStateManager refuses every
    backend but memory (sqlite is #2), so there is nothing to migrate. Wrong fix because the scope
    question is answerable without touching a key at all — every scanner already reports an ARN, and
    an ARN is where AWS states where a resource is located.
    GetResources "[r]eturns all the tagged
    or previously tagged resources that are located in the specified AWS Region for the account", so
    scoping on the reported ARN's own account and Region segments is scoping on exactly what that
    sentence is about. That is the read-side form of the rule #826 → #932 established for the write
    side, where every resolver takes account and Region from the ARN and never from the caller.

    So the design is a central filter plus prefix narrowing, not twenty-nine prefixes:

    • One choke point in scanAllResources drops a mapping whose ARN names another account or Region.
      An empty segment means the ARN states no such scope and the resource is in scope everywhere,
      which is what makes IAM fall out correctly rather than by exception. An ARN that does not parse
      stays in scope: a scan that silently dropped a resource because substrate had built a malformed
      ARN for it would hide an ARN defect behind a missing row.
    • S3 is the one service the filter cannot reach, because arn:aws:s3:::{name} carries neither
      segment
      , so its scanner scopes on the record instead: S3Bucket.Region already exists
      (s3_types.go:14) and a bucket in another Region stops being reported. For the account there is
      nothing on the record to read, so S3Bucket gains an AccountID written at creation — a struct
      field, not a key change, and safe precisely because AC 5's migration is vacuous. An empty
      AccountID stays in scope, on the same "an unstated scope is global" rule the ARN filter uses, so
      a bucket written by a path that does not set it does not silently vanish.
    • The prefixes still narrow, everywhere the key can express it — 13 Tier-2 scanners gain the Region
      and SQS gains the account, all through one shared helper. That is an optimisation and the ECS
      precedent, not the guarantee. The guarantee is one function, tested once, which cannot rot
      per-scanner the way scanECSClusters did.
    • No key shape changes. S3, Lambda and DynamoDB keep theirs. Lambda's function:{name} and
      DynamoDB's table:{acct}/{name} cannot express the Region, and they no longer need to.

    One gap this deliberately does not close, so it is on the record rather than implied: the
    resolver still has the same account blindness for Lambda, whose resolveARN arm keys
    function:{name}, so a foreign-account function ARN handed to TagResources reaches the caller's
    own function of that name. That is a write-side defect of the #826 class, not a scan-scope one, and
    it needs the key change this issue no longer does. Filed separately rather than folded in.

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

    type: bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions