-
-
Notifications
You must be signed in to change notification settings - Fork 14.1k
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: change option enableTCPIP
to actually mean TCP/IP.
#353707
base: master
Are you sure you want to change the base?
Changes from all commits
aa8d671
eb007a3
b3dbad3
2b3a2f4
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 | ||||
---|---|---|---|---|---|---|
|
@@ -361,12 +361,25 @@ in | |||||
}; | ||||||
|
||||||
enableTCPIP = mkOption { | ||||||
type = types.bool; | ||||||
default = false; | ||||||
type = types.nullOr types.bool; | ||||||
default = null; | ||||||
description = '' | ||||||
Whether PostgreSQL should listen on all network interfaces. | ||||||
If disabled, the database can only be accessed via its Unix | ||||||
domain socket or via TCP connections to localhost. | ||||||
Whether PostgreSQL should listen on network interfaces. | ||||||
If 'false', the database can only be accessed via its Unix | ||||||
domain socket. | ||||||
A value of 'null' defaults to 'true'. | ||||||
''; | ||||||
}; | ||||||
|
||||||
listenAddresses = mkOption { | ||||||
type = types.str; | ||||||
default = "localhost"; | ||||||
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 that ipv6 localhost ::1 and 127.0.0.1 on ipv4 only systems? 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. According to the PostgreSQL documentation:
|
||||||
description = '' | ||||||
The TCP/IP address(es) on which the server is to listen for connections from client applications. | ||||||
The value takes the form of a comma-separated list of host names and/or numeric IP addresses. | ||||||
The special entry `*` corresponds to all available IP interfaces. | ||||||
|
||||||
See the PostgreSQL documentation on [listen_address](https://www.postgresql.org/docs/current/runtime-config-connection.html#GUC-LISTEN-ADDRESSES). | ||||||
''; | ||||||
}; | ||||||
|
||||||
|
@@ -472,12 +485,16 @@ in | |||||
''; | ||||||
}) cfg.ensureUsers; | ||||||
|
||||||
warnings = lib.optional (cfg.enableTCPIP == true) '' | ||||||
Behaviour of `services.postgresql.enableTCPIP` changed from binding on all interfaces to binding on localhost in addition to the unix socket. | ||||||
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 is wrong: there's now an option called Generally, I'm wondering if we shouldn't just deprecate the In fact, we don't even need a I.e.
Does that make sense? |
||||||
''; | ||||||
|
||||||
services.postgresql.settings = | ||||||
{ | ||||||
hba_file = "${pkgs.writeText "pg_hba.conf" cfg.authentication}"; | ||||||
ident_file = "${pkgs.writeText "pg_ident.conf" cfg.identMap}"; | ||||||
log_destination = "stderr"; | ||||||
listen_addresses = if cfg.enableTCPIP then "*" else "localhost"; | ||||||
listen_addresses = if (cfg.enableTCPIP != false) then cfg.listenAddresses else ""; | ||||||
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.
Suggested change
|
||||||
jit = mkDefault (if cfg.enableJIT then "on" else "off"); | ||||||
}; | ||||||
|
||||||
|
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. Depending on what goes in first, we need to either adjust here or #352966, where we move all the postgres tests into 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. Thanks for linking to that PR, I didn't know about it. Do you think it would be relevant to test the behavior of these options with all PG versions ? My understanding is that this is not affected by the different versions. 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.
No, I don't think so. But I haven't made up my mind about where to draw the line, yet. The "and make sure to run them against all PG versions" was meant as a description for that PR, not necessarily as a requirement for this one. The requirement is*, that we have it in the same folder eventually, so that we're getting pinged via * And that we have it working nicely via passthru, but you already have that in principle, I think. Just avoiding the long relative path would be good (see my PR, too, for how to). |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
{ system ? builtins.currentSystem | ||
, config ? {} | ||
, pkgs ? import ../.. { inherit system config; } | ||
}: | ||
|
||
pkgs.testers.runNixOSTest { | ||
name = "postgresql-listen-addresses"; | ||
# Test that PostgreSQL defaults to "localhost" when enableTCPIP = true. | ||
|
||
nodes = { | ||
default = { pkgs, lib, ... }: { | ||
# Default behaviour of the service | ||
services.postgresql = { | ||
enable = true; | ||
}; | ||
environment.systemPackages = with pkgs; [ | ||
lsof | ||
]; | ||
}; | ||
listenall = { pkgs, lib, ... }: { | ||
services.postgresql = { | ||
enable = true; | ||
listenAddresses = "0.0.0.0"; | ||
enableTCPIP = true; | ||
# settings.listen_addresses = "0.0.0.0"; | ||
}; | ||
environment.systemPackages = with pkgs; [ | ||
lsof | ||
]; | ||
}; | ||
unixonly = { pkgs, lib, ... }: { | ||
services.postgresql = { | ||
enable = true; | ||
enableTCPIP = false; | ||
}; | ||
environment.systemPackages = with pkgs; [ | ||
lsof | ||
]; | ||
}; | ||
}; | ||
|
||
testScript = '' | ||
machines = [ default, listenall, unixonly ] | ||
|
||
for machine in machines: | ||
machine.start() | ||
machine.wait_for_unit("postgresql.service") | ||
|
||
with subtest("Configured to listen on localhost"): | ||
default.succeed( | ||
"sudo -u postgres psql <<<'SHOW listen_addresses' 2>/dev/null | grep 'localhost'") | ||
|
||
with subtest("Actually listening on localhost"): | ||
output = default.succeed("lsof -i tcp -P | grep 'localhost:5432'") | ||
|
||
with subtest("Configured to listen on localhost"): | ||
listenall.succeed( | ||
"sudo -u postgres psql <<<'SHOW listen_addresses' 2>/dev/null | grep '0.0.0.0'") | ||
|
||
with subtest("Actually listening on localhost"): | ||
listenall.succeed("lsof -i tcp -P | grep '*:5432'") | ||
|
||
with subtest("Configured not to listen on localhost or 0.0.0.0"): | ||
unixonly.fail( | ||
"sudo -u postgres psql <<<'SHOW listen_addresses' 2>/dev/null | grep 'localhost'") | ||
unixonly.fail( | ||
"sudo -u postgres psql <<<'SHOW listen_addresses' 2>/dev/null | grep '0.0.0.0'") | ||
|
||
with subtest("Actually not listening on TCP"): | ||
unixonly.fail("lsof -i tcp -P | grep ':5432'") | ||
|
||
for machine in machines: | ||
machine.shutdown() | ||
''; | ||
} |
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 setting the type to
nullOr bool
when the default istrue
?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.
The new default is
null
. This has the same behavior astrue
but this makes it possible to show a warning only to users who have this option configured, not to users who left the default values.