-
-
Notifications
You must be signed in to change notification settings - Fork 13.6k
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/nginx: Sandbox the service using systemd #60646
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,7 +45,7 @@ let | |
'')); | ||
|
||
configFile = pkgs.writers.writeNginxConfig "nginx.conf" '' | ||
user ${cfg.user} ${cfg.group}; | ||
pid /run/nginx/nginx.pid; | ||
error_log ${cfg.logError}; | ||
daemon off; | ||
|
||
|
@@ -361,12 +361,7 @@ in | |
|
||
preStart = mkOption { | ||
type = types.lines; | ||
default = '' | ||
test -d ${cfg.stateDir}/logs || mkdir -m 750 -p ${cfg.stateDir}/logs | ||
test `stat -c %a ${cfg.stateDir}` = "750" || chmod 750 ${cfg.stateDir} | ||
test `stat -c %a ${cfg.stateDir}/logs` = "750" || chmod 750 ${cfg.stateDir}/logs | ||
chown -R ${cfg.user}:${cfg.group} ${cfg.stateDir} | ||
''; | ||
default = ""; | ||
description = " | ||
Shell commands executed before the service's nginx is started. | ||
"; | ||
|
@@ -442,10 +437,10 @@ in | |
"; | ||
}; | ||
|
||
stateDir = mkOption { | ||
default = "/var/spool/nginx"; | ||
stateDirName = mkOption { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is hard coding the state directory to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Systemd only gives me the possibility to name a directory under /usr/lib as state directory. Absolute paths and .. don't work. Using another directory means I'd have to take care about mkdir, chown and chmod myself. This way, systemd does all that for me. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes I'm all for locking the state directory down under There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is possible to leave use custom folder? |
||
default = "nginx"; | ||
description = " | ||
Directory holding all state for nginx to run. | ||
Name of the directory under /var/lib holding nginx's state. | ||
"; | ||
}; | ||
|
||
|
@@ -640,14 +635,38 @@ in | |
preStart = | ||
'' | ||
${cfg.preStart} | ||
${cfg.package}/bin/nginx -c ${configFile} -p ${cfg.stateDir} -t | ||
${cfg.package}/bin/nginx -c '${configFile}' -p '/var/lib/${cfg.stateDirName}' -t | ||
''; | ||
serviceConfig = { | ||
ExecStart = "${cfg.package}/bin/nginx -c ${configFile} -p ${cfg.stateDir}"; | ||
ExecStart = "${cfg.package}/bin/nginx -c '${configFile}' -p '/var/lib/${cfg.stateDirName}'"; | ||
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID"; | ||
Restart = "always"; | ||
RestartSec = "10s"; | ||
StartLimitInterval = "1min"; | ||
# User and group | ||
User = cfg.user; | ||
Group = cfg.group; | ||
# Filesystem access | ||
ProtectSystem = "strict"; | ||
dasJ marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will break existing cache setups, including mine. I keep my cache in a folder under There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I usually use socket files in |
||
ProtectHome = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What impact will this have on things like mod_userdir? Will this break any |
||
PrivateTmp = true; | ||
PrivateDevices = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this will break my configuration which logs to journald using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this still work with |
||
ProtectKernelTunables = true; | ||
ProtectKernelModules = true; | ||
ProtectControlGroups = true; | ||
StateDirectory = [ "${cfg.stateDirName} ${cfg.stateDirName}/logs" ]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be a list with two elements, rather than a single string with a space? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We just pass that through to systemd, and systemd splits that with spaces. |
||
StateDirectoryMode = 750; | ||
RuntimeDirectory = "nginx"; | ||
RuntimeDirectoryMode = 750; | ||
# Capabilities | ||
CapabilityBoundingSet = [ "CAP_NET_BIND_SERVICE" ]; | ||
AmbientCapabilities = [ "CAP_NET_BIND_SERVICE" ]; | ||
NoNewPrivileges = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technically redundant, because |
||
# Misc. | ||
LockPersonality = true; | ||
RestrictRealtime = true; | ||
PrivateMounts = true; | ||
MemoryDenyWriteExecute = true; | ||
}; | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is the stateDir configurable but the runtimeDir not?