The purpose of this blog post is to provide multiple methods on how to install/setup Vault. This blog post generated an Ansible playbook, Docker-composes for Swarm and non-swarm, and manual instructions for installing Vault on Ubuntu 20.04. Additionally, over the past couple of months, I have been learning Vault and demonstrating different ways to incorporate Vault. This blog post will be a condensed version of the content in those blog posts and a jumping off point to those blog posts as well.
Goals
- Install/Setup Vault with Docker
- Install/Setup Vault with Docker Swarm
- Install/Setup Vault with Ansible
- Manual Install/Setup of Vault on Ubuntu 20.04
Background
What is Hashicorp Vault?
HashiCorp Vault is an open-source tool for managing secrets. Application identity management with Vault enables applications and machines to automatically create, change, and rotate secrets needed for communications, services, scripts, etc. Additionally, Vault enables administrators to manage applications and machines by providing access control over different secrets.
What is Consul?
Consul is a service mesh solution providing a full featured control plane with service discovery, configuration, and segmentation functionality. Each of these features can be used individually as needed, or they can be used together to build a full service mesh. Consul requires a data plane and supports both a proxy and native integration model. Consul ships with a simple built-in proxy so that everything works out of the box, but also supports 3rd party proxy integrations such as Envoy.
Generate OpenSSL private key and public cert
git clone https://github.com/CptOfEvilMinions/Vault-Automation
cd Vault-Automation
cp conf/tls/tls.conf.example conf/tls/tls.conf
vim conf/tls/tls.conf
and set:- Set the location information under [dn]
C
– Set CountryST
– Set stateL
– Set cityO
– Enter organization nameemailAddress
– Enter a valid e-mail for your org
- Replace
{{ base_domain }}
in all fields with your domain
- Set the location information under [dn]
- For alt names list all the valid DNS records for this cert
- Save and exit
-
openssl req -x509 -new -nodes -keyout conf/tls/vault.key -out conf/tls/vault.crt -config conf/tls/tls.conf
- Generate TLS private key and public certificate
Install Vault with Docker-compose v2.x
git clone https://github.com/CptOfEvilMinions/Vault-Automation
cd Vault-Automation
docker-compose build
docker-compose up -d
- Skip ahead to the “Init Vault” section
Install Vault with Docker-compose v3.x (Swarm)
git clone https://github.com/CptOfEvilMinions/Vault-Automation
cd Vault-Automation
docker stack deploy -c docker-compose-stack.yml vault
- Spin up Docker stack
docker service logs -f vault_consul
- Tail logs of Consul container in Vault stack
docker service logs -f vault_vault
- Tail logs of Vault container in Vault stack
- Skip ahead to the “Init Vault” section
Install Vault on Ubuntu 20.04 with Ansible
Init playbook
git clone https://github.com/CptOfEvilMinions/Vault-Automation
cd Vault-Automation
pip3 install ansible
vim hosts.yml
and add IP address under[vault]
vim all.yml
and set:base_domain
– The domain for your network and the base domain of the FQDNtimezone
– OPTIONAL – Change the default timezone of UTC +0
vim hasicorp.yml
and set:consul_version
– OPTIONAL – Set the version of Consulvault_version
– OPTIONAL – Set the version of Vault
Run playbook
ansible-playbook -i hosts.ini deploy_vault.yml -u <username> -K
- Enter password
Manual install of Vault 1.6.1 on Ubuntu 20.04
Init VM
- Login into VM
apt update -y && apt upgrade -y && reboot
apt install unzip curl -y
Install/Setup Consul v1.9.1
cd /tmp
curl https://releases.hashicorp.com/consul/1.9.1/consul_1.9.1_linux_amd64.zip -o consul_1.9.1_linux_amd64.zip
- Download Consul
unzip consul_1.9.1_linux_amd64.zip
- Unzip consul
mv /tmp/consul /usr/local/bin/consul
- Add the Consul binary to the system’s path
chmod +x /usr/local/bin/consul
- Enable the execution of the binary
groupadd --system consul
- Create a group called
consul
- Create a group called
useradd -s /sbin/nologin --system -g consul consul
- Create a user named
consul
and add it to the group namedconsul
- Create a user named
mkdir -p /var/lib/consul
- Create directory for consul
chown -R consul:consul /var/lib/consul
chmod -R 775 /var/lib/consul
- Set permissions to
consul
- Set permissions to
mkdir /etc/consul.d
- Create consul config directory
chown -R consul:consul /etc/consul.d
curl https://raw.githubusercontent.com/CptOfEvilMinions/Vault-Automation/main/conf/ansible/consul/consul.hcl -o /etc/consul.d/consul.hcl
- Download consul config
sed -i "s/{{ consul_keygen.stdout }}/$(consul keygen)/g" /etc/consul.d/consul.hcl
consul keygen
– Generates an encryption key for Consul
curl https://raw.githubusercontent.com/CptOfEvilMinions/Vault-Automation/main/conf/ansible/consul/consul.service -o /etc/systemd/system/consul.service
- Download consul systemd file
systemctl enable consul
systemctl start consul
consul members
Install/Setup Vault v1.6.1
cd /tmp
curl https://releases.hashicorp.com/vault/1.6.1/vault_1.6.1_linux_amd64.zip -o vault_1.6.1_linux_amd64.zip
- Download Vault
unzip vault_1.6.1_linux_amd64.zip
- Unzip Vault
mv vault /usr/local/bin/vault
- Add the Consul binary to the system’s path
chmod +x /usr/local/bin/vault
- Enable the execution of the binary
groupadd --system vault
- Create a group called
vault
- Create a group called
useradd --system --home-dir /etc/vault --shell /sbin/nologin -g vault vault
- Create a user named
vault
and add it to the group namedvault
- Create a user named
mkdir -p /var/lib/vault
- Create directory for consul
chown -R vault:vault /var/lib/vault
chmod -R 775 /var/lib/vault
- Set permissions to
vault
- Set permissions to
mkdir /etc/vault
- Create consul config directory
chown -R vault:vault /etc/vault
curl https://raw.githubusercontent.com/CptOfEvilMinions/Vault-Automation/main/conf/ansible/vault/vault.hcl -o /etc/vault/config.hcl
- Download consul config
curl https://raw.githubusercontent.com/CptOfEvilMinions/Vault-Automation/main/conf/ansible/vault/vault.service -o /etc/systemd/system/vault.service
- Download consul systemd file
systemctl enable vault
systemctl start vault
netstat -tnlp | grep ':8200'
Install/Setup NGINX
apt install nginx -y
curl https://raw.githubusercontent.com/CptOfEvilMinions/Vault-Automation/main/conf/tls/ssl.conf -o /etc/ssl/ssl.conf
- Download SSL config
openssl req -new -x509 -newkey rsa:2048 -sha256 -nodes -keyout /etc/ssl/private/vault.key -days 3560 -out /etc/ssl/certs/vault.crt-config /etc/ssl/ssl.conf
- Generate OpenSSL self-signed private key and public certificate
curl https://raw.githubusercontent.com/CptOfEvilMinions/Vault-Automation/main/conf/ansible/nginx/nginx.conf -o /etc/nginx/nginx.conf
- Download main NGINX config
curl https://raw.githubusercontent.com/CptOfEvilMinions/Vault-Automation/main/conf/ansible/nginx/nginx_vault.conf -o /etc/nginx/conf.d/vault.conf
- Download NGINX config to server Vault
systemd enable nginx
systemd restart nginx
netstat -tnlp | grep 'nginx'
Setup UFW
ufw allow OpenSSH
- Allow SSH access
ufw allow 'NGINX HTTP'
ufw allow 'NGINX HTTPS'
- Allow NGINX for HTTP and HTTPS
ufw enable
- Skip ahead to the “Init Vault” section
Init Vault
- Open web browser to
https://<Vault IP addr>:<port>
- Enter
1
for Key Shares- NEVER EVER ENTER 1 FOR PRODUCTION – Only enter 1 for testing
- Enter
1
for Key threshold- NEVER EVER ENTER 1 FOR PRODUCTION – Only enter 1 for testing
- Select Initialize
- Enter
- Select “Download keys”
- Open terminal
cat ~/Downloads/vault-cluster-vault-*
- Back to browser
- Select “Continue to Unseal”
- Enter “<key from downloaded file>” into Master Key Portion
- Select “Unseal”
- Select “Token” for method
- Enter “<root_token from downloaded file>” into sign in
- Select “Sign In”
- Copy the root token for the next section
Install/Setup Vault CLI tool on macOS and connect to Vault
brew install jq
brew install hashicorp/tap/vault
export VAULT_ADDR=https://<Vault IP addr>:<port>
export VAULT_SKIP_VERIFY=true
- Disable TLS cert verify
vault login
- Enter root token from above
Jumping off points
- INSTALL/SETUP VAULT FOR PKI + NGINX + DOCKER – BECOMING YOUR OWN CA
- VAULT: CONNECTING ENTITIES, AUTH BACKENDS, GROUPS, AND POLICIES OH MY
- SETTING UP KOLIDE AND OSQUERY WITH CLIENT CERTIFICATES FOR MUTUAL TLS (MTLS)
- CREATING A WINDOWS 10 64-BIT VM ON PROXMOX WITH PACKER V1.6.3 AND VAULT
- INTEGRATING VAULT SECRETS INTO JUPYTER NOTEBOOKS FOR INCIDENT RESPONSE AND THREAT HUNTING