Hashicorp's solution to managing Secrets and Protecting Sensitive Data
What is Vault?
Vault is a solution developed by Hashicorp that enables the storage and lifecycle of secrets (i.e., user/pass, API keys, certificates, encryption keys, etc.)
Installation
brewinstallvault
Vault Cheat Sheet
Vault Configuration Commands
# View vault configuration (stored on whichever server Vault is installed on). This file path can be different!cat/etc/vault.d/vault.hcl# Validate/troubleshoot configuration file. Point it to your configuration file pathvaultoperatordiagnose-config=/etc/vault.d/vault.hcl# Initialize Vault for the first time (modify as needed)vaultoperatorinit \ -key-shares=3\-key-threshold=2
Vault Operations
# Get helpvault--help# (-h)vault<command>--help# (-h)# Get vault versionvaultversion# View vault status (seal/unseal status)vaultstatus# Unseal vault (other options e.g., AWS KMS exist too)vaultoperatorunseal# hit enterUnsealKey (will behidden): # paste key shard value# Login to Vaultvaultloginhvs.7j0Pi7dUJNE5GV3Z77HyCCBS# Restart Vaultsudosystemctlrestartvault
Vault Dev Mode
# Start Vault in Dev mode (testing only, not for production)vaultserver-dev# interact with vault in another terminal tab / window# hit CMD+C to end the vault session# Or start vault in the background and interact in the same terminal tabvaultserver-dev&# kill vault by finding the pidps-ef|grep'vault server -dev'kill-9<PID>
Vault Secrets
# Create a secrets engine at the path of "home/"vaultsecretsenable-path=home/kv# kv-v2# Save a secret to the file "vault-token" at the initial path "home/". Syntax is Key=Valuevaultkvputhome/tyler/vault-token"Initial Root Token:"=hvs.35fzQIN0BstyJxCj46W0ajiy# Retrieve a secretvaultkvgethome/tyler/vault-token
Vault Auth Methods
# Enable the aws auth methodvaultauthenableaws# Provide a custom path and description for the aws auth methodvaultauthenable-path=tylers-aws-path-description=aws-credsaws# vault auth list (to see these details)# Disable auth methodvaultauthdisableaws# List auth methodsvaultauthlist# Modify the token/ auth method's TTL so that the token expires after 1 hourvaultauthtune-max-lease-ttl=3600token/#Success! Tuned the auth method at: token/
Vault Policies
# List policiesvaultpolicylist# Read a policyvaultpolicyread<policyname># Write (upload) a policyvaultpolicywrite<policyname><pathtopolicyfile># Test a policy by generating a token to login with itvaulttokencreate-policy=<policyname>
Vault Tokens
# List all tokens in vaultvaultlistauth/token/accessors# Create a new root tokenvaulttokencreate# View properties of a tokenvaulttokenlookup-accessor<accessor># run: vault list auth/token/accessors to get <accessor># Revoke a tokenvaulttokenrevoke<roottoken># found in .vault-tokenvaulttokenrevoke-accessor<accessor># run: vault list auth/token/accessors to get <accessor>