Skeleton contracts / contracts (pull_request) Blocked by required conditions
39 lines
3.5 KiB
Markdown
39 lines
3.5 KiB
Markdown
# OpenBao: local operator bootstrap
|
|
|
|
The Compose service uses OpenBao 2.3.1, a file storage volume, TLS and non-dev mode. The first initialization and every unseal are operator actions. Install the matching `bao` CLI and OpenSSL locally. Generate the stack certificates with `pwsh -File infra/tls/bootstrap.ps1`, create `.env` from `.env.example`, then start only the dependency first:
|
|
|
|
```powershell
|
|
docker compose --env-file .env up -d openbao
|
|
```
|
|
|
|
Use a separate operator shell. Do not save its history or paste these values into Git/chat/logs. With `BAO_ADDR=https://localhost:8200` and `BAO_CACERT=secrets/openbao/bao-ca.crt`, initialize once and save the printed unseal shares and initial root token in the operator's offline secret store. Never put them in the project folder. Unseal after each OpenBao restart; then authenticate as operator and configure:
|
|
|
|
```sh
|
|
bao operator init -key-shares=5 -key-threshold=3
|
|
bao operator unseal
|
|
bao login
|
|
bao secrets enable -path=secret -version=2 kv
|
|
bao policy write messenger-api infra/openbao/api-policy.hcl
|
|
bao policy write messenger-worker infra/openbao/worker-policy.hcl
|
|
bao auth enable approle
|
|
bao write auth/approle/role/messenger-api token_policies=messenger-api token_ttl=15m token_max_ttl=1h secret_id_ttl=24h secret_id_num_uses=0
|
|
bao write auth/approle/role/messenger-worker token_policies=messenger-worker token_ttl=15m token_max_ttl=1h secret_id_ttl=24h secret_id_num_uses=0
|
|
```
|
|
|
|
Create distinct MinIO service keys and write them with the KV v2 API. The `s3-bootstrap` service creates separate API and worker identities and attaches prefix-scoped policies; store each identity only at its corresponding KV path.
|
|
|
|
```sh
|
|
bao kv put secret/messenger/api s3_access_key="$S3_ACCESS_KEY" s3_secret_key="$S3_SECRET_KEY" db_username=messenger_api db_password="$POSTGRES_API_PASSWORD"
|
|
bao kv put secret/messenger/worker s3_access_key="$S3_WORKER_ACCESS_KEY" s3_secret_key="$S3_WORKER_SECRET_KEY" db_username=messenger_worker db_password="$POSTGRES_WORKER_PASSWORD"
|
|
bao read -field=role_id auth/approle/role/messenger-api/role-id > secrets/openbao-api/role_id
|
|
bao write -f -field=secret_id auth/approle/role/messenger-api/secret-id > secrets/openbao-api/secret_id
|
|
bao read -field=role_id auth/approle/role/messenger-worker/role-id > secrets/openbao-worker/role_id
|
|
bao write -f -field=secret_id auth/approle/role/messenger-worker/secret-id > secrets/openbao-worker/secret_id
|
|
```
|
|
|
|
The app role credentials are separate local runtime files, mounted read-only only into their respective service and excluded from Git. The API reads only `secret/data/messenger/api`; the worker requests only `secret/data/messenger/worker`. Neither receives operator credentials. `src/bao.py` uses AppRole and verifies the OpenBao certificate. Do not print its token or secret response. To check deny behavior, use an application token and verify `bao kv get secret/messenger/worker` is denied from the API role and `bao kv put ...` is denied for both roles.
|
|
|
|
After setting up OpenBao, start the full stack. On a later OpenBao restart, unseal it with the operator shares before restarting app containers. If the server is sealed/unavailable, startup fails closed and the API/worker will not start with fallback credentials. For rotation, update KV and re-create the local AppRole SecretID; restart affected application processes on level 3. Automated renewal and no-restart rotation are level 4.
|
|
|
|
These commands require local operator preparation; no root token, unseal shares, SecretID or private key is supplied in this repository.
|