Vault

This role deploys a new Vault instance and performs the required initialization. If ran on a client node, it provisions a Vault agent instance instead.

Prerequisites

  • Vault >1.14.0 installed
  • Terraform installed on Ansible host
  • A private key and signed certificate for TLS encryption. If from a self-signed CA, the certificate chain must be trusted.
  • (Optional) Bitwarden password manager installed

Initialization

Vault is configured and started. If the instance is uninitialized, the role performs first-time initialization and stores the root token and unseal key. Only a single unseal key is supported at the moment. The secrets can be stored in the filesystem or on Bitwarden.

Note: If storing in Bitwarden, the Bitwarden CLI must be installed, configured and the bw_password variable must be provided.

It then proceeds to login with the root token and setup the PKI secrets engine and various authentication roles with the Terraform provider. A full list of Terraform resources can be found at homelab/terraform/vault.

Warning: Any existing Vault resources in the same workspace are destroyed permanently. Take care that the appropriate workspaces are used when running the role on multiple Vault server instances.

Vault Agent

If this role is ran on a client node or vault_setup_agent is true (on a server node), it will also provision a Vault-Agent instance. It requires an existing unsealed Vault server and should be run only after the Vault server has been setup.

Vault-agent's method of authentication to Vault is TLS certificate authentication. Ansible will generate these certificates and write them to the agent's auth role.

Note: This means Ansible requires access to Vault which it receives through authentication using its own TLS certificates, created by Terraform during the provisioning of the Vault server. These certificates were also written to homelab/certs/

Variables

VariableDescriptionTypeDefault
vault_config_dirConfiguration directorystring/etc/vault.d
vault_data_dirRestricted data directorystring/opt/vault/data
vault_log_dirRestricted logs directorystring/opt/vault/logs
vault_tls_dirTLS files directorystring/opt/vault/tls
vault_ca_cert_dirVault's CA certificate directorystring/usr/share/ca-certificates/vault
vault_serverSetup Vault serverbooltrue
vault_log_fileAudit log filestring${vault_log_dir}/vault.log
vault_store_localCopy Vault init secrets to local filebooltrue
vault_secrets_fileFile path for Vault init secretsstringvault.txt
vault_store_bwStore root token in Bitwardenboolfalse
vault_terraform_workspaceTerraform workspacestringdefault
vault_admin_passwordPassword for admin userstringpassword
vault_register_consulRegister Vault as a Consul servicebooltrue
vault_setup_agentSetup Vault agentbooltrue
vault_server_fqdnExisting Vault server's FQDNstring${ansible_default_ipv4.address}

Notes

  • vault_server and vault_setup_agent are not mutually exclusive. A host can have both instances running at the same time. However, there must already be an existing server instance if vault_server is false.
  • vault_server_fqdn is used to communicate with an existing Vault server that is listening on port 8200 when setting up Vault agent.

Vault Initialization Secrets

This role offers two methods of storing the secrets generated (root token and unseal key(s)) during the initial Vault initialization:

  • On the Ansible host system
  • In Bitwarden
  • Both

Storing the secrets on the local filesystem is only recommended as a temporary measure (to verify the secrets), or for testing and development. The file should be deleted afterwards or moved to a safer location.

Warning: The Bitwarden storage functionality is not very robust and not recommended at the moment. Use it with caution.

Storing the secrets in Bitwarden requires the following prerequisites:

  • Bitwarden CLI tool must be installed and configured
  • User is logged into Bitwarden
  • bw_password variable must be defined and passed to Ansible safely

The bw_get.sh and bw_store.sh helper scripts are used to create or update the secrets. Take care that the scripts will overwrite any existing secrets (of the same name).