Vault Setup
VM Setup
VM Settings
Name: dev-vault-01
IP: 192.168.8.112
Clone from template
NO DOCKER --> 8GB Ram, 2 vCPU, 100GB HDD ub-24-min-no-docker
Update system packages
sudo vim /etc/netplan/50-cloud-init.yaml:%d [ENTER]network:
version: 2
ethernets:
enp6s18:
dhcp4: no
addresses:
- 192.168.8.7/22
gateway4: 192.168.8.1
nameservers:
addresses:
- 1.1.1.1
- 8.8.8.8sudo netplan applyReboot the server and login using 192.168.8.7
First, install Vault Server in HTTP mode
Update and Install Dependencies
sudo apt update && sudo apt upgrade -ysudo apt install -y curl gnupg unzipAdd HashiCorp GPG Key and Repo
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpgecho "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.listsudo apt updateInstall Vault
sudo apt install -y vaultConfigure Vault for HTTP Access
Create the Vault configuration directory and config file:
sudo mkdir -p /etc/vault.dsudo vim /etc/vault.d/vault.hclPaste the following minimal configuration for HTTP mode (make sure 0.0.0.0 is provided):
listener "tcp" {
address = "0.0.0.0:8200"
tls_disable = 1
}
storage "file" {
path = "/opt/vault/data"
}
disable_mlock = true
ui = trueCreate the storage directory:
sudo mkdir -p /etc/vault.dsudo chown -R vault:vault /opt/vaultSet Vault Environment Variables
export VAULT_ADDR="http://192.168.8.7:8200"Enable and Start Vault as a Service. Edit systemd service to use the config file:
sudo systemctl enable vaultsudo systemctl status vaultsudo systemctl start vaultInitialize and Unseal Vault
vault operator initYou'll get 5 unseal keys and 1 root token — save them securely.
Unseal with 3 of the unseal keys:
vault operator unsealvault operator unsealvault operator unsealRun the following command to check the status of the Vault server:
vault statusEnable required ports in firewall:
sudo ufw allow 8200sudo ufw allow 80sudo ufw allow 443sudo ufw reloadsudo ufw status verboseLogin with the root token:
vault loginAccess the Vault UI
http://192.168.8.7:8200/uiNow, HTTPS for the Vault Server
Goal:
Access Vault at: https://dev.vault.aspireclan.com
With: Cloudflare DNS, Let's Encrypt SSL via DNS-01 challenge, Certbot using a secure API Token, NGINX reverse proxy, Vault running on localhost HTTP
💡Pre-Requirements:
dev.vault.aspireclan.com must point to the Vault Server IP (update A record in prod-dns-01).
After creating the above DNS record, run:
sudo systemctl restart namedInstall Required Packages
sudo apt update && sudo apt install -y nginx certbot python3-certbot-dns-cloudflare unzip curl gnupgCreate Cloudflare Credentials File
sudo mkdir -p /etc/letsencryptsudo vim /etc/letsencrypt/cloudflare.iniCopy below information
dns_cloudflare_api_token = YOUR_CLOUDFLARE_API_TOKENReplace YOUR_CLOUDFLARE_API_TOKEN with the token you created.
Secure the file:
sudo chmod 600 /etc/letsencrypt/cloudflare.iniIssue SSL Certificate Using DNS-01 Challenge
sudo certbot certonly \
--dns-cloudflare \
--dns-cloudflare-credentials /etc/letsencrypt/cloudflare.ini \
-d dev.vault.aspireclan.com \
--preferred-challenges dns-01 \
--agree-tos \
--no-eff-email \
--email aspireclan1208@gmail.comOutput cert files will be at:
/etc/letsencrypt/live/dev.vault.aspireclan.com/sudo cat /etc/letsencrypt/live/dev.vault.aspireclan.com/Configure NGINX as Reverse Proxy to Vault
Create an NGINX config for Vault:
sudo vim /etc/nginx/sites-available/vaultPaste the following configuration:
server {
listen 80;
server_name dev.vault.aspireclan.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name dev.vault.aspireclan.com;
ssl_certificate /etc/letsencrypt/live/dev.vault.aspireclan.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/dev.vault.aspireclan.com/privkey.pem;
location / {
proxy_pass http://127.0.0.1:8200;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}Enable the config:
sudo ln -s /etc/nginx/sites-available/vault /etc/nginx/sites-enabled/sudo nginx -tsudo systemctl reload nginxUpdate Vault Config to Listen Only on Localhost
Edit Vault config:
sudo vim /etc/vault.d/vault.hclEnsure this section is correct: change 0.0.0.0 to 127.0.0.1
listener "tcp" {
address = "127.0.0.1:8200"
tls_disable = 1
}
storage "file" {
path = "/opt/vault/data"
}
disable_mlock = true
ui = trueRestart Vault:
sudo systemctl restart vault=====================================================================
Automate SSL Renewal with Cron Job [Optional]
sudo apt updatesudo apt install cronsudo apt install cron vim nanoThen enable and start the cron service:
sudo systemctl enable cronsudo systemctl start cronCreate cron job:
sudo crontab -eSelect VIM as the editor. Usually the option 2.
0 3 * * * certbot renew --dns-cloudflare --dns-cloudflare-credentials /etc/letsencrypt/cloudflare.ini --quiet --post-hook "systemctl reload nginx"=====================================================================
Test renewal manually:
sudo certbot renew --dry-runTest the Setup:
Open your browser and go to:
https://dev.vault.aspireclan.com=====================================================================