docs: condense CONTRIBUTING; status moves to the PR description
Generated-by: Claude Opus 5.5
This commit is contained in:
1 parent
052a9dc640
commit
6d48662c94
1 file changed
+35
-86
+35
-86
@@ -4,29 +4,21 @@ How to check a change, and why the confinement holds. For what this is and how t
|
||||
|
||||
## Layout
|
||||
|
||||
- [nix/hermes-guest.nix](nix/hermes-guest.nix): the confined unit, the part that ports. Its `sandbox` attribute set is the confinement this document argues for.
|
||||
- [nix/linux-host.nix](nix/linux-host.nix), [nix/llm-proxy.nix](nix/llm-proxy.nix): on a Linux host, systemd serves the unit's two sockets.
|
||||
- [nix/vfkit-vm.nix](nix/vfkit-vm.nix), [nix/darwin-host.nix](nix/darwin-host.nix): on macOS, the same unit in a microVM, with its sockets relayed over vsock to launchd on the host.
|
||||
- [nix/hermes-guest.nix](nix/hermes-guest.nix): the confined unit, the part that ports. Its `sandbox` attribute set is what [Confinement](#confinement) argues for.
|
||||
- [nix/linux-host.nix](nix/linux-host.nix), [nix/llm-proxy.nix](nix/llm-proxy.nix): on Linux, the host's systemd serves the unit's two sockets.
|
||||
- [nix/vfkit-vm.nix](nix/vfkit-vm.nix), [nix/darwin-host.nix](nix/darwin-host.nix): on macOS, the same unit in a microVM, with its sockets relayed over vsock to launchd.
|
||||
- [llm-proxy.py](llm-proxy.py): the inference proxy, which holds the API key.
|
||||
- [test/](test/demo.py): unmodified Hermes against a fake host and a scripted model.
|
||||
|
||||
## Checking a change
|
||||
|
||||
Doctests, for the fake host and the scripted model:
|
||||
|
||||
```sh
|
||||
cd test && python3 -m doctest fake_host.py fake_llm.py
|
||||
cd test
|
||||
python3 -m doctest fake_host.py fake_llm.py
|
||||
python3 demo.py path/to/hermes path/to/socat # ends with PASS
|
||||
```
|
||||
|
||||
The demo needs a `hermes` and a `socat`. Hermes's own flake doesn't build on macOS yet (its pnpm dependency hash is wrong there), so install it from a checkout with `uv sync --frozen --extra mcp`:
|
||||
|
||||
```sh
|
||||
cd test && python3 demo.py path/to/hermes-agent/.venv/bin/hermes "$(nix build --no-link --print-out-paths nixpkgs#socat)/bin/socat"
|
||||
```
|
||||
|
||||
It ends with `PASS: Hermes acted as a guest, over MCP on host.sock` in a few seconds. Hermes starts helpers detached from the demo's process tree (`hermes_cli.default_plugins`). Under systemd they stay in the unit's cgroup; after a demo run, look for strays with `pgrep -fl hermes_cli`.
|
||||
|
||||
Evaluate both platforms' configurations after a change to `nix/`:
|
||||
The demo leaves Hermes's detached helpers running; look for them with `pgrep -fl hermes_cli`. After a change to `nix/`, evaluate both platforms:
|
||||
|
||||
```sh
|
||||
nix eval --impure --expr '(builtins.getFlake (toString ./.)).lib.mkDarwin {
|
||||
@@ -34,93 +26,50 @@ nix eval --impure --expr '(builtins.getFlake (toString ./.)).lib.mkDarwin {
|
||||
}.runner.drvPath'
|
||||
```
|
||||
|
||||
Python here follows [DisciplinedPython](https://codeberg.org/dckc/awesome-ocap/src/branch/master/style-guide/ocap-py-style-guide.md); run its checker on any script you change.
|
||||
Python here follows [DisciplinedPython](https://codeberg.org/dckc/awesome-ocap/src/branch/master/style-guide/ocap-py-style-guide.md); run its checker on scripts you change. When you change the sandbox, update the table below in the same commit.
|
||||
|
||||
## Confinement
|
||||
|
||||
### The claim
|
||||
**Claim:** every process running as Hermes's user changes the world outside its state directory only by:
|
||||
|
||||
Every process that runs as Hermes's user can change the world outside Hermes's own state directory in three ways only:
|
||||
1. connecting to `host.sock`: the authority of one Endo guest;
|
||||
2. connecting to `llm.sock`: inference at one upstream, with a key it never holds;
|
||||
3. writing to its stdout and stderr, which go to the journal.
|
||||
|
||||
1. **`host.sock`**, which gives the authority of one Endo guest: the guest's methods (`listMessages`, `request`, `lookup`, `reply`, `adopt`, `dismiss`, ...), on names in its own pet store.
|
||||
2. **`llm.sock`**, which gives inference at one upstream, with a key that Hermes never holds.
|
||||
3. **Its stdout and stderr**, which go to the journal.
|
||||
|
||||
These processes are the gateway, every tool it runs (shell, code execution, browser), every MCP server it starts, and the LLM bridge.
|
||||
|
||||
### The approach: assume nothing about Hermes
|
||||
|
||||
The argument treats Hermes and its model as adversaries. It doesn't depend on which toolsets are enabled, what `config.yaml` says, or what the model chooses to do. That matters because Hermes can rewrite its own configuration: `config.yaml` is in its writable state directory. It can add MCP servers, turn tools on, or run any program its shell can reach. Every one of those runs as a descendant of the unit, so it inherits the same namespaces, mounts, cgroup and seccomp filter, and gains no new authority. The configuration decides only what Hermes does with the authority it has.
|
||||
|
||||
So the argument is about the `sandbox` attribute set in [nix/hermes-guest.nix](nix/hermes-guest.nix), which every unit running as Hermes's user gets. It goes channel by channel: every way a Linux process can affect anything outside itself.
|
||||
|
||||
### Channel by channel
|
||||
**Approach: assume nothing about Hermes.** Hermes can rewrite its own `config.yaml`, add MCP servers, and run anything its shell reaches. All of it runs inside the unit, so it inherits the same namespaces, mounts, cgroup and seccomp filter. So the argument is about the `sandbox` in [nix/hermes-guest.nix](nix/hermes-guest.nix), which every unit running as Hermes's user gets, not about Hermes or its model.
|
||||
|
||||
| Channel | What closes it |
|
||||
|---|---|
|
||||
| IP networking | `PrivateNetwork`: a network namespace with only loopback. `IPAddressDeny=any` with `IPAddressAllow=localhost` is a second check, enforced by eBPF on the cgroup. The namespace is shared with the bridge alone, so the only listener in it is the bridge's port, which forwards to `llm.sock`. |
|
||||
| Unix sockets, by path | A path-named socket works across network namespaces. A socket on a read-only mount still accepts `connect()`, so `ProtectSystem=strict` alone doesn't stop this. The places sockets live are hidden: `TemporaryFileSystem` makes `/run` (and so `/var/run`) and `/var/lib` empty, `PrivateTmp` covers `/tmp`, and `ProtectHome` covers `/home`, `/root` and `/run/user`. Then `BindReadOnlyPaths` binds back just `host.sock` and `llm.sock`. |
|
||||
| Unix sockets, abstract | The abstract namespace belongs to the network namespace, so it's private too. That cuts off D-Bus and X11 sockets bound there. |
|
||||
| Other socket families | `RestrictAddressFamilies` allows `AF_UNIX`, plus `AF_INET` and `AF_INET6` for loopback. No `AF_NETLINK`, `AF_PACKET`, or `AF_VSOCK`; on a Linux host that runs VMs, `AF_VSOCK` reaches them. |
|
||||
| systemd and D-Bus | The system bus socket is in the hidden `/run`. Upstream's module keeps a user manager running for this user, so cron jobs can `systemd-run --user`. That would start processes outside the sandbox, so the user doesn't linger and `/run/user` is hidden. Hermes's cron jobs fail closed. |
|
||||
| Escaping the unit | Every process the unit forks stays in its cgroup, which `ProtectControlGroups` makes read-only, and stopping the unit stops them all. That covers the helpers Hermes detaches, which outlive a demo run: they can leave a process tree but not a cgroup. |
|
||||
| Files | `ProtectSystem=strict` makes the whole filesystem read-only. The exceptions are the state directory (`BindPaths`, `ReadWritePaths`), a private `/tmp`, and a minimal private `/dev` (`PrivateDevices`). |
|
||||
| Other processes | `ProtectProc=invisible` and `ProcSubset=pid` hide other users' processes in `/proc`. `PrivateIPC` gives SysV IPC and POSIX message queues their own namespace. Hermes's user can still signal or ptrace its own processes, and that's why the bridge, which also runs as Hermes's user, gets the same sandbox: taking it over gains nothing. |
|
||||
| Privilege | Upstream sets `NoNewPrivileges`, so setuid binaries don't raise privilege. On top of that: `CapabilityBoundingSet=""`, `RestrictSUIDSGID`, and `RestrictNamespaces`, which rules out making a user namespace to gain capabilities in. |
|
||||
| Kernel interfaces | `ProtectKernelTunables`, `ProtectKernelModules`, `ProtectKernelLogs`, `ProtectClock` and `ProtectHostname` block writes to sysctls, module loading, the kernel log, the clock and the hostname. `LockPersonality` and `SystemCallArchitectures=native` close the syscall-ABI tricks. |
|
||||
| IP networking | `PrivateNetwork`: only loopback, shared with the bridge alone, whose one listener forwards to `llm.sock`. `IPAddressDeny=any` with `IPAddressAllow=localhost` is a second check. |
|
||||
| Unix sockets, by path | These cross network namespaces, and accept `connect()` even on a read-only mount. `TemporaryFileSystem` empties `/run` (so `/var/run`) and `/var/lib`, `PrivateTmp` covers `/tmp`, and `ProtectHome` covers `/home`, `/root` and `/run/user`. `BindReadOnlyPaths` binds back the two sockets. |
|
||||
| Unix sockets, abstract | Private to the network namespace. |
|
||||
| Other socket families | `RestrictAddressFamilies`: `AF_UNIX`, and `AF_INET`/`AF_INET6` for loopback. No `AF_NETLINK`, `AF_PACKET` or `AF_VSOCK`. |
|
||||
| systemd, D-Bus | The system bus is in the hidden `/run`. No user manager: the user doesn't linger (so Hermes's cron jobs fail closed), and `/run/user` is hidden. |
|
||||
| Escaping the unit | Descendants stay in the unit's cgroup (read-only under `ProtectControlGroups`) and stop with it, detached or not. |
|
||||
| Files | `ProtectSystem=strict`: read-only, except the state directory, a private `/tmp`, and a minimal private `/dev`. |
|
||||
| Other processes | `ProtectProc=invisible`, `ProcSubset=pid`, `PrivateIPC`. Hermes's user can still ptrace its own processes, so the bridge, which runs as that user, gets the same sandbox. |
|
||||
| Privilege | `NoNewPrivileges`, an empty `CapabilityBoundingSet`, `RestrictSUIDSGID`, and `RestrictNamespaces` (no user namespaces). |
|
||||
| Kernel interfaces | `ProtectKernelTunables`, `ProtectKernelModules`, `ProtectKernelLogs`, `ProtectClock`, `ProtectHostname`, `LockPersonality`, `SystemCallArchitectures=native`. |
|
||||
|
||||
### The two sockets
|
||||
**`host.sock`** grants what its host serves. The host must serve only the guest's methods, bound to one agent. Arguments must be data (pet names, strings, message numbers), and references must stay in the host's pet store. The socket is mode 0600, owned by Hermes's user, so the connection designates the guest. Any process as that user counts as Hermes, and all of them are confined alike.
|
||||
|
||||
**`host.sock`** gives whatever its host serves there, so this part of the claim depends on the host.
|
||||
- The host must serve only the guest's methods, bound to one guest agent.
|
||||
- Arguments must be data: pet names, strings, message numbers.
|
||||
- Object references must stay in the host's pet store; the guest sees an object only by its interface name.
|
||||
**`llm.sock`** reaches [llm-proxy.py](llm-proxy.py), which runs as another user. It reads the key from its own systemd credential, which Hermes can't read. It forwards only `/v1/` paths, to one upstream host, and replaces any `Authorization` header the client sends.
|
||||
|
||||
[test/fake_host.py](test/fake_host.py) is that protocol, and the demo checks that Hermes can work with it. The socket is mode 0600 and owned by Hermes's user. So the connection itself designates the guest, and no secret has to cross. Any process running as Hermes's user counts as Hermes, which is correct: all of them are confined the same way.
|
||||
**On macOS** the VM runs the same unit, and adds a boundary that holds even if the VM's kernel is compromised. Root in the VM reaches no network interface. It reaches the two vsock ports vfkit relays, the host's `/nix/store` read-only, and the state image. The trusted base gains Apple's hypervisor and loses the VM's kernel.
|
||||
|
||||
**`llm.sock`** reaches [llm-proxy.py](llm-proxy.py), which runs as a separate dynamic user.
|
||||
- It reads the key from its own systemd credential, which Hermes can't read.
|
||||
- It forwards only paths under `/v1/`, only to the host part of one upstream URL.
|
||||
- It replaces any `Authorization` header the client sends.
|
||||
- An absolute-form request line, such as `GET http://elsewhere/`, doesn't start with `/v1`, so it gets a 404.
|
||||
**Not claimed:**
|
||||
- **Secrecy.** Hermes can read what its user can read, and pass it to the model provider or to its host.
|
||||
- **Denial of service.** No memory, task or CPU limits are set.
|
||||
- **Kernel bugs** on a Linux host, and covert channels.
|
||||
- **Sockets the sandbox doesn't hide**, such as under `/srv`. If the host listens on one that Hermes's user may connect to, add its directory to `TemporaryFileSystem`.
|
||||
|
||||
### On macOS
|
||||
|
||||
The VM runs the same unit, so everything above holds inside it. The VM adds a second boundary, which still holds if the VM's kernel is compromised. A process with root in the VM reaches:
|
||||
- no network interface;
|
||||
- the two vsock ports vfkit relays, to `hostDir/host.sock` and `hostDir/llm.sock`;
|
||||
- the host's `/nix/store`, read-only;
|
||||
- the state image;
|
||||
- the serial console, which only whoever runs the VM sees.
|
||||
|
||||
The trusted base for the claim grows by one, Apple's hypervisor, and loses the guest kernel.
|
||||
|
||||
### What this doesn't claim
|
||||
|
||||
- **Secrecy.** Hermes can read what its user can read: the store, `/etc`, world-readable files under `/var` outside `/var/lib`. Through `llm.sock` it can send any of that to the model provider. Through `host.sock` it can send it to its host, which is by design. The claim limits what Hermes can do, not what it can learn or tell those two parties.
|
||||
- **Denial of service.** No `MemoryMax`, `TasksMax`, or CPU quota is set. Hermes can use as much of the machine as it likes, flood the journal, or spend the API key's quota.
|
||||
- **Kernel bugs** on a Linux host, and covert or timing channels.
|
||||
- **Sockets elsewhere.** The claim assumes nothing on the host listens on a Unix socket outside `/run`, `/var/lib`, `/tmp` and `/home` that Hermes's user may connect to, for example under `/srv`, `/opt` or `/var/spool`. If one does, add its directory to `TemporaryFileSystem`.
|
||||
|
||||
### What has been checked, and what hasn't
|
||||
|
||||
- Checked: both platforms' configurations evaluate. The demo passes against unmodified Hermes on macOS, outside any sandbox.
|
||||
- Not checked: neither the Linux unit nor the VM has been started.
|
||||
- Not checked: whether vfkit refuses guest connections to vsock ports it wasn't told about.
|
||||
- Not checked: the host's guest socket and the proxy, except by reading the code.
|
||||
|
||||
On a running Linux host, enter the unit's namespaces and try to get out. `nsenter` enters the namespaces and mounts but not the seccomp filter or capability limits, so this checks the network and filesystem rows of the table:
|
||||
To probe a running Linux host, enter the unit's namespaces. `nsenter` doesn't apply the seccomp filter or the capability limits, so this covers the network and file rows:
|
||||
|
||||
```sh
|
||||
pid=$(systemctl show -p MainPID --value hermes-agent)
|
||||
sudo nsenter -t "$pid" -a -S "$(id -u hermes)" -G "$(id -g hermes)" sh -c '
|
||||
ls -A /run /run/hermes-guest /var/lib /home /tmp
|
||||
ip -brief link
|
||||
socat -T2 - TCP:1.1.1.1:443 </dev/null
|
||||
'
|
||||
sudo nsenter -t "$pid" -a -S "$(id -u hermes)" -G "$(id -g hermes)" sh -c \
|
||||
'ls -A /run /var/lib /home; ip -brief link; socat -T2 - TCP:1.1.1.1:443 </dev/null'
|
||||
systemd-analyze security hermes-agent hermes-llm-bridge
|
||||
```
|
||||
|
||||
`ls` should list only `hermes-guest` (with its two sockets) and `hermes`, and `ip` should show only `lo`. The `socat` connection should fail.
|
||||
|
||||
When you change the sandbox, update the table above in the same commit.
|
||||
Expect only `hermes-guest` in `/run`, only `hermes` in `/var/lib`, an empty `/home`, only `lo`, and a failed connection.
|
||||
Reference in new issue
Block a user