Skip to content

fix(ec2): default-VPC region coherence + CreateDefault idempotency + delete protection#1761

Merged
vieiralucas merged 1 commit into
mainfrom
worktree-ec2-netiso-fix2-defaultvpc-region
Jun 18, 2026
Merged

fix(ec2): default-VPC region coherence + CreateDefault idempotency + delete protection#1761
vieiralucas merged 1 commit into
mainfrom
worktree-ec2-netiso-fix2-defaultvpc-region

Conversation

@vieiralucas

@vieiralucas vieiralucas commented Jun 18, 2026

Copy link
Copy Markdown
Member

Summary

Bug-hunt 2026-06-18 findings 1.1, 1.2, 1.3, + delete-protection.

  • 1.1 (HIGH) — default-resource ids were seeded on (account, region, role), but read handlers build a throwaway Ec2State::new(account, req.region) for accounts that don't exist yet, where req.region is the caller's SigV4 scope, not the server's region. When they differed (server us-east-1, client eu-west-1), a no-subnet RunInstances stamped the instance with subnet/VPC ids absent from its own persisted account. Fix: deterministic_id is now region-independent (fakecloud pins one region per server), so read-path and persisted ids always agree.
  • 1.3 (MED)CreateDefaultVpc now returns the seeded default VPC instead of minting a second isDefault=true VPC.
  • 1.2 (HIGH)CreateDefaultSubnet now attaches to the account's real default VPC (was the literal vpc-default, which matched no VPC and orphaned the subnet) and returns the existing per-AZ default subnet when one exists.
  • delete-protectionDeleteSecurityGroup on the default group → CannotDelete; DeleteNetworkAcl on a default NACL → CannotDeleteDefaultNetworkAcl (matches AWS). Prevents a VPC ending up with no default SG.

Test plan

  • cargo test -p fakecloud-ec2 — unit tests for region-independent ids (incl. read-vs-persist agreement across regions).
  • cargo test -p fakecloud-e2e --test ec2_instance_control_plane — idempotent CreateDefaultVpc, CreateDefaultSubnet attaches to the real default VPC, default SG/NACL delete rejection (20/20).
  • cargo test -p fakecloud-conformance --test ec2769/769.
  • clippy + fmt clean.

Summary by cubic

Fixes EC2 default network behavior: default resource IDs are now region-independent, CreateDefaultVpc/Subnet are idempotent and attach correctly, and default SG/NACL delete protection matches AWS. This prevents mismatched IDs on cross-region reads and avoids orphaned subnets or missing default groups.

  • Bug Fixes
    • Made deterministic_id region-independent so read paths and persisted state agree; no-subnet RunInstances now lands in the real default VPC/subnet.
    • CreateDefaultVpc returns the existing seeded default VPC (recreates if missing) instead of creating a second default VPC.
    • CreateDefaultSubnet attaches to the account’s actual default VPC and returns the existing per-AZ default subnet when present.
    • Block deletion of the default security group (CannotDelete) and default NACL (CannotDeleteDefaultNetworkAcl) to prevent invalid states.

Written for commit cf23a74. Summary will update on new commits.

Review in cubic

…delete protection

Bug-hunt 2026-06-18 findings 1.1, 1.2, 1.3 + delete-protection.

- 1.1: default-resource ids were seeded on (account, region, role), but read
  handlers build a throwaway Ec2State::new(account, req.region) for accounts
  that don't exist yet -- where req.region is the caller's SigV4 scope, not the
  server's region. When they differed, a no-subnet RunInstances stamped the
  instance with subnet/VPC ids that didn't exist in its own persisted account.
  Drop region from the id seed (deterministic_id is now region-independent);
  fakecloud pins one region per server anyway, so read and persist now always
  agree. AZ/CIDR cosmetics still use the region.
- 1.3: CreateDefaultVpc now returns the seeded default VPC instead of minting a
  second isDefault=true VPC (impossible on AWS).
- 1.2: CreateDefaultSubnet now attaches to the account's real default VPC (was
  the literal "vpc-default", which matched no VPC and orphaned the subnet) and
  returns the existing per-AZ default subnet when one exists.
- delete-protection: DeleteSecurityGroup on the `default` group -> CannotDelete;
  DeleteNetworkAcl on a default NACL -> CannotDeleteDefaultNetworkAcl, matching
  AWS. Prevents a VPC ending up with no default SG (which made a later
  no-SecurityGroupId RunInstances launch with an empty group list).

Tests: unit tests for region-independent ids; e2e for idempotent
CreateDefaultVpc, CreateDefaultSubnet attaching to the real default VPC, and
default SG/NACL delete rejection. Full EC2 conformance 769/769.
@codecov

codecov Bot commented Jun 18, 2026

Copy link
Copy Markdown

@vieiralucas vieiralucas merged commit ee41f3d into main Jun 18, 2026
53 of 54 checks passed
@vieiralucas vieiralucas deleted the worktree-ec2-netiso-fix2-defaultvpc-region branch June 18, 2026 14:55
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.

1 participant