-
-
Notifications
You must be signed in to change notification settings - Fork 14.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/postgresql: enable sandbox mode #113100
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 |
---|---|---|
|
@@ -375,9 +375,6 @@ in | |
|
||
serviceConfig = mkMerge [ | ||
{ ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID"; | ||
User = "postgres"; | ||
Group = "postgres"; | ||
RuntimeDirectory = "postgresql"; | ||
Type = if versionAtLeast cfg.package.version "9.6" | ||
then "notify" | ||
else "simple"; | ||
|
@@ -392,8 +389,41 @@ in | |
TimeoutSec = 120; | ||
|
||
ExecStart = "${postgresql}/bin/postgres"; | ||
|
||
# User and group | ||
User = "postgres"; | ||
Group = "postgres"; | ||
# Runtime directory and mode | ||
RuntimeDirectory = "postgresql"; | ||
RuntimeDirectoryMode = "0755"; | ||
# Capabilities | ||
CapabilityBoundingSet = ""; | ||
# Security | ||
NoNewPrivileges = true; | ||
# Sandboxing | ||
ProtectSystem = "strict"; | ||
ProtectHome = true; | ||
PrivateTmp = false; # Fixme, nixos/tests/postgresql-wal-receiver uses the /tmp directory for test. | ||
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. If that's the case, we should fix the test and not the other way around. One of the reasons why we've switched 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. Now there is no idea how to fix the test. |
||
PrivateDevices = true; | ||
ProtectHostname = true; | ||
ProtectKernelTunables = true; | ||
ProtectKernelModules = true; | ||
ProtectControlGroups = true; | ||
RestrictAddressFamilies = [ "AF_UNIX" "AF_INET" "AF_INET6" ]; | ||
LockPersonality = true; | ||
MemoryDenyWriteExecute = true; | ||
RestrictRealtime = true; | ||
RestrictSUIDSGID = true; | ||
PrivateMounts = true; | ||
# System Call Filtering | ||
SystemCallArchitectures = "native"; | ||
} | ||
(mkIf (cfg.dataDir != "/var/lib/postgresql/${cfg.package.psqlSchema}") { | ||
# Access write directories | ||
ReadWritePaths = [ cfg.dataDir ]; | ||
}) | ||
(mkIf (cfg.dataDir == "/var/lib/postgresql/${cfg.package.psqlSchema}") { | ||
# State directory and mode | ||
StateDirectory = "postgresql postgresql/${cfg.package.psqlSchema}"; | ||
StateDirectoryMode = if groupAccessAvailable then "0750" else "0700"; | ||
}) | ||
|
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.
Did you try the
systemd.services.*.confinement
options instead? I'm asking because one of the main targets of that module was PostgreSQL and it's also more strict thatProtectSystem
because it only contains runtime closure necessary for running PostgreSQL.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.
Have not tried. Don't know how to use
systemd.services.*.confinement
.