Skip to content

fix(ec2,iam): authorize every ID an EC2 request names (#744) - #763

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/ec2-authz-multi-id-744
Aug 23, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/ec2-authz-multi-id-744

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

What

An EC2 operation naming several resources of one type was authorized against the first alone.
TerminateInstances with three InstanceId.N was decided against InstanceId.1's ARN and
InstanceId.1's tags; the other two were not authorized at all.

Every ID under the four resolving parameters — InstanceId.N, GroupId.N, RouteTableId.N,
InternetGatewayId.N — now carries its own ARN and its own tags into its own decision. That is
the reading #660 and #662 established and #674 already applied to a tagging call's
ResourceId.N; this makes EC2's ID path agree with it.

Why it matters

Proved live against a built binary, an IAM user, and a policy allowing ec2:TerminateInstances
on one instance ARN. Before this change:

  • a batch naming an allowed instance and a disallowed one terminated both;
  • a Deny scoped to one instance was inert behind any instance the caller could stop;
  • a StringEquals on aws:ResourceTag/Env = dev terminated the production instance in the
    same call.

Each was refused after, naming the offending instance, and each denial was position-independent —
the pre-change binary happened to refuse only when the disallowed instance came first.

Decisions recorded rather than left to be rediscovered

  • Ordering. Fixed ec2AuthzIDParams order, then request index, matching the two existing
    multi-resource arms. So the denial names the same resource on every replay, which is what a
    consumer's test asserts on.
  • An unresolvable ID mid-batch is skipped, as a tagging call's already was. The refusal it is
    owed is the handler's InvalidInstanceID.Malformed, not an AccessDenied naming a resource
    that does not exist, and for TerminateInstances that cannot launder a state change past a
    policy — AWS documents it all-or-nothing ("If you specify multiple instances and the request
    fails … none of the instances are terminated") and substrate resolves every ID before
    terminating any. StopInstances/StartInstances are not atomic, so there the batch is
    authorized as the resources that exist. No 403-before-404 ordering is asserted: no AWS page
    publishes one. Note the narrowness — a well-formed i- ID naming no instance is still its own
    resource, because its ARN is built from the ID rather than looked up.
  • GroupId is overloaded, so DescribePlacementGroups is pulled in and is now decided
    against the groups it names. Nothing mis-resolves: the resolver keys on the prefix, so a pg-
    ID becomes a name-form placement-group/<name> ARN and an sg- one security-group/<id> in
    the same request. Pinned by a test row.
  • The two single-resource ec2 arms are deleted, not left beside the new one. Once the multi arm
    answers every resolvable EC2 request, buildResourceARN's ec2 case and resourceTagsFor's ec2
    case could only ever return "*"/nil — and leaving them would be two readings of one request
    with the multi path's inline tags silently winning. The deliberate absence is explained where
    the arm used to be.
  • DescribeInstances keeps a pre-existing divergence, deliberately. AWS says it supports no
    resource-level permissions, so a real request's resource is *. iam: the keys the bundled policies condition on have no producer #730 already resolved the first
    ID for describes and this multiplies it to N; gating the resolver is a decision about iam: the keys the bundled policies condition on have no producer #730, and
    is filed as EC2 authz: the ID resolver runs for operations AWS says have no resource-level permissions #762.

Also in this PR

docs/services.md published the unresolved-policy-variable rule backwards. AWS's Variables
and tags
page applies one sentence to both elements — "used as part of the Resource or
NotResource element … will not match any resource" — and states that inverted operators "do
match against a null value", which is what substrate's literal comparison already answers. So
there is no unresolved-variable divergence in either direction. What does diverge is a variable
that would have resolved, and the dangerous polarity is the negated one, where a
StringNotEquals against an un-substituted literal is inert on a Deny and grants on an
Allow — reachable today through SimulateCustomPolicy's own ContextEntries. That is #745;
this correction is not hostage to it landing.

Verification

gofmt/go build/go vet/golangci-lint clean (0 issues); make test (race) green; coverage
emulator 83.4%, total 82.8%; make docs-reference-check docs-versions clean; vitepress build with
no broken in-page anchor; test/e2e green. Fail-before proven at the unit tier by returning after
the first append (13 subtests fail) and live as described above, against a binary built from
main in a throwaway worktree.

Closes #744

TerminateInstances naming three instances was decided against InstanceId.1's
ARN and InstanceId.1's tags, so a policy allowing instances tagged Env=dev
and denying the rest permitted a call naming one dev instance and two
production ones — provided the dev one came first — and a Deny scoped to a
production instance was inert behind any instance the caller could touch.

Every ID under the four resolving parameters now carries its own ARN and its
own tags into its own decision, which is the reading #660/#662 established
and #674 already applied to a tagging call's ResourceId.N. The permission
boundary sees the whole batch too. The denial names the first resource the
policy does not allow, in fixed parameter order then request index, so it is
replay-stable and it names a resource the caller can act on.

An ID that resolves to no ARN is skipped, as a tagging call's already was:
the refusal it is owed is the handler's Malformed/NotFound, not an
AccessDenied naming a resource that does not exist. No ordering between the
403 and the 404 is asserted, because no AWS page publishes one.

The ec2 arms of buildResourceARN and resourceTagsFor were unreachable once
the multi arm answers every resolvable request, and were the trap the plan
flagged — two readings of one request, with the multi path's inline tags
silently winning. Both are deleted and the absence is explained in place.

Also corrects docs/services.md, which published the unresolved-policy-variable
rule backwards: AWS applies one sentence to Resource and NotResource alike,
and states that inverted operators do match a null value, so there is no
unresolved-variable divergence in either direction. What diverges is a
variable that would have resolved (#745).

#762 tracks whether the resolver should be gated to the operations AWS says
support resource-level permissions.

Closes #744
@scttfrdmn scttfrdmn added this to the v0.109.0 milestone Aug 23, 2026
@codecov

codecov Bot commented Aug 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.23529% with 2 lines in your changes missing coverage. Please review.

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

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit f2805e3 into main Aug 23, 2026
16 checks passed
@scttfrdmn
scttfrdmn deleted the fix/ec2-authz-multi-id-744 branch August 23, 2026 05:32
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: an operation naming several IDs is decided against the first alone

1 participant