fix(openbao): validate the publish bind before writing any state
deploy.sh narrows the Docker publish bind to OPENBAO_ADDR when that is an IP, but never checked that the host actually holds that address. A typo'd IP therefore failed late, inside `docker compose up`: failed to bind host port 192.160.100.50:8200/tcp: cannot assign requested address ...by which point .env had been seeded and the TLS cert generated with the bad address in its SAN. Neither is rewritten on a re-run (.env is never overwritten, gen-tls.sh never regenerates over an existing pair), so re-running with a corrected OPENBAO_ADDR silently changed nothing. Add host_addrs() + check_bind_addr(), run before anything is written: - lists the host's addresses from plain `ip addr show` -- no -o/scope filters, since busybox ip supports neither -- falling back to ifconfig, and skipping the check when neither exists rather than blocking; - skips 0.0.0.0 / :: / *, and unwraps an [IPv6] publish literal; - SKIP_BIND_CHECK=1 overrides for an address that only comes up later. Resolve the bind compose will really interpolate, which follows compose's own precedence -- shell environment before .env: - exported (automations.sh passes answers via `env VAR=...`, or a standalone OPENBAO_BIND=... run): the environment wins, so warn when .env disagrees, because a later bare `docker compose up` would not; - derived here: that assignment is not exported, so .env wins; - in neither: compose falls back to 0.0.0.0 and publishes the API on every interface -- warn, since that is a silent exposure. Also warn when .env's OPENBAO_ADDR differs from this run's, naming the cert that has to be deleted for the SAN to be regenerated. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a3843d3d85
commit
920edc50b3
2 files changed
+112
-1
No files matched your search
@@ -25,7 +25,7 @@ internet.
|
||||
| Variable | Notes |
|
||||
|----------|-------|
|
||||
| `OPENBAO_ADDR` | IP/DNS the Kanrisha tape host uses to reach this vault (goes in the cert SAN; you point the daemon at `https://$OPENBAO_ADDR:8200`). |
|
||||
| `OPENBAO_BIND` | Host interface the API publishes on. Left at the default, deploy.sh narrows it to `OPENBAO_ADDR` when that is an IP (a published port bypasses the INPUT firewall, so this bind is the real restriction — see [Exposure](#exposure)). |
|
||||
| `OPENBAO_BIND` | Host interface the API publishes on. Left at the default, deploy.sh narrows it to `OPENBAO_ADDR` when that is an IP (a published port bypasses the INPUT firewall, so this bind is the real restriction — see [Exposure](#exposure)). It must be an address this host actually holds — deploy.sh checks that before writing anything and refuses otherwise (`SKIP_BIND_CHECK=1` to override). |
|
||||
| `OPENBAO_TLS_SANS` | **Extra** SANs beyond `OPENBAO_ADDR` + loopback (which deploy.sh always adds). Read from the environment at deploy time — `export` it before running deploy.sh. |
|
||||
| `OPENBAO_TAG` | OpenBao image tag (pin it). |
|
||||
| `OPENBAO_HSM_PIN` | Only for PKCS#11 auto-unseal. Leave blank for manual unseal. |
|
||||
@@ -57,6 +57,34 @@ docker compose exec -e BAO_ADDR=https://127.0.0.1:8200 openbao \
|
||||
**Store the unseal keys + root token out of band** — ideally age-encrypted with
|
||||
your backup recipient (`globals/age-pubkey.txt`), never on this host.
|
||||
|
||||
### Re-running after a wrong address
|
||||
|
||||
`deploy.sh` is idempotent, but two things it writes are deliberately **sticky**:
|
||||
`.env` (never overwritten) and `tls/tls.{crt,key}` (never regenerated over an
|
||||
existing pair). So passing a corrected `OPENBAO_ADDR` to a re-run does *not* move
|
||||
the vault — the cert keeps the old SAN, and the old `.env` usually still decides
|
||||
the bind. Which `OPENBAO_BIND` wins follows Compose's own precedence:
|
||||
|
||||
| How `OPENBAO_BIND` is set | What Compose uses |
|
||||
|---------------------------|-------------------|
|
||||
| Exported into deploy.sh's environment (`OPENBAO_BIND=… bash deploy.sh`, or answering the bind prompt — `automations.sh` passes answers via `env VAR=…`) | the **environment** value; `.env` is ignored for this run, so a later hand-run `docker compose up -d` can bind somewhere else |
|
||||
| Derived by deploy.sh (bind prompt left blank → narrowed to `OPENBAO_ADDR`) | the **`.env`** value, since that assignment is never exported |
|
||||
| Absent from both | `0.0.0.0` — **all interfaces** |
|
||||
|
||||
deploy.sh warns on each of those mismatches. To actually change the address:
|
||||
|
||||
```bash
|
||||
cd /srv/openbao
|
||||
docker compose down # keeps the raft volume
|
||||
sed -i 's/OLD_IP/NEW_IP/g' .env # OPENBAO_ADDR + OPENBAO_BIND
|
||||
rm -f tls/tls.crt tls/tls.key # force a new SAN
|
||||
# then re-run deploy.sh with the corrected OPENBAO_ADDR
|
||||
```
|
||||
|
||||
A bind address the host does not hold is caught up front; without that check
|
||||
Docker fails the `up` with `cannot assign requested address` only *after* the
|
||||
bad value is already in `.env` and the cert.
|
||||
|
||||
## TLS
|
||||
|
||||
- **Self-signed (default):** `deploy.sh` runs [`gen-tls.sh`](gen-tls.sh) to
|
||||
|
||||
Reference in new issue
Block a user