Skip to content

feat(tagging): GetResources reports an ECS service, task and task definition (#935), and a ResourceTypeFilters type is the ARN's own segment (#936) - #940

Merged
scttfrdmn merged 3 commits into
mainfrom
fix/935-ecs-scanners
Sep 16, 2026
Merged

scttfrdmn merged 3 commits into
mainfrom
fix/935-ecs-scanners

Conversation

@scttfrdmn

@scttfrdmn scttfrdmn commented Sep 16, 2026 •

Copy link
Copy Markdown
Owner

Closes #935.
Closes #936.
Closes #909.

#936 is a duplicate of #909, which I filed first — while implementing #835's RDS rows — and
missed when filing #936. Both are closed here by the one fix, and both carry a comment saying which
is which. #909's analysis is the better one; #936 added the second failure direction and the
citation. #909's two extra acceptance criteria are satisfied in the second commit.

The ECS row (#935) — the last of #835

scanECSClusters was the ECS namespace's only descriptor, so GetResources reported a cluster and
nothing else. A tag written to a service, a task or a task definition through TagResources — which
has worked since v0.115.0, and reads back through ECS's own ListTagsForResource — was invisible to
the tagging API's own inventory call. A caller asking "which of my resources carry this tag?" was
answered "none" about a resource the same API had just tagged.

Three new descriptors (scanECSServices, scanECSTasks, scanECSTaskDefinitions) bring the ECS
namespace to four and the scanned set to twenty-eight resource types. With this, all eleven rows of
#835 meet its five acceptance criteria
, so #835 closes with it.

A task is in scope alongside the two types #835's table names: ecsTagStateKey already resolved a
task ARN, so a tag could be written to one and read back nowhere, and AWS lists tasks first among the
taggable ECS resources — "There are multiple ways that Amazon ECS tasks, services, task
definitions, and clusters are tagged"
. Leaving it out would have left the row's own defect behind in
a third of the namespace.

Two decisions the task-definition scanner records rather than assumes:

  • Every revision is reported, not the family's newest. RegisterTaskDefinition accepts tags per
    revision and ecsTagStateKey splits a {family}:{revision} ARN to reach exactly one of them, so
    reporting only the newest would hide a tag the tagging API itself wrote to an older one.
  • A deregistered (INACTIVE) revision is reported too. AWS's tagging page says nothing about
    deregistration, and such a revision still answers DescribeTaskDefinition, so it is still an
    observable resource.

Region scope came with the row, not after it

scanECSClusters prefixed its scan by account alone, so a us-east-1 caller was reported a
us-west-2 cluster. Had that been left, ECS would have answered one caller cross-Region about
clusters and same-Region about the three new types — a worse state than either answer. GetResources
settles which is right in its opening sentence: it "[r]eturns all the tagged or previously tagged
resources that are located in the specified AWS Region for the account"
. All four scanners now go
through one ecsScanPrefix helper so they cannot disagree about scope.

The same Region blindness remains in fourteen other scanners, with a cross-account variant in three.
That is #937, filed rather than fixed piecemeal here, and ecsScanPrefix's doc comment says so.

The colon-terminated guard, four times over

The four key prefixes are now named constants shared with the key builders in ecs_plugin.go, and all
four are colon-terminated: cluster:, taskdef:, service:, task:. Each sits beside an index
key in the same namespace — cluster_names:, taskdef_families:, taskdef_revisions:,
service_names:, task_ids: — whose value is a JSON array of names. A prefix without the colon lists
those too and then drops them silently when the unmarshal into a resource type fails, which is the
failure mode that hides a defect by making the count right for the wrong reason. ECS is the sixth
namespace to need the guard and the first to need it four times. (task: does not collide with
taskdef:; they differ at position 5.)

ecsTagsToTaggingTags also sorts by key now, in the one converter rather than at each of the four
call sites, so no ECS scanner can report the order tags happened to be written in (#862).

The filter fix (#936) — and why it had to ship with the row

matchesResourceType compared a filter's type half with strings.HasPrefix against the ARN's whole
resource portion. AWS pins what the type means from two directions — "[s]pecifying a resource type of
ec2:instance returns only EC2 instances"
and "[t]he string for each service name and resource
type is the same as that embedded in a resource's Amazon Resource Name (ARN)"
— and the prefix
comparison broke the first in both directions:

  • Too wide: ecs:task selected a task definition, whose resource portion is
    task-definition/{family}:{revision} and therefore begins with the string task. A caller could
    not express "tasks only" at all — which is why the selectivity assertions for the row above could
    not have been written honestly against it.
  • Too narrow: apigateway:restapis selected nothing. AWS publishes the ARN as
    arn:{partition}:apigateway:{region}::/restapis/{api-id}, so the resource portion begins with a
    slash that a prefix comparison against restapis cannot see past. This one was already known and
    worked around in a comment in TestTagging_GetResources_APIGateway rather than filed; that comment
    is now an assertion.

The type is taken as the segment the ARN itself delimits, with one leading slash stripped first:

ARN resource portion Type
instance/i-abc123 instance
stateMachine:hello stateMachine
task-definition/sidecar:3 task-definition
/restapis/abc123 restapis
my-bucket my-bucket (S3 embeds no type)

This is the anchored-segment rule of #910 and #918 applied one layer up. Those fixed
strings.Contains(arn, ":stateMachine:") and strings.LastIndex(arn, "distribution/") in the ARN
resolvers, on the ground that a resource type must be matched against the ARN's own delimited
segment. The filter matcher is the one comparison of that kind whose left-hand side comes from the
caller, and it was in neither pass.

One narrowing a consumer may notice, recorded under ### Changed: an S3 bucket ARN is
arn:aws:s3:::{name} and embeds no type string, so a bucket named bucket-logs used to match
s3:bucket by accident of its first six characters (and assets never did). The service-only filter
s3 is what reaches a bucket, as it always was.

Corrections carried here

Tests

Two new files, both entirely wire-driven through emulator.StartTestServer — nothing writes state
directly, per #765.

emulator/tagging_ecs_test.go: all four types reported and carrying their tag; a tag readable through
both APIs in both directions for each of the three new types; a ResourceTypeFilters entry
selecting only its own type (five subtests); neither Region reporting the other's identically-named
resources; the exact-set assertion that no index key is reported as a resource; both revisions of one
family reported with their own tags; and reported tags in key order.

emulator/tagging_type_filter_test.go: one case per ARN shape in the scanned set, each with a filter
that must select and a strict-prefix filter that must not; the service check ahead of the type check;
the OR across the filter list; and the arity guard on a malformed ARN. It goes through a new
ResourceTypeMatchesForTest export, because two of the six shapes — an S3 bucket named bucket…, a
malformed ARN — cannot be created through the wire at all.

Load-bearing against origin/main: with only a minimal export stub injected, the two files fail
with 21 FAIL lines across all 8 new top-level tests. Three type-filter tests and the
ecs:cluster subtest pass on main; those are deliberate regression guards on already-correct
behaviour.

#909's two extra criteria

TestTaggingTypeFilter_EveryReachableTypeIsSelectedByItsOwnName asserts the rule once per reachable
resource type
rather than once per ARN shape: thirty-three rows, being the twenty-nine the
twenty-eight GetResources scanners produce (scanIAMEntities yields both a user and a role) plus the
four that only TagResources/UntagResources reach — an EFS access point and Glue's job, crawler and
connection. The row count is locked with require.Len, so a thirty-fourth type fails the test rather
than going unexercised.

TestTaggingTypeFilter_ARDSClusterFilterDoesNotSelectAClusterParameterGroup pins #909's prospective
case. AWS's RDS ARN table gives cluster-pg, cluster-snapshot and cluster-endpoint as resource
types in their own right, all three beginning with the string cluster. None is storable today — the
RDS resolver refuses all three segments — so the assertion is on the matcher, where it fails the moment
one becomes storable.

Verification

The nine-command gate, all green, from the repo root:

gofmt -l . && go build ./... && go vet ./...      # clean
golangci-lint run ./...                            # 0 issues
make test                                          # ok
GOTOOLCHAIN=go1.26.6 make test                     # ok
GOTOOLCHAIN=go1.26.6 make coverage                 # 84.2% emulator / 83.7% total — baseline held
make docs-reference docs-reference-check docs-versions authz-reference-check
npm --prefix docs run build
go vet -C test/e2e ./... && go test -C test/e2e ./...

#835's fourth criterion

The one criterion #835 was still short of when the scanner landed: "any type for which a tag
genuinely cannot be written is listed in docs/services.md with the reason."
ECS's refusals existed
only as why strings in tagging_arn_guards_test.go, which is not where a consumer looks. They are
now a table in the tagging section — a capacity provider (AWS lists it among the taggable ECS
resources, substrate stores no such record, so there is nothing to read a tag back from), AWS's
documented short service ARN (it names no cluster, so it identifies no record; the long
service/{cluster}/{name} form is what carries a tag), and a task-definition ARN whose revision is
not an integer — with a container instance taking the capacity provider's reason, and with absence
(ResourceNotFoundException) distinguished from shape.

…inition (#935)

The ECS namespace had one scanner descriptor, scanECSClusters, so a tag written
to a service, a task or a task definition through TagResources -- which has
worked since v0.115.0, and reads back through ECS's own ListTagsForResource --
was invisible to GetResources. That is the asymmetry every row of #835 closes,
and this is the eleventh and last of them.

A task ships with the two rows #835's table names: ecsTagStateKey already
resolved a task ARN, and AWS lists tasks first among the taggable ECS resources.
Every task-definition revision is reported, including a deregistered one, because
each carries its own ARN and its own tags.

Two things come with the row. scanECSClusters prefixed by account alone, so a
us-east-1 caller was reported a us-west-2 cluster; all four scanners now share
one ecsScanPrefix helper, per GetResources' own "located in the specified AWS
Region for the account". The remaining Region-blind scanners are #937.

And a ResourceTypeFilters type is now matched against the ARN's own delimited
segment rather than as a prefix of the whole resource portion (#936). The old
comparison was wrong in both directions: "ecs:task" selected a task definition,
whose portion begins with "task", and "apigateway:restapis" selected nothing,
because API Gateway's portion begins with a slash. One narrowing follows -- an S3
bucket named "bucket-logs" is no longer selected by "s3:bucket", since an S3 ARN
embeds no type string for that filter to be "the same as".

The four ECS key prefixes are named constants and colon-terminated, the sixth
namespace to need that guard: each sits beside an index key whose value is a JSON
array of names. ecsTagsToTaggingTags sorts by key in the one converter rather
than at the four call sites, per #862.

Closes #935.
Closes #936.
@codecov

codecov Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.32394% with 9 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/tagging_plugin.go 86.56% 9 Missing ⚠️

📢 Thoughts on this report? Let us know!

…RDS case (#909)

#909 is the earlier filing of #936 -- the same unanchored prefix comparison,
found while implementing #835's RDS rows. Its acceptance criteria ask for two
things #936's did not, and both are cheap enough to be worth having rather than
leaving a duplicate half-satisfied.

One row per reachable resource type: thirty-three, being the twenty-nine the
twenty-eight GetResources scanners produce plus the four that only the named-ARN
operations reach. The count is locked with require.Len, so a thirty-fourth type
fails the test rather than going unexercised. The existing per-shape table proves
the rule; this proves the rule covers the tree.

And #909's prospective RDS case: cluster-pg, cluster-snapshot and
cluster-endpoint are AWS resource types in their own right, all beginning with
the string "cluster", so rds:cluster would have selected them. None is storable
today, so the assertion is on the matcher, where it fails the moment one becomes
storable.

Closes #909.
#835's fourth criterion asks that any type for which a tag genuinely cannot be
written be listed in docs/services.md with the reason. ECS's three refused ARN
shapes existed only as why strings in a guard test: a capacity provider (AWS
lists it as taggable, substrate stores no such record), the documented short
service ARN, and a task-definition ARN with a non-numeric revision. A container
instance takes the capacity provider's reason.

Part of #835.
@scttfrdmn
scttfrdmn merged commit a97164e into main Sep 16, 2026
16 of 17 checks passed
@scttfrdmn
scttfrdmn deleted the fix/935-ecs-scanners branch September 16, 2026 03: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

1 participant