Skip to content

Commit 1289c91

Browse files
nixos/echoip: improve systemd hardening (#387466)
2 parents 86f44b0 + eccf638 commit 1289c91

File tree

3 files changed

+37
-31
lines changed

3 files changed

+37
-31
lines changed

nixos/modules/services/web-apps/echoip.nix

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,12 @@ in
7575
);
7676

7777
# Hardening
78+
AmbientCapabilities = "";
7879
CapabilityBoundingSet = [ "" ];
79-
DeviceAllow = [ "" ];
80+
DevicePolicy = "closed";
8081
LockPersonality = true;
82+
MemoryDenyWriteExecute = true;
83+
NoNewPrivileges = true;
8184
PrivateDevices = true;
8285
PrivateTmp = true;
8386
PrivateUsers = true;
@@ -91,15 +94,19 @@ in
9194
ProtectKernelTunables = true;
9295
ProtectProc = "invisible";
9396
ProtectSystem = "strict";
94-
RestrictAddressFamilies = [
95-
"AF_INET"
96-
"AF_INET6"
97-
"AF_UNIX"
98-
];
97+
RemoveIPC = true;
98+
RestrictAddressFamilies = [ "AF_INET AF_INET6 AF_UNIX" ];
9999
RestrictNamespaces = true;
100100
RestrictRealtime = true;
101101
RestrictSUIDSGID = true;
102102
SystemCallArchitectures = "native";
103+
SystemCallFilter = [
104+
"@system-service"
105+
"~@privileged"
106+
"~@resources"
107+
"setrlimit"
108+
];
109+
UMask = "0077";
103110
};
104111
};
105112

nixos/tests/all-tests.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ in {
353353
early-mount-options = handleTest ./early-mount-options.nix {};
354354
ec2-config = (handleTestOn ["x86_64-linux"] ./ec2.nix {}).boot-ec2-config or {};
355355
ec2-nixops = (handleTestOn ["x86_64-linux"] ./ec2.nix {}).boot-ec2-nixops or {};
356-
echoip = handleTest ./echoip.nix {};
356+
echoip = runTest ./echoip.nix;
357357
ecryptfs = handleTest ./ecryptfs.nix {};
358358
fscrypt = handleTest ./fscrypt.nix {};
359359
fastnetmon-advanced = runTest ./fastnetmon-advanced.nix;

nixos/tests/echoip.nix

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
1-
import ./make-test-python.nix (
2-
{ lib, ... }:
3-
{
4-
name = "echoip";
5-
meta.maintainers = with lib.maintainers; [ defelo ];
1+
{ lib, ... }:
62

7-
nodes.machine = {
8-
services.echoip = {
9-
enable = true;
10-
virtualHost = "echoip.local";
11-
};
3+
{
4+
name = "echoip";
5+
meta.maintainers = with lib.maintainers; [ defelo ];
126

13-
networking.hosts = {
14-
"127.0.0.1" = [ "echoip.local" ];
15-
"::1" = [ "echoip.local" ];
16-
};
7+
nodes.machine = {
8+
services.echoip = {
9+
enable = true;
10+
virtualHost = "echoip.local";
1711
};
1812

19-
testScript = ''
20-
machine.wait_for_unit("echoip.service")
21-
machine.wait_for_open_port(8080)
13+
networking.hosts = {
14+
"127.0.0.1" = [ "echoip.local" ];
15+
"::1" = [ "echoip.local" ];
16+
};
17+
};
18+
19+
testScript = ''
20+
machine.wait_for_unit("echoip.service")
21+
machine.wait_for_open_port(8080)
2222
23-
resp = machine.succeed("curl -4 http://echoip.local/ip")
24-
assert resp.strip() == "127.0.0.1"
25-
resp = machine.succeed("curl -6 http://echoip.local/ip")
26-
assert resp.strip() == "::1"
27-
'';
28-
}
29-
)
23+
resp = machine.succeed("curl -4 http://echoip.local/ip")
24+
assert resp.strip() == "127.0.0.1"
25+
resp = machine.succeed("curl -6 http://echoip.local/ip")
26+
assert resp.strip() == "::1"
27+
'';
28+
}

0 commit comments

Comments
 (0)