Configure Vault auto-unseal with AWS KMS for high availability secrets management

Intermediate 25 min Apr 12, 2026 225 views
Ubuntu 24.04 Debian 12 AlmaLinux 9 Rocky Linux 9

Set up HashiCorp Vault with AWS KMS auto-unseal to eliminate manual unsealing processes and enable high availability deployments with automatic recovery.

Prerequisites

  • AWS account with IAM permissions
  • Root or sudo access
  • Basic knowledge of HashiCorp Vault
  • SSL certificate (self-signed acceptable for testing)

What this solves

HashiCorp Vault requires manual unsealing after restarts, which creates operational overhead and prevents true high availability. AWS KMS auto-unseal eliminates this bottleneck by automatically unsealing Vault servers using AWS Key Management Service encryption keys. This configuration enables automated failover, reduces human intervention, and supports scalable secrets management in production environments.

Step-by-step configuration

Update system packages

Start by updating your package manager to ensure you get the latest versions and security patches.

sudo apt update && sudo apt upgrade -y
sudo apt install -y curl unzip jq awscli
sudo dnf update -y
sudo dnf install -y curl unzip jq awscli

Install HashiCorp Vault

Download and install the latest Vault binary from HashiCorp's official releases.

VAULT_VERSION="1.15.4"
wget https://releases.hashicorp.com/vault/${VAULT_VERSION}/vault_${VAULT_VERSION}_linux_amd64.zip
unzip vault_${VAULT_VERSION}_linux_amd64.zip
sudo mv vault /usr/local/bin/
sudo chmod +x /usr/local/bin/vault
vault --version

Create Vault user and directories

Create a dedicated system user for Vault and set up the necessary directory structure with proper permissions.

sudo useradd --system --home /opt/vault --shell /bin/false vault
sudo mkdir -p /opt/vault/data /opt/vault/logs /etc/vault.d
sudo chown -R vault:vault /opt/vault
sudo chmod 750 /opt/vault/data
Never use chmod 777. It gives every user on the system full access to your files. Vault data directories contain sensitive information and should only be accessible by the vault user.

Configure AWS CLI with IAM permissions

Set up AWS credentials for Vault to access KMS. Create an IAM user with KMS permissions first in the AWS Console.

sudo -u vault aws configure

Enter your AWS Access Key ID, Secret Key, region (e.g., us-east-1), and output format (json)

The IAM user needs this policy for KMS operations:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "kms:Encrypt",
        "kms:Decrypt",
        "kms:ReEncrypt*",
        "kms:GenerateDataKey*",
        "kms:DescribeKey"
      ],
      "Resource": "arn:aws:kms:::key/*"
    }
  ]
}

Create AWS KMS key for Vault unsealing

Create a dedicated KMS key for Vault auto-unseal operations with proper key policy and alias.

aws kms create-key --description "Vault Auto-Unseal Key" --usage ENCRYPT_DECRYPT

Note the KeyId from the output

Create an alias for easier reference

aws kms create-alias --alias-name alias/vault-unseal --target-key-id YOUR_KEY_ID_HERE

Get the key ARN for configuration

aws kms describe-key --key-id alias/vault-unseal --query 'KeyMetadata.Arn' --output text

Configure Vault server with auto-unseal

Create the main Vault configuration file with AWS KMS auto-unseal parameters and storage backend.

ui = true
api_addr = "https://vault.example.com:8200"
cluster_addr = "https://vault.example.com:8201"

storage "file" {
  path = "/opt/vault/data"
}

listener "tcp" {
  address = "0.0.0.0:8200"
  cluster_address = "0.0.0.0:8201"
  tls_cert_file = "/etc/vault.d/vault.crt"
  tls_key_file = "/etc/vault.d/vault.key"
  tls_min_version = "tls12"
}

seal "awskms" {
  region = "us-east-1"
  kms_key_id = "alias/vault-unseal"
  endpoint = "https://kms.us-east-1.amazonaws.com"
}

log_level = "INFO"
log_file = "/opt/vault/logs/vault.log"
log_rotate_duration = "24h"
log_rotate_max_files = 30

default_lease_ttl = "168h"
max_lease_ttl = "720h"

cluster_name = "vault-prod"

Generate SSL certificates

Create self-signed certificates for testing or use your existing SSL certificates for production.

sudo openssl req -x509 -nodes -days 365 -newkey rsa:4096 \
  -keyout /etc/vault.d/vault.key \
  -out /etc/vault.d/vault.crt \
  -subj "/C=US/ST=State/L=City/O=Organization/CN=vault.example.com" \
  -addext "subjectAltName = DNS:vault.example.com,DNS:localhost,IP:127.0.0.1"

sudo chown vault:vault /etc/vault.d/vault.key /etc/vault.d/vault.crt
sudo chmod 600 /etc/vault.d/vault.key
sudo chmod 644 /etc/vault.d/vault.crt

Set configuration file permissions

Secure the Vault configuration file to prevent unauthorized access to sensitive settings.

sudo chown vault:vault /etc/vault.d/vault.hcl
sudo chmod 640 /etc/vault.d/vault.hcl

Create systemd service file

Configure Vault to run as a systemd service with proper security settings and automatic restart capabilities.

[Unit]
Description=HashiCorp Vault
Documentation=https://www.vaultproject.io/docs/
Requires=network-online.target
After=network-online.target
ConditionFileNotEmpty=/etc/vault.d/vault.hcl

[Service]
Type=notify
User=vault
Group=vault
ProtectSystem=full
ProtectHome=read-only
PrivateTmp=yes
PrivateDevices=yes
SecureBits=keep-caps
AmbientCapabilities=CAP_IPC_LOCK
Capabilities=CAP_IPC_LOCK+ep
CapabilityBoundingSet=CAP_SYSLOG CAP_IPC_LOCK
NoNewPrivileges=yes
ExecStart=/usr/local/bin/vault server -config=/etc/vault.d/vault.hcl
ExecReload=/bin/kill --signal HUP $MAINPID
KillMode=process
Restart=on-failure
RestartSec=5
TimeoutStopSec=30
StartLimitInterval=60
StartLimitBurst=3
LimitNOFILE=65536
LimitMEMLOCK=infinity

[Install]
WantedBy=multi-user.target

Enable and start Vault service

Start the Vault service and enable it to run automatically on system boot.

sudo systemctl daemon-reload
sudo systemctl enable vault
sudo systemctl start vault
sudo systemctl status vault

Initialize Vault with auto-unseal

Initialize Vault which will automatically unseal using the AWS KMS key. The initialization only happens once.

export VAULT_ADDR="https://vault.example.com:8200"
export VAULT_SKIP_VERIFY=1  # Only for self-signed certificates

Initialize Vault

vault operator init -recovery-shares=5 -recovery-threshold=3

Save the recovery keys and root token securely

Vault should automatically unseal after initialization

Note: With auto-unseal, you get recovery keys instead of unseal keys. Store these securely as they're needed for disaster recovery operations.

Configure firewall rules

Open the necessary ports for Vault API and cluster communication.

sudo ufw allow 8200/tcp comment "Vault API"
sudo ufw allow 8201/tcp comment "Vault Cluster"
sudo ufw reload
sudo firewall-cmd --add-port=8200/tcp --permanent --zone=public
sudo firewall-cmd --add-port=8201/tcp --permanent --zone=public
sudo firewall-cmd --reload

Test auto-unseal functionality

Test service restart and auto-unseal

Verify that Vault automatically unseals when the service restarts, eliminating manual intervention.

# Check current seal status
vault status

Restart the Vault service

sudo systemctl restart vault

Wait a few seconds and check status again

sleep 5 vault status

Vault should show "Sealed: false" without manual unsealing

Test failover scenario

Simulate a complete system restart to verify automatic unsealing during boot.

# Record current status
vault status

Simulate system restart

sudo systemctl stop vault sudo systemctl start vault

Check logs for auto-unseal process

sudo journalctl -u vault -f --since="5 minutes ago"

Verify your setup

# Check Vault service status
sudo systemctl status vault

Verify Vault is unsealed

vault status

Check AWS KMS key usage

aws kms describe-key --key-id alias/vault-unseal

Test basic Vault operations

vault auth -method=userpass vault secrets list

Common issues

SymptomCauseFix
Vault fails to start with permission errorsIncorrect file ownership or permissionssudo chown -R vault:vault /opt/vault /etc/vault.d
Auto-unseal fails with AWS credentials errorMissing or incorrect AWS credentialsRun sudo -u vault aws sts get-caller-identity to verify credentials
KMS access denied errorIAM user lacks KMS permissionsAttach the vault-kms-policy to your IAM user
SSL/TLS handshake errorsCertificate issues or hostname mismatchUpdate certificate SAN or use VAULT_SKIP_VERIFY=1 for testing
Vault sealed after AWS outageTemporary KMS unavailabilityUse recovery keys: vault operator unseal -mode=recovery
High availability cluster failsIncorrect cluster configurationVerify cluster_addr and network connectivity between nodes

Next steps

Automated install script

Run this to automate the entire setup

Need help?

Don't want to manage this yourself?

We handle infrastructure security hardening for businesses that depend on uptime. From initial setup to ongoing operations.