Floci rewrites an AWS-shaped ECR image of an ECS task or an image-backed
Lambda to its loopback registry and hands that address to the Docker
daemon, as <account>.dkr.ecr.<region>.localhost:<port>/<repo> in the
hostname style. A daemon with the containerd image store, the default
from Docker Engine 29, cannot pull from it. Measured on Docker 29.9.1:
against a plain HTTP registry:2, localhost:<port> and 127.0.0.1:<port>
are reached over HTTP, while any *.localhost name is tried over HTTPS
only ("server gave HTTP response to HTTPS client"), the 127.0.0.0/8
insecure CIDR notwithstanding. With Floci's TLS on, the same names reach
Floci's TLS port and fail on its certificate instead (unknown authority,
and *.localhost names are not in it). The containers never start: ECS
reports TaskFailedToStart.
So the rewrite now always gives localhost:<port>/<account>/<region>/<repo>,
path style, in either URI style and with or without TLS: the address
every daemon, classic or containerd store, pulls from over plain HTTP.
The data plane claims path-style requests on a loopback host (localhost,
127.0.0.0/8, ::1) in the hostname style too, so those pulls still go
through it and its repository name mapping. Nothing else changes: the
advertised repositoryUri, the login endpoint and pushes keep their style.
ECR built repositoryUri, the GetAuthorizationToken proxyEndpoint and
the Lambda and ECS image rewrites from floci.port, the port Floci
listens on inside its own container. The Docker daemon performs login,
push and pull, and reaches Floci through the host port that container
publishes. When Floci ran as docker run -p 54321:4566, every advertised
address named port 4566 on the host, where nothing answers, so docker
login, CDK container asset publishing and ECS or Lambda image pulls
failed.
EcrRegistryManager now has advertisedPort(): the host port Floci's
container publishes for floci.port, read through the existing
CurrentContainerNetworkResolver.resolvePublishedPort as RDS does for
its proxy endpoint, or floci.port when Floci is not in a container or
the port is not published. repositoryUri (hostname and path style,
plain and TLS URI mode), proxyEndpoint and rewriteImageUri all use it.
The EKS registry mirror keys must match the URIs pods name, so they
use the same advertised port. The mirror endpoint stays Floci's
in-network address on floci.port.
The resolver now caches every published-port answer, "not published"
and a failed inspect included, as it already caches the network: a
running container's port bindings cannot change, and an inspect that
fails fails the same way next time. ECR requests therefore do not
inspect the container each time.
* fix(ecr): retry occupied registry ports
The backing registry reserved one port from the configured range and gave
up when Docker refused to publish it, although the next port was free. The
allocator's probe races `docker run`, and from inside a container it cannot
see a host process holding the port, so a refusal is expected and not fatal.
A start Docker refuses as a host-port collision now moves on to the next
port in the range; any other failure still fails at once. Refused ports stay
reserved until the start finishes so each is tried once, then are released.
When the range runs out the error names the refused ports. EC2's collision
check moves to PortAllocator so both callers share it.
Closesfloci-io/floci#4856
* chore(ecr): keep the port retry tests independent of host ports
The unit tests now use an allocator that skips the host probe, so a busy
6100 or 6101 on the machine cannot change their outcome. The integration
test picks its port pair with the Docker-aware allocator, so a container
already publishing a port is skipped as well, and drops its logger.
* docs(ecr): say other registry start errors still fail at once
The paragraph said startup fails only when the range is full, but a daemon
or image failure still fails without trying another port. The exhaustion
tests now also allocate the last refused port, so releasing only some of
them fails.
* refactor(ec2,ecr): share the port retry loop in PortAllocator
Review asked for the allocate, start and retry loop itself to live in one
place, not just the collision check. PortAllocator.allocateAndStart takes
the start as a callback, moves past ports Docker refuses as in use, and
releases the refused ports when it returns. ECR and EC2 both call it.
EC2 used to mark a refused SSH port reserved for the life of the process.
It now releases it after the launch, as ECR does, so a port whose holder
goes away is usable again.
With the loop moved, a launch cancelled between attempts can now reach
the worker's failure path. When Docker is also gone that path marked the
instance running without a container, so it now goes through markRunning
and leaves a cancelled instance terminated.
* test: share one host-blind PortAllocator across the port tests
PortAllocatorTest, EcrRegistryManagerTest and the ECR port-conflict
integration test each built their own allocator that skips the host
probe. HostBlindPortAllocator replaces the three copies.
* fix(ecr): support image scanning configuration updates
* fix(ecr): validate scanning configuration booleans
* fix(ecr): accept null scan-on-push values
* docs(ecr): list the image scanning configuration actions
Add PutImageScanningConfiguration and BatchGetRepositoryScanningConfiguration
to the Supported Actions table. The table is not generated, so the docs check
does not catch a missing row.
- Update ECR host routing regex to support <account>.dkr.ecr.<region>.localhost.floci.io
- Populate regional wildcard SANs (*.dkr.ecr.<region>.localhost.floci.io) for all advertised AWS regions
- Add unit tests for hostname matching, malformed host rejection, immutable tag mutability over TLS, and certificate SAN enumeration
- Add Docker integration test verifying end-to-end TLS image push/pull with root CA verification and plain HTTP regression
- Update ECR and TLS user documentation
Route Docker Distribution traffic through Floci so repository mutability applies to manifest writes. Keep legacy registry storage reachable while moving public ECR endpoints to the guarded listener.
* feat(ecr): prefer locally present images over the loopback registry rewrite
EcrRegistryManager.rewriteImageUri rewrote every AWS-shaped
<account>.dkr.ecr.<region>.amazonaws.com/<repo>:<tag> URI to Floci's
loopback registry unconditionally, so a container image Lambda function
(or ECS task) whose image was built locally and tagged with its real ECR
URI could never run: the launcher started the registry:2 sidecar and
tried to pull from it, failing with "failed to resolve reference ..."
(Lambda.InitError) even though the daemon already held the image.
The rewrite now first asks the Docker daemon whether the image exists
under the URI as given; if it does, the URI is used unchanged and the
registry container is not started. Images the daemon does not have keep
the existing rewrite-and-pull path, so CDK DockerImageFunction flows are
unaffected. floci.services.ecr.prefer-local-images
(FLOCI_SERVICES_ECR_PREFER_LOCAL_IMAGES, default true) restores the old
behaviour when set to false.
Verified with a provided.al2023 Go image tagged
000000000000.dkr.ecr.ap-southeast-2.amazonaws.com/e2e/hello-image:local:
Invoke fails on 2.0.1 and succeeds with this change, both with Floci as
a host process and inside a container sharing the host's docker.sock; an
image absent from the daemon still takes the rewrite path.
* fix(ecr): inspect the image reference ContainerBuilder launches when preferring local images
With floci.docker.image-registry-base set, rewriteImageUri inspected the bare
AWS-shaped URI while ContainerBuilder later prefixed it, so a locally present
image was reported as found and then missed at launch. Resolve the image
through ContainerBuilder before asking the daemon so both paths agree.
k3s containerd could not reach the emulated ECR registry: repository
URIs embed localhost plus the host-published port, which resolves to the
k3s container itself, and containerd requires a registries.yaml entry
before it will speak plain HTTP to a registry.
New clusters now get a generated /etc/rancher/k3s/registries.yaml,
injected through the Docker API before the container starts, that
mirrors every repository hostname the emulator can mint (the default
account across the region catalog, plus the path-style form) to the
registry container's in-network endpoint. Public registries are never
matched, and any failure skips the mirror without aborting cluster
creation. Opt out with FLOCI_SERVICES_EKS_ECR_REGISTRY_MIRROR=false.
Closes#1761
* docs: update Docker image references to floci/floci
* docs: keep README Docker Hub badges pointing to hectorvent/floci
The hectorvent/floci image has accumulated pull and size metrics; switch
the badges to floci/floci once the new image has comparable numbers.
* fix(ecr): fixing port and network issues on ecr
* fix: issue on merge with main
* fix(ecr): connect containers to network after start only when port bindings exist