Repository navigation
fix(ec2,iam): authorize every ID an EC2 request names (#744) - #763
Merged
Merged
Conversation
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
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
An EC2 operation naming several resources of one type was authorized against the first alone.
TerminateInstanceswith threeInstanceId.Nwas decided againstInstanceId.1's ARN andInstanceId.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 isthe 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:TerminateInstanceson one instance ARN. Before this change:
Denyscoped to one instance was inert behind any instance the caller could stop;StringEqualsonaws:ResourceTag/Env=devterminated the production instance in thesame 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
ec2AuthzIDParamsorder, then request index, matching the two existingmulti-resource arms. So the denial names the same resource on every replay, which is what a
consumer's test asserts on.
owed is the handler's
InvalidInstanceID.Malformed, not anAccessDeniednaming a resourcethat does not exist, and for
TerminateInstancesthat cannot launder a state change past apolicy — 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/StartInstancesare not atomic, so there the batch isauthorized 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 ownresource, because its ARN is built from the ID rather than looked up.
GroupIdis overloaded, soDescribePlacementGroupsis pulled in and is now decidedagainst 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 ansg-onesecurity-group/<id>inthe same request. Pinned by a test row.
answers every resolvable EC2 request,
buildResourceARN's ec2 case andresourceTagsFor's ec2case could only ever return
"*"/nil— and leaving them would be two readings of one requestwith the multi path's inline tags silently winning. The deliberate absence is explained where
the arm used to be.
DescribeInstanceskeeps a pre-existing divergence, deliberately. AWS says it supports noresource-level permissions, so a real request's resource is
*. iam: the keys the bundled policies condition on have no producer #730 already resolved the firstID 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.mdpublished the unresolved-policy-variable rule backwards. AWS's Variablesand tags page applies one sentence to both elements — "used as part of the
ResourceorNotResourceelement … will not match any resource" — and states that inverted operators "domatch 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
StringNotEqualsagainst an un-substituted literal is inert on aDenyand grants on anAllow— reachable today throughSimulateCustomPolicy's ownContextEntries. That is #745;this correction is not hostage to it landing.
Verification
gofmt/go build/go vet/golangci-lintclean (0 issues);make test(race) green; coverageemulator 83.4%, total 82.8%;
make docs-reference-check docs-versionsclean; vitepress build withno broken in-page anchor;
test/e2egreen. Fail-before proven at the unit tier by returning afterthe first append (13 subtests fail) and live as described above, against a binary built from
mainin a throwaway worktree.Closes #744