2023-04-25 13:58:30 +00:00
|
|
|
import ./make-test-python.nix (
|
|
|
|
{ pkgs, ... }:
|
|
|
|
{
|
|
|
|
name = "vault-agent";
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2023-04-25 13:58:30 +00:00
|
|
|
nodes.machine =
|
|
|
|
{ config, pkgs, ... }:
|
|
|
|
{
|
|
|
|
services.vault-agent.instances.example.settings = {
|
|
|
|
vault.address = config.environment.variables.VAULT_ADDR;
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2023-04-25 13:58:30 +00:00
|
|
|
auto_auth = [
|
|
|
|
{
|
|
|
|
method = [
|
2024-12-10 19:26:33 +00:00
|
|
|
{
|
2023-04-25 13:58:30 +00:00
|
|
|
type = "token_file";
|
|
|
|
config.token_file_path = pkgs.writeText "vault-token" config.environment.variables.VAULT_TOKEN;
|
|
|
|
}
|
|
|
|
];
|
2024-12-10 19:26:33 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2023-04-25 13:58:30 +00:00
|
|
|
template = [
|
|
|
|
{
|
|
|
|
contents = ''
|
|
|
|
{{- with secret "secret/example" }}
|
|
|
|
{{ .Data.data.key }}"
|
|
|
|
{{- end }}
|
|
|
|
'';
|
|
|
|
perms = "0600";
|
|
|
|
destination = "/example";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2023-04-25 13:58:30 +00:00
|
|
|
services.vault = {
|
|
|
|
enable = true;
|
|
|
|
dev = true;
|
|
|
|
devRootTokenID = config.environment.variables.VAULT_TOKEN;
|
|
|
|
};
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2023-04-25 13:58:30 +00:00
|
|
|
environment = {
|
|
|
|
systemPackages = [ pkgs.vault ];
|
|
|
|
variables = {
|
|
|
|
VAULT_ADDR = "http://localhost:8200";
|
|
|
|
VAULT_TOKEN = "root";
|
2024-12-10 19:26:33 +00:00
|
|
|
};
|
|
|
|
};
|
2023-04-25 13:58:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
testScript = ''
|
|
|
|
machine.wait_for_unit("vault.service")
|
|
|
|
machine.wait_for_open_port(8200)
|
|
|
|
|
|
|
|
machine.wait_until_succeeds('vault kv put secret/example key=example')
|
|
|
|
|
|
|
|
machine.wait_for_unit("vault-agent-example.service")
|
|
|
|
|
|
|
|
machine.wait_for_file("/example")
|
|
|
|
machine.succeed('grep "example" /example')
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
)
|