Repository navigation
Description
What
An EC2 operation that names several resources of one type is authorized against the first ID only. TerminateInstances with InstanceId.1, .2 and .3 is decided against InstanceId.1's ARN and InstanceId.1's tags; the other two are not authorized at all.
ec2AuthzNamedResource (emulator/ec2_authz.go) reads the parameter through extractIndexedParams and takes ids[0]. Its doc comment records the gap.
Why it matters
This is the same shape as #674, which was fixed for tagging calls: ec2AuthzTagResources resolves every ResourceId.N into its own authzResource, and CheckAccess loops over all of them, so a CreateTags naming three resources is denied unless the caller's policies admit all three. #660/#662 established that reading — "every resource that is required for the action" — and #730 extended single-resource ID resolution past InstanceId to GroupId, RouteTableId and InternetGatewayId, but kept the first-ID-only rule.
So a policy that allows terminating instances tagged Env=dev and denies the rest currently permits a TerminateInstances naming one dev instance and two production ones, provided the dev instance is first. Real AWS authorizes each instance separately.
Shape of the fix
buildResourceARNs (emulator/authz.go) already exists for exactly this: it is the multi-resource entry point, and ec2AuthzTagResources is the precedent for an ec2 arm that returns a slice. Extend the ec2 arm to return one authzResource per ID for the plural parameters — InstanceId.N, GroupId.N, RouteTableId.N, InternetGatewayId.N — each carrying its own ARN and its own tags via ec2AuthzTagsFor, instead of resolving through ec2AuthzNamedResource's first-ID path.
Two things need deciding rather than assuming:
- An unresolvable ID in the middle of a batch.
ec2AuthzTagResourcesskips it (continue), leaving the authorizer to decide on the resources it could resolve and the handler to answerNotFound. Whether the same is right here needs stating: skipping means a batch of one real and one bogus ID is authorized as a batch of one. - Ordering. The loop is replay-visible through the denial message, which names a resource. Fixed parameter order plus request index order keeps it stable.
Acceptance criteria
- An EC2 operation naming several IDs of one type is denied unless the caller's policies admit every one of them.
- The denial message names a resource the caller can act on, and the choice is deterministic across replays.
- The unresolvable-ID-in-a-batch rule is decided, recorded in
docs/services.md, and pinned by a test. -
ec2AuthzNamedResource's doc comment stops citing this issue as open.
Activity
fix(ec2): the operation decides whether a request has a resource (#799)