Repository navigation
Description
What
RunInstances naming no SubnetId and no SecurityGroupId.N has its default VPC subnet and
default security group chosen after the authorization decision has already been made.
The server authorizes at emulator/server.go:695:
// Step 2: cross-service IAM authorization.
if s.opts.Auth != nil {
if authErr := s.opts.Auth.CheckAccess(reqCtx, req); authErr != nil {The default VPC is resolved inside the handler, well after that returns — the call site is in
runInstancesWithTags at emulator/ec2_plugin.go:502-521 (ensureDefaultVPC itself is at
:2785):
// Auto-create default VPC/subnet if none specified.
if subnetID == "" {
vpc, subnet, err := p.ensureDefaultVPC(context.Background(), reqCtx)So the subnet and security group the launch actually uses are not in req.Params when
CheckAccess runs, and no amount of resource-resolution inside the authorizer can see them.
Why it matters
A policy scoped to one subnet cannot fence off a default-VPC launch. The consumer writes
Deny ec2:RunInstances on every subnet but subnet-approved, omits SubnetId from the
request, and launches anyway — the deny has nothing to match against because the subnet does
not exist yet at decision time.
#662 narrows the gap: a launch that names a subnet, AMI or security group is now checked
against it. It does not close this one, because the defaulting path names nothing. The two are
complementary, and this half is the one that survives #662 unfixed.
ensureDefaultVPC also creates the VPC and subnet when absent, so an unauthorized request
can leave state behind — the same partial-write problem #671 notes for block device mappings,
reached from a different direction.
The internal fleet path has the same shape
emulator/ec2_fleet.go:505-510 calls runInstancesWithTags directly with a synthesized
AWSRequest, never going through the server's CheckAccess at all. A CreateFleet or
RequestSpotFleet is authorized as itself, and the launches it performs are authorized as
nothing. Whatever this issue decides about ordering has to say what the fleet path does, or
it will remain a hole beside a fixed door.
Acceptance criteria
- A
RunInstancesnaming no subnet is authorized against the subnet it will actually use,
so a policy scoped to a different subnet denies it. - The same for the default security group.
- The approach is chosen deliberately between resolving the default VPC before
authorization and authorizing a second time after resolution, with the reasoning
recorded — the second is simpler but decides on state a denied request created. - A denied default-VPC launch leaves no VPC, subnet or security group behind.
- The internal fleet path (
emulator/ec2_fleet.go:505-510) either reaches the same
decision or its exemption is documented with the reason. - A test fails before the change: a policy allowing only
subnet-approvedmust not permit
aRunInstancesthat omitsSubnetId. -
docs/services.mdrecords when a default-VPC resource participates in the decision. -
CHANGELOG.mdunder## [Unreleased], with a compatibility note: a request a
subnet-scoped policy previously allowed may now be denied.
Activity
fix(ec2,iam): resolve the default VPC before the decision, and author…