Checks / Docker and containers
Container ports are published on all addresses
- Check
docker.public_ports- Severity
- medium
- Runs
- on the server, in the daily run of the agent
- Looks at
- Ports published on 0.0.0.0 or :: (Docker adds its own iptables rules and bypasses ufw)
What the check looks at
The port bindings of every running container. The check warns for each port published without a host address
or on 0.0.0.0 or ::, with the container name as the subject and the binding as evidence, for example
0.0.0.0:5432->5432/tcp. Ports bound to 127.0.0.1, ::1 or one specific address pass. Containers on the
host network are covered by docker.host_network and by the list of listening
sockets.
Risk
-p 5432:5432 or ports: ["5432:5432"] publishes the port on every address of the host. Docker reaches the
container through a DNAT rule and its own chains at the start of the FORWARD chain. These packets never pass
the INPUT rules of ufw, and firewalld forwards them through the docker zone, which Docker creates with the
target ACCEPT. The Docker documentation calls Docker and ufw "incompatible". A database or admin interface
published this way is open to the internet, and ufw status does not list it.
The severity is medium because many published ports are meant to be public, such as 80 and 443 of a reverse proxy.
How to fix it
-
Decide for each reported port whether other machines must reach it.
-
If only the host needs it (a reverse proxy, a backup job, you through an SSH tunnel), bind it to loopback:
services: db: ports: - "127.0.0.1:5432:5432"or
docker run -p 127.0.0.1:5432:5432 ..., then recreate the container (docker compose up -d <service>). -
If only other containers need it, remove the
ports:entry. Containers on the same Docker network reach each other by service name. -
If some outside addresses need it, keep the binding and filter in the
DOCKER-USERchain with-m conntrack --ctorigdstport <port>. The guide Docker bypasses ufw has a tested script and a systemd unit for it.
To reach a loopback port from your machine, open an SSH tunnel:
ssh -L 5432:127.0.0.1:5432 user@server.
How to check the fix
docker ps --format 'table {{.Names}}\t{{.Ports}}'
0.0.0.0 or [::] must appear only for the ports you want public. From another machine,
nc -zv -w 3 <server> 5432 must fail.
When a warning is fine
For ports that are meant to be public, such as 80 and 443 of a reverse proxy, a mail server or a public API. Accept the result for that container on the dashboard.
A firewall at the hosting provider also blocks the port, since Docker cannot change it. The finding then tells you that the server itself does not filter the port, a risk on the day someone changes the provider rules.
An accepted result stays out of the digest and the counts until it changes.
Sources
- Docker docs: Packet filtering and firewalls
("Docker and ufw", the firewalld zone
docker) - Docker docs: Port publishing and mapping
(default bind address
0.0.0.0and[::]) - Docker docs: Docker with iptables
(
DOCKER-USER,--ctorigdstport)