An admin panel with a "restart" button and a terminal in the browser is convenient, but it is also a big attack surface. If a web app can run docker commands, anyone who takes over that app or someone's session can run them too. The thesis of this post: you can keep the convenience if you split the one who asks from the one who executes.
I describe a panel I wrote for a single-node Docker Swarm: .NET 10, Blazor, PostgreSQL and sign-in through my own SSO (OIDC). It replaced my daily ssh + docker ... from a laptop, and it does monitoring without Grafana.
1. The panel mostly reads
The Status, Nodes, Resources and Containers pages only read. The code that talks to the Docker socket sends GET only (services, tasks, nodes, logs). Metrics come from the host's cgroup v2 and from pg_stat_* through a role with pg_monitor. The RabbitMQ account has only the monitoring tag, and the RustFS keys are read only.
Honestly: mounting the Docker socket as :ro does not block writes through that socket. The flag applies to the file, not to the protocol. The safeguard is the code (one class, GET only) and the sign-in, not the mount itself.
2. Actions are requests, not commands
Restart, scaling and docker system prune don't call Docker from the panel. The panel writes a small file to the only directory it can write to:
op=scale
service=shop_api
replicas=0
[email protected]On the host a systemd path unit is waiting:
[Path]
PathExistsGlob=/var/lib/ambit-svr/ops-requests/*.requestIt starts a script that runs as a separate user in the docker group and takes requests one at a time, oldest first. Before it runs anything, it checks the file against its own rules:
- at most 6
key=valuelines, each value in its own pattern, and an unknown key rejects the whole request; - only three operations:
restart(docker service update --force),scale(0–5 replicas, replicated services only),prune(docker system prune -a -f, never--volumes); - the service must exist, and the node must be in the swarm;
- a list of protected services that it never scales to zero: SSO, Traefik, the file service and the panel itself.
The answer comes back next to it as <id>.state and <id>.log, and the panel only reads them and shows the history. The limits are written down twice, in the panel's config and in the host's unit, and the host's copy is the one that counts. The panel checks the same thing first only so the page never sends a request the host would refuse anyway.
The result: a bug in the panel or a stolen session can ask for these three things, nothing more. It is the same pattern I use for database backups: the panel asks for a dump or a restore, and the host does it.
3. Risky actions need intent, not a click
Scaling to zero and prune require typing the name of the service or node. Every action goes into the history: who asked, for what, when, and what the host answered. The page also has a "Scale back" button, because the host remembers the previous replica count.
4. The terminal: here the file pattern doesn't work
A shell can't be pushed through request files, so this is the one place where the panel writes directly. That's why I treat the terminal as the most dangerous feature:
- A container shell is
docker execthrough the socket, in a separate class. The rest of the code still sends GET only. - The host shell is ttyd (an Ubuntu package) on a unix socket, never on a TCP port, one session at a time. The panel relays the WebSocket only after its own checks.
- Fresh sign-in: the terminal opens only when the SSO sign-in (
auth_timefrom the ID token) is at most 5 minutes old. Otherwise the page sends you to SSO withprompt=login. An old session cookie alone is not enough. - The WebSocket's Origin must be the panel's own address, because the cookie rides along from any page that opens a WebSocket.
- Time limits: closed after 15 minutes idle and after one hour in total.
- Audit: every session is a row in the panel's database (who, where, when, why it ended). A failed audit write doesn't block the shell, because the shell is what fixes a broken server.
5. Monitoring without a metrics stack
For one server, Prometheus, Grafana and exporters are more things to maintain than what they watch. Instead:
- a small agent (
.deb) on each node writes disks (likedf, with inodes), CPU (user, system, iowait, steal), RAM, swap and containers to PostgreSQL every minute, and deletes data older than 7 days itself; - a sampler in the panel collects PostgreSQL counters every 10 seconds (connections, TPS, locks,
pg_stat_io, XID age, WAL), and the heaviest queries frompg_stat_statementsevery minute; - the charts are my own dark dashboard with ranges from 15 minutes to 14 days and drag-to-zoom.
Alerts are plain queries over those samples, sent by e-mail:
- disk at 80%, again every 24 h, and "back to normal" only below 78% (hysteresis, so you don't get mail at 79.9/80.1);
- CPU only when every minute of the last 10 was at least 95%. Short spikes wake nobody, and sustained load comes with the list of processes causing it.
Along the way the panel replaced my separate visits to the RabbitMQ management UI and the RustFS console. Queues of every vhost (purge after confirming) and S3 buckets (read only) have the same look and sit behind the same sign-in.
The role of the AI agent
I built the panel in about three weeks with Claude Code. The hard part wasn't the code, it was writing the rules down before the code existed. The decisions went into ADRs: "the panel asks, the host executes", "one class writes to the socket", "fresh sign-in before the terminal". The agent stuck to them, and in review it was easy to check that a change didn't break them.
The risk
Honestly: the host shell runs as the owner's account, and that account has sudo without a password. A stolen fresh session of the owner is root on the server. It's a conscious choice instead of a second factor: the fresh sign-in, the Origin check, the time limits and the audit shrink the window, but they don't close it. The container shell's env also shows that application's secrets. I accept that, because they are in the container anyway.
The "who asks, who executes" pattern is something I'd keep in any similar tool. It costs one directory, one systemd unit and a validating script, and for everything except the terminal it removes a whole class of "web app → root on the host" bugs.