1 /* This test checks that
2 - multiple config files can be loaded
3 - the storage backend can be in a file outside the nix store
4 as is required for security (required because while confidentiality is
5 always covered, availability isn't)
6 - the postgres integration works
8 import ./make-test-python.nix ({ pkgs, ... }:
10 name = "vault-postgresql";
11 meta = with pkgs.lib.maintainers; {
12 maintainers = [ lnl7 roberth ];
14 nodes.machine = { lib, pkgs, ... }: {
15 environment.systemPackages = [ pkgs.vault ];
16 environment.variables.VAULT_ADDR = "http://127.0.0.1:8200";
17 services.vault.enable = true;
18 services.vault.extraSettingsPaths = [ "/run/vault.hcl" ];
20 systemd.services.vault = {
24 # Try for about 10 minutes rather than the default of 5 attempts.
25 serviceConfig.RestartSec = 1;
26 serviceConfig.StartLimitBurst = 600;
28 # systemd.services.vault.unitConfig.RequiresMountsFor = "/run/keys/";
30 services.postgresql.enable = true;
31 services.postgresql.initialScript = pkgs.writeText "init.psql" ''
32 CREATE USER vaultuser WITH ENCRYPTED PASSWORD 'thisisthepass';
33 GRANT CONNECT ON DATABASE postgres TO vaultuser;
35 -- https://www.vaultproject.io/docs/configuration/storage/postgresql
36 CREATE TABLE vault_kv_store (
37 parent_path TEXT COLLATE "C" NOT NULL,
38 path TEXT COLLATE "C",
41 CONSTRAINT pkey PRIMARY KEY (path, key)
43 CREATE INDEX parent_path_idx ON vault_kv_store (parent_path);
45 GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO vaultuser;
52 storage "postgresql" {
53 connection_url = "postgres://vaultuser:thisisthepass@localhost/postgres?sslmode=disable"
59 machine.wait_for_unit("multi-user.target")
60 machine.succeed("cat >/root/vault.hcl <<EOF\n%s\nEOF\n" % secretConfig)
62 "install --owner vault --mode 0400 /root/vault.hcl /run/vault.hcl; rm /root/vault.hcl"
64 machine.wait_for_unit("vault.service")
65 machine.wait_for_open_port(8200)
66 machine.succeed("vault operator init")
67 machine.succeed("vault status || test $? -eq 2")