Skip to content

fix(ec2): the operation decides whether a request has a resource - #799

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/ec2-authz-operation-gate
Sep 11, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/ec2-authz-operation-gate

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Whether an EC2 request has a resource is a property of the operation, not of the
parameters the request carries.

ec2AuthzNamedResources resolved InstanceId, GroupId, RouteTableId and
InternetGatewayId into per-resource ARNs for any operation carrying one — it never looked at
req.Operation. AWS documents ec2:DescribeInstances as supporting no resource-level
permissions, so a policy scoping it to an instance ARN grants nothing there and granted exactly
those instances here.

That is the direction that matters: it grants. A consumer's test scoping a describe to one
instance passed against substrate while the deployment behind it failed on AWS — the precise
failure substrate exists to prevent. docs/services.md recorded the divergence as deliberately
left, on the reading that gating the resolver was a question about the resolution rather than
about the batch #744 was fixing. This closes it.

The gate

An ID is resolved only when AWS documents the operation as supporting that resource type, read
from the table #797 vendored — not a hand-written operation list, so it cannot fall behind
an operation substrate adds later. The early return also skips the state reads
ec2TaggableResource performs for a pg- or key- ID.

An operation absent from the table is also decided against *: the same answer AWS gives an
action with no published resource types, and the safe direction of the two, since a resource
narrower than the one AWS would use is a grant substrate would be inventing.
make authz-reference-check is what stops a stale snapshot from widening a decision quietly.

The three EC2 resolvers already gated on their operation are untouched — CreateTags/DeleteTags
(#674) and RunInstances (#662) — and AWS scopes all three to resource types, so the gate
confirms them rather than narrowing them.

Two consequences, pinned rather than left to be rediscovered

  • DescribePlacementGroups is now decided against *. It reads pg- IDs through the
    overloaded GroupId, which was the specific over-reach docs/services.md admitted. The
    name-form placement-group ARN translation is still exercised by CreateTags, which AWS does
    scope to placement-group.
  • An ec2:ResourceTag/<key> condition on a describe can no longer match, because with the
    request resource * there is no resource whose tags to read. That is AWS's behavior too — AWS
    cannot evaluate a resource tag for an action with no resource — and it is why the bundled
    policies put those conditions on the mutating operations. Its own test says so, so it reads as
    a decision rather than a regression.

Three existing tests changed rather than deleted

Each failed before the change, which is the fail-before evidence:

  • TestEC2_Authz_SingleResourceOperationsAreUnchanged — DescribeInstances' row now asserts
    *.
  • TestEC2_Authz_BatchDenialIsReplayStable — drives TerminateInstances; on a describe the
    ordering assertion would be vacuous.
  • TestEC2_Authz_AllFourIDParametersExpand — the placement-group row moved into the new gate
    test, where it asserts the opposite answer.

Verification

gofmt -l . && go build ./... && go vet ./... && golangci-lint run ./...   # clean
make test                                    # go1.27.1, pass
GOTOOLCHAIN=go1.26.6 make test               # pass
GOTOOLCHAIN=go1.26.6 make coverage           # emulator 83.5%, total 82.9% — baseline held
make docs-reference-check docs-versions authz-reference-check   # pass
npm --prefix docs run build                  # pass
go vet -C test/e2e ./... && go test -C test/e2e ./...           # pass

Closes #762.

Whether an EC2 request has a resource is a property of the operation, not of the
parameters the request carries. AWS documents ec2:DescribeInstances as supporting no
resource-level permissions, so a policy scoping it to an instance ARN grants nothing
there — and granted precisely those instances here, because ec2AuthzNamedResources
resolved InstanceId, GroupId, RouteTableId and InternetGatewayId for any operation
carrying one and never looked at req.Operation.

That is the direction that matters: it grants. A consumer's test scoping a describe to
one instance passed against substrate and the deployment behind it failed on AWS, which
is the precise failure substrate exists to prevent. docs/services.md recorded the
divergence as deliberately left, on the reading that gating the resolver was a question
about the resolution rather than about the batch #744 was fixing; this closes it.

An ID is now resolved only when AWS documents the operation as supporting that resource
type, read from the vendored Service Reference Information table rather than from a
hand-written operation list, so it cannot fall behind an operation substrate adds later.
An operation absent from that table is also decided against "*" — the same answer AWS
gives an action with no published resource types, and the safe direction of the two,
since a resource narrower than the one AWS would use is a grant substrate would be
inventing. The early return also skips the state reads ec2TaggableResource performs for
a pg- or key- ID.

The three EC2 resolvers already gated on their operation are untouched: CreateTags and
DeleteTags (#674) and RunInstances (#662). AWS scopes all three to resource types, so
the gate confirms them rather than narrowing them.

Two consequences, both pinned by tests rather than left to be rediscovered.
DescribePlacementGroups, which reads pg- IDs through the overloaded GroupId, is now
decided against "*"; the name-form placement-group ARN translation is still exercised by
CreateTags, which AWS does scope to placement-group. And an ec2:ResourceTag/<key>
condition on a describe can no longer match, because with the request resource "*" there
is no resource whose tags to read — AWS's behavior too, and why the bundled policies put
those conditions on the mutating operations.

Three existing tests changed rather than being deleted: DescribeInstances' row in
TestEC2_Authz_SingleResourceOperationsAreUnchanged now asserts "*",
TestEC2_Authz_BatchDenialIsReplayStable drives TerminateInstances so its ordering
assertion is not vacuous, and the placement-group row moved out of the four-parameter
expansion table into the new gate test.

Closes #762.
@scttfrdmn scttfrdmn added this to the v0.111.0 milestone Sep 11, 2026
@codecov

codecov Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

Codecov Report

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

Files with missing lines Patch % Lines
emulator/ec2_authz.go 75.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit eace648 into main Sep 11, 2026
16 of 17 checks passed
@scttfrdmn
scttfrdmn deleted the fix/ec2-authz-operation-gate branch September 11, 2026 03:48
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.

EC2 authz: the ID resolver runs for operations AWS says have no resource-level permissions

1 participant