Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos/chrony: systemd service hardening #104944

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions nixos/modules/services/networking/ntp/chrony.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ with lib;
let
cfg = config.services.chrony;

runDir = "/var/run/chrony";
stateDir = "/var/lib/chrony";
driftFile = "${stateDir}/chrony.drift";
keyFile = "${stateDir}/chrony.keys";
Expand Down Expand Up @@ -116,9 +117,34 @@ in
{ Type = "simple";
ExecStart = "${pkgs.chrony}/bin/chronyd ${chronyFlags}";

ProtectHome = "yes";
ProtectSystem = "full";
KeyringMode = "private";
LockPersonality = true;
MemoryDenyWriteExecute = true;
NoNewPrivileges = true;
PrivateMounts = "yes";
PrivateTmp = "yes";
ProtectControlGroups = true;
ProtectHome = "yes";
ProtectHostname = true;
ProtectKernelModules = true;
ProtectKernelTunables = true;
ProtectSystem = "strict";
ReadWritePaths = [ runDir stateDir ];
RemoveIPC = true;
RestrictAddressFamilies = [ "AF_UNIX" "AF_INET" "AF_INET6" ];
RestrictNamespaces = true;
RestrictRealtime = true;
RestrictSUIDSGID = true;
SystemCallFilter = "@system-service @clock";
SystemCallArchitectures = "native";

# even though in the default configuration chrony does not access the rtc clock,
# it may be configured to so so either with the 'rtcfile' configuration option
# or using the '-s' flag. so we make sure rtc devices can still be used by it.
# at the same time there is no need for chrony to access any other device types.
DeviceAllow = "char-rtc";
DevicePolicy = "closed";

};

};
Expand Down