feat(sandbox): an empty root, by NixOS confinement
The filesystem was the one part of the sandbox that started from the host's view and hid places from it (/run, /var/lib, /tmp, /home), so the argument had to assume no sockets elsewhere. Both units now start from an empty root: their closure (fullUnit, so PATH's packages too), /bin/sh, the state directory and the two sockets, and nothing else. socat is added to Hermes's closure by hand, since only config.yaml names it. CONTRIBUTING's table now has one row for files and sockets by path, and the "sockets the sandbox doesn't hide" caveat is gone. Generated-by: Claude Opus 5.5
This commit is contained in:
1 parent
6d48662c94
commit
d58b77aa89
2 files changed
+28
-25
No files matched your search
+16
-14
@@ -8,8 +8,8 @@
|
||||
# lookup, ...) as an MCP server, bound to one guest agent
|
||||
# llmSocket model inference, through a proxy that holds the API key
|
||||
#
|
||||
# The service has no network of its own (PrivateNetwork), and sees no
|
||||
# other Unix sockets on the machine.
|
||||
# The service has no network of its own (PrivateNetwork), and its root
|
||||
# is empty except for its closure and those two sockets (confinement).
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
@@ -21,8 +21,17 @@ let
|
||||
hermes = config.services.hermes-agent;
|
||||
socketDir = "/run/hermes-guest";
|
||||
|
||||
# The sandbox every process running as Hermes's user gets. See
|
||||
# CONTRIBUTING.md#confinement for why it confines.
|
||||
# The sandbox every process running as Hermes's user gets, beside
|
||||
# `confinement` (below): an empty root, plus the unit's closure and the
|
||||
# binds each unit lists. See CONTRIBUTING.md#confinement for why it
|
||||
# confines.
|
||||
confine = extra: {
|
||||
enable = true;
|
||||
# the closure of everything the unit mentions, so PATH's packages too:
|
||||
# Hermes's shell tool runs bash, coreutils, git
|
||||
fullUnit = true;
|
||||
packages = extra;
|
||||
};
|
||||
sandbox = {
|
||||
PrivateNetwork = true;
|
||||
IPAddressDeny = "any";
|
||||
@@ -32,15 +41,6 @@ let
|
||||
"AF_INET"
|
||||
"AF_INET6"
|
||||
];
|
||||
# Path-named Unix sockets ignore network namespaces, and a socket on a
|
||||
# read-only mount still accepts connect(): hide the places sockets
|
||||
# live, then bind back what each unit may use. (/var/run is a symlink
|
||||
# to /run, so it's covered too; PrivateTmp and ProtectHome cover /tmp
|
||||
# and /home.)
|
||||
TemporaryFileSystem = [
|
||||
"/run"
|
||||
"/var/lib"
|
||||
];
|
||||
ProtectProc = "invisible";
|
||||
ProcSubset = "pid";
|
||||
PrivateDevices = true;
|
||||
@@ -116,12 +116,13 @@ in
|
||||
systemd.services.hermes-agent = {
|
||||
after = [ "hermes-llm-bridge.service" ];
|
||||
requires = [ "hermes-llm-bridge.service" ];
|
||||
# socat: config.yaml's MCP command, which the unit itself doesn't name
|
||||
confinement = confine [ pkgs.socat ];
|
||||
serviceConfig = sandbox // {
|
||||
BindReadOnlyPaths = [
|
||||
cfg.hostSocket
|
||||
cfg.llmSocket
|
||||
];
|
||||
# the state directory, back inside the empty /var/lib
|
||||
BindPaths = [ hermes.stateDir ];
|
||||
ProtectHome = lib.mkForce true;
|
||||
};
|
||||
@@ -135,6 +136,7 @@ in
|
||||
description = "Hermes's loopback port to the inference proxy";
|
||||
unitConfig.JoinsNamespaceOf = "hermes-agent.service";
|
||||
partOf = [ "hermes-agent.service" ];
|
||||
confinement = confine [ ];
|
||||
serviceConfig = sandbox // {
|
||||
User = hermes.user;
|
||||
Group = hermes.group;
|
||||
|
||||
Reference in new issue
Block a user