Compare commits

..

7 commits

View file

@ -30,6 +30,13 @@ self: {
config_dir = "${cfg.stateDir}/conf"; config_dir = "${cfg.stateDir}/conf";
cache_dir = cfg.cacheDir; cache_dir = cfg.cacheDir;
}); });
# Check if we need privileged port capability
portMatch = builtins.match ".*:([0-9]+)" cfg.listenAddress;
needsPrivilegedPort =
portMatch
!= null
&& builtins.fromJSON (builtins.head portMatch) < 1024;
in { in {
###### interface ###### interface
options = { options = {
@ -53,7 +60,6 @@ in {
metricsPort = mkOption { metricsPort = mkOption {
type = port; type = port;
default = 9100; default = 9100;
example = 9110;
description = "The port for the Prometheus metrics endpoint."; description = "The port for the Prometheus metrics endpoint.";
}; };
@ -67,13 +73,13 @@ in {
minDelay = mkOption { minDelay = mkOption {
type = int; type = int;
default = 1000; default = 1000;
description = "Minimum delay (in ms) between sending characters in tarpit mode."; description = "Minimum delay (in milliseconds) between sending characters in tarpit mode.";
}; };
maxDelay = mkOption { maxDelay = mkOption {
type = int; type = int;
default = 15000; default = 15000;
description = "Maximum delay (in ms) between sending characters in tarpit mode."; description = "Maximum delay (in milliseconds) between sending characters in tarpit mode.";
}; };
maxTarpitTime = mkOption { maxTarpitTime = mkOption {
@ -260,7 +266,7 @@ in {
# Process management # Process management
ExecStart = '' ExecStart = ''
${lib.getExe cfg.package} \ ${cfg.package}/bin/eris \
--config-file ${erisConfigFile} \ --config-file ${erisConfigFile} \
--log-level ${cfg.logLevel} --log-level ${cfg.logLevel}
''; '';
@ -276,29 +282,27 @@ in {
# Deny privilege escalation # Deny privilege escalation
NoNewPrivileges = true; NoNewPrivileges = true;
# FIXME: this breaks everything.
# Filesystem access control # Filesystem access control
# ProtectSystem = "strict"; # Mount /usr, /boot, /etc read-only ProtectSystem = "strict"; # Mount /usr, /boot, /etc read-only
# ProtectHome = true; # Make /home, /root inaccessible ProtectHome = true; # Make /home, /root inaccessible
#
# # Explicitly allow writes to state/cache/data dirs # Explicitly allow writes to state/cache/data dirs
# ReadWritePaths = [ ReadWritePaths = [
# "/var/lib/eris" "${cfg.stateDir}"
# "${cfg.stateDir}" "${cfg.cacheDir}"
# "${cfg.cacheDir}" "${cfg.dataDir}"
# "${cfg.dataDir}" ];
# ];
# # Allow reads from config file path
# # Allow reads from config file path ReadOnlyPaths = ["${erisConfigFile}"];
# ReadOnlyPaths = ["${erisConfigFile}"];
# # Explicitly deny access to sensitive paths
# # Explicitly deny access to sensitive paths InaccessiblePaths = [
# InaccessiblePaths = [ "/boot"
# "/boot" "/root"
# "/root" "/home"
# "/home" "/srv"
# "/srv" ];
# ];
PrivateTmp = true; # Use private /tmp and /var/tmp PrivateTmp = true; # Use private /tmp and /var/tmp
PrivateDevices = true; # Restrict device access (/dev) PrivateDevices = true; # Restrict device access (/dev)
@ -341,11 +345,14 @@ in {
preStart = let preStart = let
corporaDir = "${cfg.dataDir}/corpora"; corporaDir = "${cfg.dataDir}/corpora";
scriptsDir = "${cfg.dataDir}/scripts"; scriptsDir = "${cfg.dataDir}/scripts";
confDir = "${cfg.stateDir}/conf";
chownCmd = "${pkgs.coreutils}/bin/chown ${cfg.user}:${cfg.group}";
# Create commands to copy corpora files # Create commands to copy corpora files
copyCorporaCmds = copyCorporaCmds =
lib.mapAttrsToList (name: path: '' lib.mapAttrsToList (name: path: ''
cp -vf ${path} ${corporaDir}/${name} cp -vf ${path} ${corporaDir}/${name}
${chownCmd} ${corporaDir}/${name}
'') '')
cfg.corpora; cfg.corpora;
@ -353,9 +360,13 @@ in {
copyLuaScriptCmds = copyLuaScriptCmds =
lib.mapAttrsToList (name: path: '' lib.mapAttrsToList (name: path: ''
cp -vf ${path} ${scriptsDir}/${name} cp -vf ${path} ${scriptsDir}/${name}
${chownCmd} ${scriptsDir}/${name}
'') '')
cfg.luaScripts; cfg.luaScripts;
in '' in ''
# Create subdirectories only - base directories are created by systemd
mkdir -p ${confDir} ${corporaDir} ${scriptsDir}
# Copy declarative files # Copy declarative files
${lib.optionalString (cfg.corpora != {}) (toString copyCorporaCmds)} ${lib.optionalString (cfg.corpora != {}) (toString copyCorporaCmds)}
${lib.optionalString (cfg.luaScripts != {}) (toString copyLuaScriptCmds)} ${lib.optionalString (cfg.luaScripts != {}) (toString copyLuaScriptCmds)}