Skip to content

Commit 68d9643

Browse files
committed
nixos/tests/postgresql: test plv8 hardening on non-JIT variants only
PostgreSQL with JIT support enabled doesn't work with plv8. Hence, we'd get an evaluation failure for each `nixosTests.postgresql.postgresql.postgresql_jit_X`. This should be restructured in the future (less VM tests for custom extensions, but a single VM test for this case to cover). For now, we should get this fix out and this is a good-enough approach.
1 parent e198536 commit 68d9643

File tree

1 file changed

+38
-25
lines changed

1 file changed

+38
-25
lines changed

nixos/tests/postgresql/postgresql.nix

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,46 +14,59 @@ let
1414
postgresql-clauses = makeEnsureTestFor package;
1515
};
1616

17-
test-sql = pkgs.writeText "postgresql-test" ''
18-
CREATE EXTENSION pgcrypto; -- just to check if lib loading works
19-
CREATE TABLE sth (
20-
id int
17+
test-sql =
18+
enablePLv8Test:
19+
pkgs.writeText "postgresql-test" (
20+
''
21+
CREATE EXTENSION pgcrypto; -- just to check if lib loading works
22+
CREATE TABLE sth (
23+
id int
24+
);
25+
INSERT INTO sth (id) VALUES (1);
26+
INSERT INTO sth (id) VALUES (1);
27+
INSERT INTO sth (id) VALUES (1);
28+
INSERT INTO sth (id) VALUES (1);
29+
INSERT INTO sth (id) VALUES (1);
30+
CREATE TABLE xmltest ( doc xml );
31+
INSERT INTO xmltest (doc) VALUES ('<test>ok</test>'); -- check if libxml2 enabled
32+
''
33+
+ lib.optionalString enablePLv8Test ''
34+
-- check if hardening gets relaxed
35+
CREATE EXTENSION plv8;
36+
-- try to trigger the V8 JIT, which requires MemoryDenyWriteExecute
37+
DO $$
38+
let xs = [];
39+
for (let i = 0, n = 400000; i < n; i++) {
40+
xs.push(Math.round(Math.random() * n))
41+
}
42+
console.log(xs.reduce((acc, x) => acc + x, 0));
43+
$$ LANGUAGE plv8;
44+
''
2145
);
22-
INSERT INTO sth (id) VALUES (1);
23-
INSERT INTO sth (id) VALUES (1);
24-
INSERT INTO sth (id) VALUES (1);
25-
INSERT INTO sth (id) VALUES (1);
26-
INSERT INTO sth (id) VALUES (1);
27-
CREATE TABLE xmltest ( doc xml );
28-
INSERT INTO xmltest (doc) VALUES ('<test>ok</test>'); -- check if libxml2 enabled
29-
-- check if hardening gets relaxed
30-
CREATE EXTENSION plv8;
31-
-- try to trigger the V8 JIT, which requires MemoryDenyWriteExecute
32-
DO $$
33-
let xs = [];
34-
for (let i = 0, n = 400000; i < n; i++) {
35-
xs.push(Math.round(Math.random() * n))
36-
}
37-
console.log(xs.reduce((acc, x) => acc + x, 0));
38-
$$ LANGUAGE plv8;
39-
'';
4046

4147
makeTestForWithBackupAll =
4248
package: backupAll:
49+
let
50+
enablePLv8Check = !package.pkgs.plv8.meta.broken;
51+
in
4352
makeTest {
4453
name = "postgresql${lib.optionalString backupAll "-backup-all"}-${package.name}";
4554
meta = with lib.maintainers; {
4655
maintainers = [ zagy ];
4756
};
4857

4958
nodes.machine =
50-
{ ... }:
59+
{ config, ... }:
5160
{
5261
services.postgresql = {
5362
inherit package;
5463
enable = true;
5564
enableJIT = lib.hasInfix "-jit-" package.name;
56-
extensions = ps: with ps; [ plv8 ];
65+
# plv8 doesn't support postgresql with JIT, so we only run the test
66+
# for the non-jit variant.
67+
# TODO(@Ma27) split this off into its own VM test and move a few other
68+
# extension tests to use postgresqlTestExtension.
69+
extensions = lib.mkIf enablePLv8Check (ps: with ps; [ plv8 ]);
5770
};
5871

5972
services.postgresqlBackup = {
@@ -80,7 +93,7 @@ let
8093
8194
with subtest("Postgresql is available just after unit start"):
8295
machine.succeed(
83-
"cat ${test-sql} | sudo -u postgres psql"
96+
"cat ${test-sql enablePLv8Check} | sudo -u postgres psql"
8497
)
8598
8699
with subtest("Postgresql survives restart (bug #1735)"):

0 commit comments

Comments
 (0)