nixos/echoip: improve systemd hardening (#387466)

Sandro 1289c914 86f44b00

Changed files
+37 -31
nixos
modules
services
web-apps
tests
+13 -6
nixos/modules/services/web-apps/echoip.nix
···
);
# Hardening
+
AmbientCapabilities = "";
CapabilityBoundingSet = [ "" ];
-
DeviceAllow = [ "" ];
+
DevicePolicy = "closed";
LockPersonality = true;
+
MemoryDenyWriteExecute = true;
+
NoNewPrivileges = true;
PrivateDevices = true;
PrivateTmp = true;
PrivateUsers = true;
···
ProtectKernelTunables = true;
ProtectProc = "invisible";
ProtectSystem = "strict";
-
RestrictAddressFamilies = [
-
"AF_INET"
-
"AF_INET6"
-
"AF_UNIX"
-
];
+
RemoveIPC = true;
+
RestrictAddressFamilies = [ "AF_INET AF_INET6 AF_UNIX" ];
RestrictNamespaces = true;
RestrictRealtime = true;
RestrictSUIDSGID = true;
SystemCallArchitectures = "native";
+
SystemCallFilter = [
+
"@system-service"
+
"~@privileged"
+
"~@resources"
+
"setrlimit"
+
];
+
UMask = "0077";
};
};
+1 -1
nixos/tests/all-tests.nix
···
early-mount-options = handleTest ./early-mount-options.nix {};
ec2-config = (handleTestOn ["x86_64-linux"] ./ec2.nix {}).boot-ec2-config or {};
ec2-nixops = (handleTestOn ["x86_64-linux"] ./ec2.nix {}).boot-ec2-nixops or {};
-
echoip = handleTest ./echoip.nix {};
+
echoip = runTest ./echoip.nix;
ecryptfs = handleTest ./ecryptfs.nix {};
fscrypt = handleTest ./fscrypt.nix {};
fastnetmon-advanced = runTest ./fastnetmon-advanced.nix;
+23 -24
nixos/tests/echoip.nix
···
-
import ./make-test-python.nix (
-
{ lib, ... }:
-
{
-
name = "echoip";
-
meta.maintainers = with lib.maintainers; [ defelo ];
+
{ lib, ... }:
-
nodes.machine = {
-
services.echoip = {
-
enable = true;
-
virtualHost = "echoip.local";
-
};
+
{
+
name = "echoip";
+
meta.maintainers = with lib.maintainers; [ defelo ];
-
networking.hosts = {
-
"127.0.0.1" = [ "echoip.local" ];
-
"::1" = [ "echoip.local" ];
-
};
+
nodes.machine = {
+
services.echoip = {
+
enable = true;
+
virtualHost = "echoip.local";
+
};
+
+
networking.hosts = {
+
"127.0.0.1" = [ "echoip.local" ];
+
"::1" = [ "echoip.local" ];
};
+
};
-
testScript = ''
-
machine.wait_for_unit("echoip.service")
-
machine.wait_for_open_port(8080)
+
testScript = ''
+
machine.wait_for_unit("echoip.service")
+
machine.wait_for_open_port(8080)
-
resp = machine.succeed("curl -4 http://echoip.local/ip")
-
assert resp.strip() == "127.0.0.1"
-
resp = machine.succeed("curl -6 http://echoip.local/ip")
-
assert resp.strip() == "::1"
-
'';
-
}
-
)
+
resp = machine.succeed("curl -4 http://echoip.local/ip")
+
assert resp.strip() == "127.0.0.1"
+
resp = machine.succeed("curl -6 http://echoip.local/ip")
+
assert resp.strip() == "::1"
+
'';
+
}