Skip to content

Commit e5d70cf

Browse files
authored
nixos/matter-server: fix permission denied error in 7.0.1 (#384651)
2 parents 9773378 + b4f4971 commit e5d70cf

File tree

2 files changed

+34
-24
lines changed

2 files changed

+34
-24
lines changed

nixos/modules/services/home-automation/matter-server.nix

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ in
5858
serviceConfig = {
5959
ExecStart = (
6060
lib.concatStringsSep " " [
61+
# `python-matter-server` writes to /data even when a storage-path
62+
# is specified. This symlinks /data at the systemd-managed
63+
# /var/lib/matter-server, so all files get dropped into the state
64+
# directory.
65+
"${pkgs.bash}/bin/sh"
66+
"-c"
67+
"'"
68+
"${pkgs.coreutils}/bin/ln -s %S/matter-server/ %t/matter-server/root/data"
69+
"&&"
6170
"${cfg.package}/bin/matter-server"
6271
"--port"
6372
(toString cfg.port)
@@ -68,22 +77,21 @@ in
6877
"--log-level"
6978
"${cfg.logLevel}"
7079
"${lib.escapeShellArgs cfg.extraArgs}"
80+
"'"
7181
]
7282
);
7383
# Start with a clean root filesystem, and allowlist what the container
7484
# is permitted to access.
75-
TemporaryFileSystem = "/";
85+
# See https://discourse.nixos.org/t/hardening-systemd-services/17147/14.
86+
RuntimeDirectory = [ "matter-server/root" ];
87+
RootDirectory = "%t/matter-server/root";
88+
7689
# Allowlist /nix/store (to allow the binary to find its dependencies)
7790
# and dbus.
78-
ReadOnlyPaths = "/nix/store /run/dbus";
91+
BindReadOnlyPaths = "/nix/store /run/dbus";
7992
# Let systemd manage `/var/lib/matter-server` for us inside the
8093
# ephemeral TemporaryFileSystem.
8194
StateDirectory = storageDir;
82-
# `python-matter-server` writes to /data even when a storage-path is
83-
# specified. This bind-mount points /data at the systemd-managed
84-
# /var/lib/matter-server, so all files get dropped into the state
85-
# directory.
86-
BindPaths = "${storagePath}:/data";
8795

8896
# Hardening bits
8997
AmbientCapabilities = "";

nixos/tests/matter-server.nix

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import ./make-test-python.nix (
88
{
99
name = "matter-server";
1010
meta.maintainers = with lib.maintainers; [ leonm1 ];
11+
meta.timeout = 120; # Timeout after two minutes
1112

1213
nodes = {
1314
machine =
@@ -22,29 +23,30 @@ import ./make-test-python.nix (
2223

2324
testScript = # python
2425
''
25-
start_all()
26+
@polling_condition
27+
def matter_server_running():
28+
machine.succeed("systemctl status matter-server")
2629
27-
machine.wait_for_unit("matter-server.service")
28-
machine.wait_for_open_port(1234)
30+
start_all()
2931
30-
with subtest("Check websocket server initialized"):
31-
output = machine.succeed("echo \"\" | ${pkgs.websocat}/bin/websocat ws://localhost:1234/ws")
32-
machine.log(output)
32+
machine.wait_for_unit("matter-server.service", timeout=20)
33+
machine.wait_for_open_port(1234, timeout=20)
3334
34-
assert '"sdk_version": "${chipVersion}"' in output, (
35-
'CHIP version \"${chipVersion}\" not present in websocket message'
36-
)
35+
with matter_server_running: # type: ignore[union-attr]
36+
with subtest("Check websocket server initialized"):
37+
output = machine.succeed("echo \"\" | ${pkgs.websocat}/bin/websocat ws://localhost:1234/ws")
38+
machine.log(output)
3739
38-
assert '"fabric_id": 1' in output, (
39-
"fabric_id not propagated to server"
40-
)
40+
assert '"fabric_id": 1' in output, (
41+
"fabric_id not propagated to server"
42+
)
4143
42-
with subtest("Check storage directory is created"):
43-
machine.succeed("ls /var/lib/matter-server/chip.json")
44+
with subtest("Check storage directory is created"):
45+
machine.succeed("ls /var/lib/matter-server/chip.json")
4446
45-
with subtest("Check systemd hardening"):
46-
_, output = machine.execute("systemd-analyze security matter-server.service | grep -v '✓'")
47-
machine.log(output)
47+
with subtest("Check systemd hardening"):
48+
_, output = machine.execute("systemd-analyze security matter-server.service | grep -v '✓'")
49+
machine.log(output)
4850
'';
4951
}
5052
)

0 commit comments

Comments
 (0)