Files
floci/docs/services
Allen Sanborn 14f99a5123 feat(ec2): support VPC peering connections (#2654)
* feat(ec2): support VPC peering connections

CreateVpcPeeringConnection was entirely unimplemented, returning
UnsupportedOperation and blocking all three VPC-peering examples in
terraform-aws-vpc (vpc-peering, vpc-peering-cross-accounts,
vpc-peering-external).

Adds CreateVpcPeeringConnection, AcceptVpcPeeringConnection,
DescribeVpcPeeringConnections, ModifyVpcPeeringConnectionOptions and
DeleteVpcPeeringConnection, matching the resources those examples
actually use (aws_vpc_peering_connection,
aws_vpc_peering_connection_accepter, aws_vpc_peering_connection_options).
Connections start pending-acceptance and only move to active via an
explicit accept, same as real AWS; Terraform's auto_accept convenience
is provider-side, not API-side, so no same-account special-casing is
needed here.

CreateRoute now also accepts VpcPeeringConnectionId as a target and
reports it back on DescribeRouteTables - every one of the three
examples routes traffic through the peering connection via aws_route,
and without this the provider would see permanent drift on the route
resource it just created.

* fix(ec2): enforce cross-account peering identity and fix route target bugs

Addresses Greptile's 0/5 review of #2654:

- AcceptVpcPeeringConnection now resolves the connection across every
  account's storage partition (findAnyAccountEntry, same pattern as
  Ec2IpamService's RAM-shared IPAM lookups) and rejects a caller that is
  not the connection's accepter, instead of only ever finding a
  connection the accepting account itself created.
- DescribeVpcPeeringConnections, ModifyVpcPeeringConnectionOptions and
  DeleteVpcPeeringConnection get the same cross-account resolution, and
  Describe now filters to connections visible from the caller's account
  and region instead of leaking every account's connections in every
  region.
- CreateRoute rejects a VpcPeeringConnectionId combined with another
  target, matching the existing EgressOnlyInternetGatewayId check.
- ReplaceRoute accepts VpcPeeringConnectionId as a target, so a peering
  route created by CreateRoute can actually be repointed.

Adds a cross-account integration test covering acceptance identity,
region-scoped visibility, and the two route-target fixes.

* fix(ec2): record the actual caller as peering requester, enforce region on mutations

Two more issues from Greptile's re-review of #2654:

- CreateVpcPeeringConnection recorded requesterVpcInfo.ownerId as the
  emulator's configured default account rather than the account that
  actually made the request. A non-default requester could never
  describe, modify or delete its own connection, while the unrelated
  default account was treated as the requester and granted those
  operations. Same fix applied to the accepter-owner fallback when
  PeerOwnerId is omitted (same-account peering).
- AcceptVpcPeeringConnection, ModifyVpcPeeringConnectionOptions and
  DeleteVpcPeeringConnection now enforce the same regional-visibility
  invariant Describe already did: an endpoint in a region belonging to
  neither side of the connection reports it as absent instead of acting
  on it.

Extends the cross-account integration test to cover both: the actual
requester managing its own connection while the default account cannot,
and mutations issued from an unrelated region being rejected.

* fix(ec2): enforce per-endpoint ownership on ModifyVpcPeeringConnectionOptions

Greptile's third pass on #2654: a participant that is legitimately part of a
connection could still set the *other* side's DNS-resolution option, e.g. the
requester setting AccepterPeeringConnectionOptions. AWS scopes each option
block to that side's own VPC owner, not to participation in the connection
generally.

ModifyVpcPeeringConnectionOptions now checks the caller against the specific
side's owner for whichever option block(s) the request actually sets, and
rejects a cross-endpoint attempt with OperationNotPermitted. Adds a test
covering both directions (requester setting the accepter's option and vice
versa).

* fix(ec2): resolve the peer VPC's real owner instead of trusting PeerOwnerId

Greptile's fourth pass on #2654: CreateVpcPeeringConnection recorded the
requester-supplied PeerOwnerId as the accepter's identity without checking it
against the peer VPC's actual owner. Since AcceptVpcPeeringConnection
authorizes against that recorded value, a requester could name another
account's real VPC while claiming itself (or anyone) as PeerOwnerId and
self-authorize acceptance of a connection it doesn't actually control.

The peer VPC is now resolved across every account's partition, same as a
peering connection's own id lookup. When it's known locally, that storage
partition is authoritative and overrides any conflicting PeerOwnerId; the
claim is trusted only for a genuinely external/cross-account peer this store
never seeded, where there's nothing to validate against.

Adds a test creating the peer VPC under a real "victim" account and
confirming the forging account can't accept the connection while the real
owner can.

* fix(ec2): take the per-connection lock in DeleteVpcPeeringConnection

Greptile's fifth pass on #2654: accept and modify already synchronized on
lockFor(vpcPeeringConnectionId) before loading and saving the connection, but
delete did not take that lock at all. A delete could run between one of those
mutations' load and its unconditional save, and that save would resurrect the
row delete just removed.

Wraps delete's lookup, visibility check, and removal in the same lock.

* fix(ec2): surface peeringOptions in VPC peering connection responses

CreateVpcPeeringConnection, AcceptVpcPeeringConnection, and
DescribeVpcPeeringConnections never echoed the DNS-resolution setting
under requesterVpcInfo/accepterVpcInfo, even though it's a real field
there in AWS's own examples. ModifyVpcPeeringConnectionOptions stored
it correctly, but Terraform's aws_vpc_peering_connection_options
resource reads the value back via Describe on every plan, not by
re-issuing Modify, so a config setting DNS resolution would show
permanent drift. Flagged in review:
https://github.com/floci-io/floci/pull/2654#pullrequestreview-5054115075

* fix(ec2): reject a peer VPC named with the wrong PeerRegion

CreateVpcPeeringConnection resolved the peer VPC only within the region the
requester supplied, and treated a miss as "external peer, trust PeerOwnerId".
That left the ownership forgery closed on the previous commit reachable again:
name another account's real VPC, point PeerRegion at a region that VPC is not
in, and the requester's own claimed PeerOwnerId is recorded unchallenged --
after which AcceptVpcPeeringConnection authorizes the requester against it.

Real AWS resolves the peer VPC globally and answers InvalidVpcID.NotFound when
the named region is not the one it lives in, so a lookup miss now falls back to
trusting PeerOwnerId only when the id is absent from every region. A genuinely
external peer VPC -- one this emulator has never seen -- behaves as before.
2026-09-01 09:32:51 -04:00
..
2026-05-10 11:53:31 -05:00
2026-05-10 11:53:31 -05:00
2026-08-21 00:09:04 -04:00
2026-08-31 09:03:26 -04:00
2026-05-10 11:53:31 -05:00
2026-05-10 11:53:31 -05:00