Hardening

Lock containers down, set resource limits, accept exceptions and bring the whole host in line with align.

Lint and harden

seawall stack lint nextcloud          # the gaps
seawall stack lint --all
seawall stack lint --rules        # every rule
seawall stack harden nextcloud        # the proposed change
seawall stack harden nextcloud --yes  # writes the disk copy and deploys it

harden adds only keys that are missing. These are no-new-privileges, cap_drop: [ALL] with the capabilities the image is known to need, admin ports on 127.0.0.1 and services off the default bridge. An image whose files can't be read keeps its capabilities. It never proposes read_only. With --yes it runs the change on a copy of the stack for a minute first and drops a setting the copy refuses, naming it. It then writes the disk copy and deploys it, backed up first and rolled back if the stack doesn't come up. For 15 minutes after, it watches for refusals and out-of-memory kills and alerts on any. A stopped stack stays stopped. Its file is updated and the change applies at its next start.

Take a setting out again with --remove. It writes an allow line in the compose file so harden doesn't propose it again. In the command centre the harden pane offers r to roll back and R to take one setting out.

seawall stack harden kuma --remove cap_drop --service uptime-kuma --yes

Warnings sit beside the errors, among them memory and PID limits, a read-only root, host mounts and NET_ADMIN. cpu-limit wants a CPU limit so one container can't take every core. ulimits wants an open files ulimit (nofile). healthcheck wants a health check, the service's or its image's. The first lint of a host reads each image once to see its own health check.

A start script that runs as root and starts its app as another user needs KILL, the permission to signal another user's process. With it the start script passes the stop signal to the app. The app then saves before it stops. Without it every stop ends in a kill. harden and an update of such a container add it.

Admin screens stay on 127.0.0.1. Lint gives an error for one published on any other address. The rule covers Nginx Proxy Manager's port 81, Portainer, Grafana, Prometheus, cAdvisor, Traefik's dashboard and CrowdSec's API. harden binds the port to 127.0.0.1 and prints the SSH tunnel that reaches it. A port written in long syntax needs host_ip: 127.0.0.1 added by hand.

-      - "3000:3000" # the dashboard
+      - "127.0.0.1:3000:3000" # the dashboard
ssh -N -L 3000:127.0.0.1:3000 <this host>

Accept a finding on purpose with a comment anywhere in the compose file. Lint stops reporting it and harden stops proposing it.

# seawall-lint: allow docker-socket socket-proxy -- the proxy needs it
# seawall-lint: allow root game until 2026-12-31 -- the image needs root
# seawall-lint: allow privileged vpn -- WireGuard

A comment with until expires on that day. The finding then comes back in lint, posture and facts. allow root shows the container as accepted in seawall security.

Resource limits

seawall stack limits nextcloud        # the proposed limits
seawall stack limits nextcloud --yes
seawall stack limits monitoring --remove cpus --service cadvisor --yes
seawall stack limits game --never

stack limits sets them. Limits are a backstop against a container running away. Memory is a hard limit at twice the observed peak and an alert fires when a container nears it. CPU is a weight (cpu_shares) that only counts when containers compete. Processes get one fixed cap of 4096 and open files keep what the container runs with now. --cpu-cap adds a hard CPU quota at four times the 99th percentile of each minute, at least one core. Collectors and proxies never get one. A service that sets its limits under deploy.resources gets them written there.

--remove takes a limit out and --never stops proposing limits for a stack. --again proposes them again. Like harden it deploys with --yes, trying a tighter limit on a copy first, and watches for 15 minutes after, here for refusals, out-of-memory kills and refused forks. A limit that only loosens has no trial and no watch.

Everything at once

seawall align            # what isn't as seawall wants it
seawall align --yes
seawall align --only harden,limits --yes

align is one plan for the whole host. It lists init's steps not done, the fixes in To do, Security rows with a fix, image updates that aren't a major, restart policies, harden and limits. With --yes it runs each step through its own command. Databases are backed up first and the proxy's and Portainer's stacks go last. It stops at the first step that fails or leaves a stack worse, names the rollback and exits non-zero. Run it again to carry on.