nixos/matter-server: fix permission denied error in 7.0.1 (#384651)

Changed files
+34 -24
nixos
modules
services
home-automation
tests
+15 -7
nixos/modules/services/home-automation/matter-server.nix
···
serviceConfig = {
ExecStart = (
lib.concatStringsSep " " [
+
# `python-matter-server` writes to /data even when a storage-path
+
# is specified. This symlinks /data at the systemd-managed
+
# /var/lib/matter-server, so all files get dropped into the state
+
# directory.
+
"${pkgs.bash}/bin/sh"
+
"-c"
+
"'"
+
"${pkgs.coreutils}/bin/ln -s %S/matter-server/ %t/matter-server/root/data"
+
"&&"
"${cfg.package}/bin/matter-server"
"--port"
(toString cfg.port)
···
"--log-level"
"${cfg.logLevel}"
"${lib.escapeShellArgs cfg.extraArgs}"
+
"'"
]
);
# Start with a clean root filesystem, and allowlist what the container
# is permitted to access.
-
TemporaryFileSystem = "/";
+
# See https://discourse.nixos.org/t/hardening-systemd-services/17147/14.
+
RuntimeDirectory = [ "matter-server/root" ];
+
RootDirectory = "%t/matter-server/root";
+
# Allowlist /nix/store (to allow the binary to find its dependencies)
# and dbus.
-
ReadOnlyPaths = "/nix/store /run/dbus";
+
BindReadOnlyPaths = "/nix/store /run/dbus";
# Let systemd manage `/var/lib/matter-server` for us inside the
# ephemeral TemporaryFileSystem.
StateDirectory = storageDir;
-
# `python-matter-server` writes to /data even when a storage-path is
-
# specified. This bind-mount points /data at the systemd-managed
-
# /var/lib/matter-server, so all files get dropped into the state
-
# directory.
-
BindPaths = "${storagePath}:/data";
# Hardening bits
AmbientCapabilities = "";
+19 -17
nixos/tests/matter-server.nix
···
{
name = "matter-server";
meta.maintainers = with lib.maintainers; [ leonm1 ];
+
meta.timeout = 120; # Timeout after two minutes
nodes = {
machine =
···
testScript = # python
''
+
@polling_condition
+
def matter_server_running():
+
machine.succeed("systemctl status matter-server")
+
start_all()
-
machine.wait_for_unit("matter-server.service")
-
machine.wait_for_open_port(1234)
+
machine.wait_for_unit("matter-server.service", timeout=20)
+
machine.wait_for_open_port(1234, timeout=20)
-
with subtest("Check websocket server initialized"):
-
output = machine.succeed("echo \"\" | ${pkgs.websocat}/bin/websocat ws://localhost:1234/ws")
-
machine.log(output)
-
-
assert '"sdk_version": "${chipVersion}"' in output, (
-
'CHIP version \"${chipVersion}\" not present in websocket message'
-
)
+
with matter_server_running: # type: ignore[union-attr]
+
with subtest("Check websocket server initialized"):
+
output = machine.succeed("echo \"\" | ${pkgs.websocat}/bin/websocat ws://localhost:1234/ws")
+
machine.log(output)
-
assert '"fabric_id": 1' in output, (
-
"fabric_id not propagated to server"
-
)
+
assert '"fabric_id": 1' in output, (
+
"fabric_id not propagated to server"
+
)
-
with subtest("Check storage directory is created"):
-
machine.succeed("ls /var/lib/matter-server/chip.json")
+
with subtest("Check storage directory is created"):
+
machine.succeed("ls /var/lib/matter-server/chip.json")
-
with subtest("Check systemd hardening"):
-
_, output = machine.execute("systemd-analyze security matter-server.service | grep -v '✓'")
-
machine.log(output)
+
with subtest("Check systemd hardening"):
+
_, output = machine.execute("systemd-analyze security matter-server.service | grep -v '✓'")
+
machine.log(output)
'';
}
)