WIP: feat: Hermes confined to act only as an Endo guest #1
+45
-30
@@ -20,6 +20,43 @@ let
|
|||||||
cfg = config.services.hermes-guest;
|
cfg = config.services.hermes-guest;
|
||||||
hermes = config.services.hermes-agent;
|
hermes = config.services.hermes-agent;
|
||||||
socketDir = "/run/hermes-guest";
|
socketDir = "/run/hermes-guest";
|
||||||
|
|
||||||
|
# The sandbox every process running as Hermes's user gets. See
|
||||||
|
# CONTRIBUTING.md#confinement for why it confines.
|
||||||
|
sandbox = {
|
||||||
|
PrivateNetwork = true;
|
||||||
|
IPAddressDeny = "any";
|
||||||
|
IPAddressAllow = "localhost";
|
||||||
|
RestrictAddressFamilies = [
|
||||||
|
"AF_UNIX"
|
||||||
|
"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;
|
||||||
|
PrivateIPC = true;
|
||||||
|
ProtectKernelTunables = true;
|
||||||
|
ProtectKernelModules = true;
|
||||||
|
ProtectKernelLogs = true;
|
||||||
|
ProtectControlGroups = true;
|
||||||
|
ProtectClock = true;
|
||||||
|
ProtectHostname = true;
|
||||||
|
RestrictNamespaces = true;
|
||||||
|
RestrictSUIDSGID = true;
|
||||||
|
LockPersonality = true;
|
||||||
|
CapabilityBoundingSet = "";
|
||||||
|
SystemCallArchitectures = "native";
|
||||||
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.services.hermes-guest = {
|
options.services.hermes-guest = {
|
||||||
@@ -79,60 +116,38 @@ in
|
|||||||
systemd.services.hermes-agent = {
|
systemd.services.hermes-agent = {
|
||||||
after = [ "hermes-llm-bridge.service" ];
|
after = [ "hermes-llm-bridge.service" ];
|
||||||
requires = [ "hermes-llm-bridge.service" ];
|
requires = [ "hermes-llm-bridge.service" ];
|
||||||
serviceConfig = {
|
serviceConfig = sandbox // {
|
||||||
PrivateNetwork = true;
|
|
||||||
IPAddressDeny = "any";
|
|
||||||
IPAddressAllow = "localhost";
|
|
||||||
RestrictAddressFamilies = [
|
|
||||||
"AF_UNIX"
|
|
||||||
"AF_INET"
|
|
||||||
"AF_INET6"
|
|
||||||
];
|
|
||||||
# Path-named Unix sockets ignore network namespaces: hide them all,
|
|
||||||
# then put back the two this service may use. (/var/run is a
|
|
||||||
# symlink to /run, so it's covered too.)
|
|
||||||
TemporaryFileSystem = [ "/run" ];
|
|
||||||
BindReadOnlyPaths = [
|
BindReadOnlyPaths = [
|
||||||
cfg.hostSocket
|
cfg.hostSocket
|
||||||
cfg.llmSocket
|
cfg.llmSocket
|
||||||
];
|
];
|
||||||
|
# the state directory, back inside the empty /var/lib
|
||||||
|
BindPaths = [ hermes.stateDir ];
|
||||||
ProtectHome = lib.mkForce true;
|
ProtectHome = lib.mkForce true;
|
||||||
PrivateDevices = true;
|
|
||||||
PrivateIPC = true;
|
|
||||||
ProtectKernelTunables = true;
|
|
||||||
ProtectKernelModules = true;
|
|
||||||
ProtectKernelLogs = true;
|
|
||||||
ProtectControlGroups = true;
|
|
||||||
ProtectClock = true;
|
|
||||||
ProtectHostname = true;
|
|
||||||
RestrictNamespaces = true;
|
|
||||||
RestrictSUIDSGID = true;
|
|
||||||
LockPersonality = true;
|
|
||||||
CapabilityBoundingSet = "";
|
|
||||||
SystemCallArchitectures = "native";
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
# Hermes's client wants a TCP base_url. This joins Hermes's network
|
# Hermes's client wants a TCP base_url. This joins Hermes's network
|
||||||
# namespace and forwards its loopback port to llmSocket.
|
# namespace and forwards its loopback port to llmSocket. It runs as
|
||||||
|
# Hermes's user, so it gets the same sandbox: taking it over (ptrace,
|
||||||
|
# same uid) must gain nothing.
|
||||||
systemd.services.hermes-llm-bridge = {
|
systemd.services.hermes-llm-bridge = {
|
||||||
description = "Hermes's loopback port to the inference proxy";
|
description = "Hermes's loopback port to the inference proxy";
|
||||||
unitConfig.JoinsNamespaceOf = "hermes-agent.service";
|
unitConfig.JoinsNamespaceOf = "hermes-agent.service";
|
||||||
partOf = [ "hermes-agent.service" ];
|
partOf = [ "hermes-agent.service" ];
|
||||||
serviceConfig = {
|
serviceConfig = sandbox // {
|
||||||
User = hermes.user;
|
User = hermes.user;
|
||||||
Group = hermes.group;
|
Group = hermes.group;
|
||||||
PrivateNetwork = true;
|
|
||||||
ExecStart = lib.escapeShellArgs [
|
ExecStart = lib.escapeShellArgs [
|
||||||
"${pkgs.socat}/bin/socat"
|
"${pkgs.socat}/bin/socat"
|
||||||
"TCP-LISTEN:${toString cfg.llmPort},bind=127.0.0.1,fork,reuseaddr"
|
"TCP-LISTEN:${toString cfg.llmPort},bind=127.0.0.1,fork,reuseaddr"
|
||||||
"UNIX-CONNECT:${cfg.llmSocket}"
|
"UNIX-CONNECT:${cfg.llmSocket}"
|
||||||
];
|
];
|
||||||
|
BindReadOnlyPaths = [ cfg.llmSocket ];
|
||||||
ProtectSystem = "strict";
|
ProtectSystem = "strict";
|
||||||
ProtectHome = true;
|
ProtectHome = true;
|
||||||
PrivateTmp = true;
|
PrivateTmp = true;
|
||||||
NoNewPrivileges = true;
|
NoNewPrivileges = true;
|
||||||
CapabilityBoundingSet = "";
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user