[FEAT] ECS: same-task localhost for awsvpc tasks without security-group enforcement (rootless Docker / Podman)
Service
ECS (awsvpc task networking), related to EC2 security-group enforcement (#2564, #3681).
API Action / Feature
Same-task localhost for awsvpc tasks (RunTask / CreateService with networkMode: awsvpc), independently of security-group enforcement.
On Fargate, the containers of an awsvpc task share one network namespace and reach each other over localhost. In Floci, this shared namespace only exists as part of security-group enforcement (FLOCI_NETWORK_SECURITY_GROUP_ENFORCEMENT_ENABLED=true): EcsContainerManager.prepareNetwork returns null when enforcement is off, so each task container gets its own Docker IP and 127.0.0.1:<port of a sibling container> is refused.
Proposed: an opt-in setting that keeps the shared namespace when enforcement is off.
floci:
services:
ecs:
shared-task-network: false # FLOCI_SERVICES_ECS_SHARED_TASK_NETWORK
When enforcement is off and this setting is on, prepareNetwork creates the same helper container (floci/network-helper) without applying the nftables ruleset, and the task containers join it with container:<helper>, as in the protected path. The helper owns the published ports and is removed with the task ENI (unregister). Helpers left over by a previous run are removed at startup. When enforcement is on, nothing changes.
Two small issues found along the way, which also affect the enforcement path:
- ELBv2 target address. When Floci runs in a container,
EcsContainerManager.resolveContainerHostinspects the workload container to find the target address. A container incontainer:<helper>mode has no network of its own, so the lookup falls back to127.0.0.1. Following the network mode to the helper fixes ALB targets for tasks in a shared or protected namespace. - Helper image name.
src/main/resources/docker/network-helper.Dockerfileuses the short namealpine:3.21. Podman enforces fully-qualified names when it cannot prompt, so building the helper through the Docker-compatible API fails.docker.io/library/alpine:3.21works on both Docker and Podman.
AWS Documentation
- Amazon ECS task networking options for Fargate: containers that belong to the same task communicate over the
localhostinterface. - Allocate a network interface for an Amazon ECS task (
awsvpcnetwork mode)
Why is this needed?
Multi-container awsvpc task definitions (the Fargate sidecar pattern: nginx → php-fpm on 127.0.0.1:9000, a cache in front of the web server, an Envoy or log-router sidecar) cannot run unchanged in Floci on Linux with rootless Docker or Podman, which is a common local setup. Local task definitions then have to diverge from the ones deployed to AWS.
Enforcement, the only way to get the shared namespace today, cannot be used everywhere:
- Rootless Docker / rootless Podman:
SecurityGroupFirewallManager.createNamespacerejects it (Security-group enforcement requires rootful Docker, as documented indocs/services/ec2.md). - Rootful Podman on Linux (WSL2): enforcement starts, but in my setup Floci then could not reach its own backends. ElastiCache provisioning looped on
ElastiCache backend for group spike2-redis did not become ready on 10.89.0.3:6379 within 60000msand the replication group was rolled back. I did not isolate the cause; #3681 mentions that native rootful Linux validation was deferred, so this may already be known.
Security-group filtering and same-task localhost are separate concerns. The first needs nftables and privileges. The second only needs the task containers to join one namespace, which works unprivileged, rootless included.
Reproduction. Floci 2.1.0 and main @ 204e509e8, Podman 5.8.4 (netavark, cgroup v2), Fedora 44 on WSL2 (kernel 6.18). Floci runs in a container on a user-defined network, with the Podman socket mounted as /var/run/docker.sock.
resource "aws_ecs_task_definition" "t" {
family = "localhost-check"
requires_compatibilities = ["FARGATE"]
network_mode = "awsvpc"
cpu = "256"
memory = "512"
container_definitions = jsonencode([
{
name = "web"
image = "docker.io/library/busybox:latest"
essential = true
command = ["httpd", "-f", "-p", "8081", "-h", "/etc"]
},
{
name = "proxy"
image = "docker.io/library/nginx:alpine"
essential = true
portMappings = [{ containerPort = 80 }]
command = ["sh", "-c",
"printf 'server { listen 80; location / { proxy_pass http://127.0.0.1:8081; } }' > /etc/nginx/conf.d/default.conf && exec nginx -g 'daemon off;'"]
},
])
}
# + aws_ecs_service (FARGATE, awsvpc subnets and security group)
Inside the proxy container:
$ wget -qO- http://127.0.0.1:8081/hostname
wget: can't connect to remote host (127.0.0.1): Connection refused
docker inspect shows the two containers in bridge mode with two different IPs (10.89.1.18 and 10.89.1.19). On AWS, this request succeeds.
Status. I have a patch: the setting, the shared helper, the two fixes above, docs, and a unit test class, about 360 lines including tests. Checked on rootless Podman 5.8.4 with the reproduction above:
- both containers join the helper (
container:<helper>) andproxyreacheswebon127.0.0.1:8081; - the task still reaches RDS and ElastiCache;
- an ALB target group gets the helper address and serves
HTTP 200through the proxy; - the helper is removed when the task is replaced and when Floci restarts.
The existing ECS, EC2 and security-group unit tests still pass (158 run, 0 failures). Workloads in a shared namespace keep their capabilities; only enforced workloads drop NET_ADMIN/NET_RAW, as today.
Are you willing to contribute a PR?
- [x] Yes
- [ ] No
👋 Thanks for opening your first issue in Floci!
A maintainer will triage this and add the right service label. If you included a minimal reproduction and the Floci version, that is everything we need — no action required from you right now.
Come say hi in Slack if you want to talk it through with maintainers and other contributors. Questions about AWS behaviour, design tradeoffs, and rough proposals are all welcome there.
@jossensei please check out this proposal -> https://github.com/orgs/floci-io/discussions/4065
Thanks @CoreOxide, I read through #4065, including the Docker Desktop prototype results.
As far as I can tell the two are independent:
- #4065 is about EC2 host port publishing with security-group enforcement on, and explicitly leaves ECS out of scope.
- This issue is about ECS
awsvpctasks without enforcement: the containers of a task only need to share one network namespace so that127.0.0.1reaches the sibling containers, as on Fargate. There is no filtering, no DNAT and no return path involved, so the two blockers found in the prototype do not apply here.
The target environment also differs: enforcement requires rootful Docker, while this request is mainly for rootless Docker and Podman, where enforcement is refused.
The only overlap I see is the helper container, which this would reuse without the nftables ruleset, behind an opt-in setting. With enforcement on, nothing changes, so whatever design #4065 lands on should not be affected.
@jossensei thanks for the detailed write-up. We're picking this up as the opt-in you proposed, in #8654: floci.services.ecs.shared-task-network (FLOCI_SERVICES_ECS_SHARED_TASK_NETWORK), off by default. With it on and security-group enforcement off, an awsvpc task gets a helper container that holds its network namespace, with no nftables ruleset and no rootful Docker requirement, and every container in the task joins it, so they reach each other on localhost as on Fargate. With enforcement on, nothing changes.
The helper also takes over what each container holds on its own today: the published ports, the link-local address for task-role credentials, and the task's ENI address on the VPC network. FireLens's FLUENT_HOST is 127.0.0.1, the value the ECS agent sets for awsvpc, and the helper is removed with the task and swept at startup like any other leftover ECS container. The ELB target fix has been on main since #4509, and the qualified docker.io/library/alpine name goes in too, since the task-role credentials proxy is built from the same Dockerfile.
If you can try it on rootless Podman, that would be a great check, since that's the setup we can't easily reproduce here.