at 23.11-pre 2.4 kB view raw
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 7 */ 8import ./make-test-python.nix ({ pkgs, ... }: 9{ 10 name = "vault-postgresql"; 11 meta = with pkgs.lib.maintainers; { 12 maintainers = [ lnl7 roberth ]; 13 }; 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" ]; 19 20 systemd.services.vault = { 21 after = [ 22 "postgresql.service" 23 ]; 24 # Try for about 10 minutes rather than the default of 5 attempts. 25 serviceConfig.RestartSec = 1; 26 serviceConfig.StartLimitBurst = 600; 27 }; 28 # systemd.services.vault.unitConfig.RequiresMountsFor = "/run/keys/"; 29 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; 34 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", 39 key TEXT COLLATE "C", 40 value BYTEA, 41 CONSTRAINT pkey PRIMARY KEY (path, key) 42 ); 43 CREATE INDEX parent_path_idx ON vault_kv_store (parent_path); 44 45 GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO vaultuser; 46 ''; 47 }; 48 49 testScript = 50 '' 51 secretConfig = """ 52 storage "postgresql" { 53 connection_url = "postgres://vaultuser:thisisthepass@localhost/postgres?sslmode=disable" 54 } 55 """ 56 57 start_all() 58 59 machine.wait_for_unit("multi-user.target") 60 machine.succeed("cat >/root/vault.hcl <<EOF\n%s\nEOF\n" % secretConfig) 61 machine.succeed( 62 "install --owner vault --mode 0400 /root/vault.hcl /run/vault.hcl; rm /root/vault.hcl" 63 ) 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") 68 ''; 69})