fix: restrict docker commands for ai-worker (wrapper blacklist — exec, cp, commit, etc. blocked) #65

Open
Hermes wants to merge 1 commits from feat/restrict-docker-blacklist into master
Collaborator

Security Fix: Block dangerous docker commands for ai-worker

Problem

The ai-worker user is in the docker group, giving unrestricted access to ALL Docker commands. An agent was able to generate a Gitea admin token via docker exec -u git gitea gitea admin user generate-access-token -u gortium.

This PR

Keeps ai-worker in the docker group (so docker ps, docker compose, docker build, docker run, etc. still work), but wraps the docker binary with a script that blocks dangerous subcommands.

BLOCKED commands

exec, cp, commit, diff, export, import, load, save, attach, push, tag

ALLOWED commands

ps, images, inspect, logs, start, stop, restart, rm, rmi, pull, build, run, compose, system, network ls, volume ls

How it works

A wrapper script intercepts docker calls, parses the subcommand, and rejects blocked ones. The wrapper is installed both as a system package and in ai-worker's personal profile so it takes precedence over the real Docker binary.

Fixes

Closes the security incident where the agent created a Gitea admin token via docker exec.

## Security Fix: Block dangerous docker commands for ai-worker ### Problem The `ai-worker` user is in the `docker` group, giving unrestricted access to ALL Docker commands. An agent was able to generate a Gitea admin token via `docker exec -u git gitea gitea admin user generate-access-token -u gortium`. ### This PR Keeps ai-worker in the `docker` group (so `docker ps`, `docker compose`, `docker build`, `docker run`, etc. still work), but wraps the `docker` binary with a script that **blocks dangerous subcommands**. ### BLOCKED commands `exec`, `cp`, `commit`, `diff`, `export`, `import`, `load`, `save`, `attach`, `push`, `tag` ### ALLOWED commands `ps`, `images`, `inspect`, `logs`, `start`, `stop`, `restart`, `rm`, `rmi`, `pull`, `build`, `run`, `compose`, `system`, `network ls`, `volume ls` ### How it works A wrapper script intercepts `docker` calls, parses the subcommand, and rejects blocked ones. The wrapper is installed both as a system package and in ai-worker's personal profile so it takes precedence over the real Docker binary. ### Fixes Closes the security incident where the agent created a Gitea admin token via docker exec.
Hermes added 1 commit 2026-05-21 00:42:47 +00:00
SECURITY CHANGE: Keep ai-worker in docker group but block dangerous
docker subcommands via a wrapper script.

Approach:
- docker group membership preserved (ps, start, stop, compose still work)
- Docker binary wrapped with a script that blocks dangerous subcommands
- BLOCKED: exec, cp, commit, diff, export, import, load, save, attach, push, tag
- ALLOWED: ps, images, inspect, logs, start, stop, restart, rm, rmi,
  pull, build, run, compose, system, network ls, volume ls

The wrapper is installed in both system packages and ai-worker's
personal profile to ensure it takes precedence over the real docker.
This is effective for the LLM agent threat model — the agent uses CLI
commands and blocked subcommands simply return an error.

Files modified:
- users/ai-worker.nix — restored docker group, kept sudo audit rules
- modules/nixos/security/ai-worker-restricted.nix — added docker wrapper
  script with blacklist logic and NixOS module integration
- modules/nixos/security/README-ai-worker.md — documentation update
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin feat/restrict-docker-blacklist:feat/restrict-docker-blacklist
git checkout feat/restrict-docker-blacklist
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: gortium/infra#65
No description provided.