Files
floci/docs
Allen Sanborn cf1aabce39 feat(ec2): back each VPC with a real Docker network in RFC 1918 space (#3272)
* feat(ec2): back each VPC with a real Docker network in RFC 1918 space

An instance's private IP was a plausible-looking number nothing could
connect to. Every VPC now gets its own Docker network, created lazily on
the first launch into it, with the VPC CIDR as the network's IPAM pool
and each subnet allocating static addresses from its own slice. The
address Floci reports is one the container actually holds, and instances
in different VPCs sit on different bridges.

One network per VPC, not per subnet: subnets inside a VPC route to each
other in AWS, so a network per subnet would manufacture a partition AWS
does not have and break the two-tier app/database topologies this corpus
is full of.

The declared CIDR is used verbatim wherever it can be. It cannot be when
it is absent, malformed, outside RFC 1918, or already claimed on the
Docker daemon, which includes another Floci VPC: two VPCs may legally
declare the same CIDR in AWS but one daemon cannot route two identical
ranges. Only then is an equivalent block drawn from the configured
fallback pool, and the substitution is logged at WARN. A reported private
IP that does not mean what the caller declared is either true or it is in
the log.

Leases are given back on every exit: a launch that never attaches, a
launch that fails, and terminate. Detach precedes release, because Docker
holds the address while the endpoint stands and would refuse the next
launch handed the same one. Startup reconciles this emulator's own
orphaned networks first (scoped by API port, so instances sharing a
daemon never touch each other's), then re-declares the plan from
persisted VPCs and subnets and re-reserves the addresses restored
instances still hold.

Between-VPC isolation is the Docker daemon's, not Floci's, and OrbStack
does not enforce it. On such a host the VPC boundary is an addressing
boundary only. docs/services/ec2.md says so.

Off with FLOCI_SERVICES_EC2_VPC_NETWORKS_ENABLED=false, and off whenever
ec2 mock is on.

* fix(ec2): do not adopt a leftover VPC network that routes another range

materialise() treated any network under the VPC's own name as its own: a
successful inspect set created=true and returned. A network left by a
previous run that declared a different CIDR was therefore adopted, after
which addresses were handed out of vpc.effective while the bridge routed
something else entirely.

Compare the leftover's IPAM subnet to vpc.effective. A match is adopted as
before. A mismatch is removed and recreated on the planned range rather
than re-planned onto the leftover's subnet: by the time materialise runs,
addresses have already been allocated from vpc.effective, and after a
restart some are leases held by live containers, so the plan cannot move
under them. The network name carries this emulator's own port and region,
so recreating it cannot destroy a user's network. If the removal fails the
instance stays on the shared bridge, which is a documented degradation,
instead of holding an address nothing routes.

Also make small blocks work or refuse out loud. FIRST_HOST_OFFSET was a
flat 10, so a /29 (eight addresses) and a /30 (four) allocated nothing at
all and said nothing about it, and fallback-prefix-length had no upper
bound to stop a /30 being configured. The offset now scales down to 2 for
blocks that cannot spare ten addresses, a block with no room for a host is
refused at plan time with a WARN, and the fallback prefix is clamped into
the range that can serve hosts.

* fix(ec2): keep the IMDS source address current across start and restore

Ec2MetadataServer resolves an instance from the source address of the
request, and a container's default route is the bridge, so a VPC-attached
instance's metadata requests arrive from its bridge address rather than
from the VPC address Floci reports. launch() registered both. start() and
restoreMetadataRegistration() registered only the address
getContainerBridgeIp returns, which for a VPC-attached container is the
VPC address: neither refreshed imdsSourceIp nor registered the bridge.

Docker hands out a fresh bridge address when a stopped container starts
again, and an emulator restart rebuilds the registration map empty, so
after either the instance's IMDS requests arrived from an address nothing
knew about, while the address from the previous run stayed registered.

Both paths now unregister the stale source address and register the
current one. A bridge-only instance is unaffected: its reported address
and its bridge address are the same, so there is no second registration.

* fix(ec2): keep the IMDS source registration when inspect fails

bridgeNetworkIp swallowed every inspect failure and returned null, the same
answer it gives for a container that genuinely has no bridge address.
refreshImdsSourceRegistration acts on that null by unregistering the instance's
recorded IMDS source address, so one transient Docker hiccup permanently dropped
a healthy instance's registration and put nothing in its place: its metadata
requests stopped resolving until some later start or restore happened to
succeed.

Split the two answers apart. bridgeNetworkIp now lets the exception propagate,
so null means only "no bridge address"; refreshImdsSourceRegistration catches it
and returns early, leaving the existing registration exactly as it was.

* docs(ec2): drop the em dashes this branch added

AGENTS.md forbids em dashes in all content. The enforcing check runs with
--diff-filter=A, so it only scans files a PR adds and stayed green on these, but a
check that cannot see a violation is not a licence for it. Six of them are in lines
this branch adds: four in docs/services/ec2.md, one in an Ec2ContainerManager javadoc,
one in an Instance javadoc.

Replaced with colons and commas. Wording is otherwise unchanged, and the em dashes
already present in these files are left alone: they predate this branch, and
rewriting them here would bury the actual change in unrelated churn.
2026-09-09 18:12:40 -05:00
..
2026-03-15 17:43:56 -05:00