Why the executor runs as root
What limits kosken-exec on a machine, what does not, why Kosken does not use sudo, and how to check each point on your own host.
On this page
On each machine, kosken-exec runs as root. Security teams ask why, and whether a sudo rule would be safer. This page answers both questions for an auditor. It lists the limits that systemd and the signatures put on the executor, the limits that do not exist, and the commands that check each point on your host.
For the full model, with the agent, the gates and the approvals, see How Kosken keeps a machine safe.
Why root
The executor runs the recipes of Kosken: it installs packages, restarts services, changes kernel settings, runs containers, manages Proxmox guests and makes backups. apt-get, dnf, rpm and systemctl check that they run as user 0. A plain user with Linux capabilities is not enough for them. So the executor is root, and systemd limits what that root can reach.
The unit, as the install writes it
[Service]
User=root
EnvironmentFile=-/etc/kosken/agent.env
ExecStart=/usr/local/lib/kosken/current/kosken-exec
Restart=always
RestartSec=5
RuntimeDirectory=kosken
RuntimeDirectoryMode=0755
RuntimeDirectoryPreserve=yes
PrivateNetwork=yes
ProtectHome=yes
PrivateTmp=yes
RestrictAddressFamilies=AF_UNIX
ReadWritePaths=/var/lib/kosken/exec /var/lib/kosken/recipes /run/kosken
CapabilityBoundingSet=CAP_CHOWN CAP_DAC_OVERRIDE CAP_DAC_READ_SEARCH CAP_FOWNER CAP_KILL CAP_SETUID CAP_SETGID CAP_SETPCAP CAP_AUDIT_WRITE CAP_SYS_PTRACE CAP_SYS_RESOURCE
MemoryMax=512M
What limits the executor
- No network.
PrivateNetwork=yesgives the executor a network namespace with only a loopback interface, andRestrictAddressFamilies=AF_UNIXlets it open local sockets only. Nothing on the network can connect to it, and it cannot send data out. Orders come from the agent on a local socket. - A closed set of capabilities. The bounding set above is the most that the executor and every program it starts can hold, also as root. It has no
CAP_SYS_ADMIN, so it cannot mount file systems or change most device settings. It has noCAP_SYS_MODULE,CAP_SYS_RAWIO,CAP_SYS_BOOT,CAP_SYS_TIMEorCAP_NET_ADMIN: it cannot load a kernel module, read raw memory or disks, reboot through the kernel, set the clock or change the network. - No home directories, a private /tmp and 512 MB of memory.
ProtectHome=yeshides/home,/rootand/run/user. - Signed recipes only. A recipe is a signed JSON document. Each step is a fixed list of arguments, never a shell string, and parameters have types and allowed values. The executor keeps a recipe only when its signature leads to the root key, whose public half is built into the binary. The root key is kept offline.
- Signed orders. Each order is signed with a separate key and names one machine and one workspace. The executor refuses an order that expired, that it ran before, or whose recipe or parameters do not match.
- Needs that a person on the host enables. A recipe that needs more than the base unit declares a need. The need adds a systemd drop-in, and only root on the host can add it, with
kosken-agent enable <need>. Kosken cannot widen a host.kosken-agent disable <need>removes it. - A local log. The executor writes one line per order to
/var/lib/kosken/exec/audit.log, each with the hash of the line before it. A changed line, or a line removed from the middle, breaks the chain.
What each need adds
| Need | What the drop-in adds |
|---|---|
gpu | CAP_SYS_ADMIN, which NVML asks for to change power limits and clocks, and write access to /sys/class/drm, /sys/devices and /etc/systemd/system. |
os_tune | CAP_SYS_ADMIN, and write access to the CPU governor, transparent huge pages, the kernel and vm settings in /proc/sys, /etc/sysctl.d, /etc/default, /etc/kernel, /boot and /etc/systemd/system. |
packages | Network out, so apt, dnf and zypper reach their mirrors. |
storage | Network out to backup destinations, the home directories, the restore and backup directories, and 1 GB of memory. |
network | Network out to the address of the Kubernetes API server only (IPAddressDeny=any with that address allowed). |
proxmox | Network, the home directories, CAP_SYS_ADMIN, CAP_NET_ADMIN and the other capabilities that pvesh, qm and pct need, the Proxmox directories, and 1 GB of memory. |
What does not limit it
- The file system is writable. The unit does not set
ProtectSystem, because recipes install packages and write files in/etc. WithCAP_DAC_OVERRIDEandCAP_CHOWN, the executor can write any file outside the home directories. A process that can write a systemd unit or a cron file can get full root on the next start. - Docker. On a host with Docker, the executor reaches the Docker socket. A recipe that runs
dockercan do anything root can do. - The keys. The root key is offline, but the recipe signing key and the order signing key are on the Kosken platform. If the platform is compromised, an attacker can sign recipes and orders until the root key revokes the signing key. The local log on the host records each order, and you can read it without trusting Kosken.
So the real boundary is the signature. The executor runs what Kosken signed, inside the limits above, and nothing else.
Why not sudo
Kosken planned a mode where the executor runs as a plain user and calls sudo for each step that needs root, with a sudoers file that lists the allowed commands. The plan was dropped, for these reasons:
- The recipes have 1,540 command steps that use 133 programs, and their arguments come from parameters. A sudoers rule for them needs wildcards such as
systemctl *. - Many of those programs give root with the right arguments:
docker,apt-get,dnf,systemctl,runuser,pvesh,qm,pctandkubectl. A list that allows them allows root. - 27 steps are code inside the executor, for example writing a file, changing a GPU setting or running a backup. sudo cannot limit code inside a process.
- A single sudo rule that hands each signed step to a root helper keeps the same boundary, the signature. It adds a line in the sudo log, and the local log of the executor already records each order.
If your policy does not allow a root service, write to us. The sudo design stays on record for that case.
Check it on your host
Each of these commands reads your host, not Kosken.
systemctl cat kosken-exec.service
systemctl show kosken-exec.service -p User -p PrivateNetwork -p CapabilityBoundingSet
ls /etc/systemd/system/kosken-exec.service.d/
systemd-analyze security kosken-exec.service
sudo /usr/local/lib/kosken/current/kosken-agent log-audit
The first two show the unit with its drop-ins and the values that systemd applies. The third lists the needs that a person enabled. The fourth rates the sandbox of the unit. The last prints the local log of the executor and checks its hash chain.
Something here does not match the app? Tell us