Skip to content

Commit d392913

Browse files
authored
update Hashicorp Vault formula (#719)
1 parent 0be958f commit d392913

File tree

7 files changed

+561
-14
lines changed

7 files changed

+561
-14
lines changed

vault/README.md

Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
# vault Salt formula
2+
3+
Short, accurate documentation for this formula.
4+
5+
## Overview
6+
This formula installs and configures HashiCorp Vault, supports:
7+
- Binary installation (specified via `pillar['vault']['version']`) — downloads official Vault zip and installs `/usr/bin/vault`.
8+
- APT installation (legacy) following HashiCorp apt repository instructions.
9+
- Setting capabilities (`CAP_IPC_LOCK`, `CAP_NET_BIND_SERVICE`) so Vault can bind to privileged ports (443).
10+
- Snapshot creation
11+
- Restore from snapshot, initialization, unseal, and full wipe workflows.
12+
13+
## Files
14+
- init.sls — install/config (binary and apt branches)
15+
- initialization.sls — runs `vault operator init` and stores JSON on the Vault host
16+
- unseal.sls — unseal logic using pillar['vault']['unseal_keys']
17+
- audit.sls — enable/disable audit logging to file
18+
- remove_init_files.sls — cleanup of init JSON files after keys are safely stored in pillar
19+
- root_token_file.sls — create `/root/.vault-token` with root token for quick authentication
20+
- restore.sls — restore snapshot workflow
21+
- wipe.sls — destructive reinstall + wipe
22+
23+
## Pillar (example)
24+
```
25+
vault:
26+
version: '1.21.1' # optional — if present, binary install is used
27+
privileged_token: '...'
28+
unseal_keys:
29+
- 'AAA...='
30+
- 'BBB...='
31+
- 'CCC...='
32+
env_vars:
33+
VAULT_ADDR: 'https://127.0.0.1:8200'
34+
init:
35+
key_shares: 5
36+
key_threshold: 3
37+
output_file: /opt/vault/init-temp.json
38+
restore:
39+
snapshot_path: /opt/vault/snapshots/vault_YY-MM-DD.snap
40+
unseal_keys: # optional: keys to use only for restore
41+
- 'ZZZ...='
42+
```
43+
44+
## Key workflows
45+
46+
### Install
47+
- With binary: set `vault.version` in pillar. The formula downloads the specified release zip from releases.hashicorp.com, extracts only the `vault` binary to `/usr/bin/vault`, sets perms and capabilities, and creates systemd unit.
48+
- With apt: omit `vault.version`. The formula follows the official apt repo setup (signed-by keyring) and installs `vault` package.
49+
50+
### Initialization
51+
- Prerequisite: apply `vault.init` first (installs binary/package, writes config/env, systemd unit, and starts the service).
52+
53+
```bash
54+
salt-ssh 'target' state.apply vault.init
55+
salt-ssh 'target' state.apply vault.initialization
56+
```
57+
58+
- The `vault.initialization` state runs `vault operator init -format=json` only when Vault is not initialized. It saves JSON to `/opt/vault/init-temp.json`, and prints a pillar-ready YAML snippet to stdout so you can copy it into your pillar.
59+
60+
### Unseal
61+
- `vault.unseal` reuses pillar['vault']['unseal_keys'].
62+
- During restore, if `vault.restore.unseal_keys` is provided, those keys will be used for autounsealing restored storage.
63+
64+
### Restore (restore.sls)
65+
- Requirements: `pillar['vault']['restore']['snapshot_path']` must be set.
66+
- Behavior:
67+
- Includes `vault.unseal` so unseal states are available.
68+
- Stops/starts vault service appropriately, runs `vault operator raft snapshot restore` with provided `snapshot_path`.
69+
- After restore, it performs unseal steps using `vault.restore.unseal_keys`.
70+
- Important: Vault must be reachable and the privileged token available in pillar for operations that require authentication.
71+
72+
### Wipe (wipe.sls)
73+
- Stops Vault, deletes configured data path `/opt/vault/data`, removes package or binary depending on install mode, then includes `vault.init` and `vault.initialization` to reinstall and re-init.
74+
75+
### Audit Logging (audit.sls)
76+
- Enable or disable audit logging via pillar:
77+
```yaml
78+
vault:
79+
audit:
80+
enable: true
81+
file: /var/log/vault_audit.log
82+
```
83+
- Apply the state:
84+
```bash
85+
salt-ssh 'target' state.apply vault.audit
86+
```
87+
- Requires `privileged_token` in pillar for authentication.
88+
- Audit logs are written to the specified file in JSON format.
89+
90+
### Root Token File (root_token_file.sls)
91+
- After initialization, store your `privileged_token` in pillar and apply:
92+
```bash
93+
salt-ssh 'target' state.apply vault.root_token_file
94+
```
95+
- Creates `/root/.vault-token` with mode 600, allowing `root` to run Vault commands without manually providing `VAULT_TOKEN`:
96+
```bash
97+
sudo vault status # will automatically use /root/.vault-token
98+
```
99+
100+
### Cleanup Init Files (remove_init_files.sls)
101+
- After safely copying the JSON output from `vault.initialization` into your pillar, remove the temporary init file:
102+
```bash
103+
salt-ssh 'target' state.apply vault.remove_init_files
104+
```
105+
- Deletes `/opt/vault/init-temp.json` by default (configurable via `init.output_file`).
106+
- Recommended: do this only after you have verified the keys are stored in a safe location (pillar, sealed backup, etc.).
107+
108+
## Systemd & capabilities
109+
- The formula always creates `/etc/systemd/system/vault.service.d/capabilities.conf` with:
110+
```
111+
[Service]
112+
CapabilityBoundingSet=CAP_SYSLOG CAP_IPC_LOCK CAP_NET_BIND_SERVICE
113+
AmbientCapabilities=CAP_NET_BIND_SERVICE
114+
```
115+
- The Vault binary receives capabilities via `setcap` so binding to port 443 works on both install methods.
116+
117+
## Quick Diagnostics Commands
118+
119+
### Vault Status & Health
120+
```bash
121+
# Check Vault status (sealed/unsealed, cluster info)
122+
vault status
123+
124+
# Check if Vault is initialized
125+
vault status -format=json | jq -r '.initialized'
126+
127+
# Check if Vault is sealed
128+
vault status -format=json | jq -r '.sealed'
129+
130+
# Health check endpoint
131+
curl -k https://localhost:8200/v1/sys/health
132+
133+
# Leader status
134+
curl -sk https://localhost:8200/v1/sys/leader | jq
135+
```
136+
137+
### Raft Cluster
138+
```bash
139+
# List Raft peers
140+
vault operator raft list-peers
141+
142+
# Show cluster configuration
143+
vault read sys/storage/raft/configuration
144+
145+
# Check if node is leader
146+
vault read sys/leader
147+
```
148+
149+
### Snapshots
150+
```bash
151+
# List snapshots directory
152+
ls -lah /opt/vault/snapshots/
153+
154+
# Verify snapshot integrity
155+
vault operator raft snapshot inspect /opt/vault/snapshots/vault_latest.snap
156+
157+
# Manually create snapshot
158+
vault operator raft snapshot save /tmp/manual-backup.snap
159+
```
160+
161+
### Configuration & Environment
162+
```bash
163+
# Check Vault config file
164+
cat /etc/vault.d/vault.hcl
165+
166+
# Verify environment variables
167+
cat /etc/vault.d/vault.env
168+
169+
# Check if VAULT_ADDR is set in current shell
170+
echo $VAULT_ADDR
171+
172+
# Test network connectivity to Vault
173+
curl -k -I -L https://localhost:8200
174+
```
175+
176+
### TLS Certificates
177+
```bash
178+
# Test TLS connection
179+
openssl s_client -connect localhost:8200 -showcerts
180+
```
181+
182+
### Audit & Logs
183+
```bash
184+
# Check audit device status
185+
vault audit list
186+
187+
# View audit log (if file backend enabled)
188+
tail -f /var/log/vault_audit.log | jq
189+
```
190+
191+
### Authentication & Tokens
192+
```bash
193+
# Login with root token
194+
vault login
195+
196+
# Check token info
197+
vault token lookup
198+
199+
# Renew current token
200+
vault token renew
201+
202+
# List token accessors
203+
vault list auth/token/accessors
204+
```
205+
206+
### Secrets Engines
207+
```bash
208+
# List enabled secrets engines
209+
vault secrets list
210+
211+
# Check secrets engines
212+
vault secrets list -detailed
213+
```
214+
215+
### Performance & Metrics
216+
```bash
217+
# Prometheus metrics endpoint (if enabled)
218+
curl -sk https://localhost:8200/v1/sys/metrics?format=prometheus
219+
```
220+

0 commit comments

Comments
 (0)