Files
EnvBao/docs/configuration.md
mattandClaude Sonnet 5.5 0cde1ff7f7
release / validate (push) Successful in 5s
test / test (push) Successful in 1m6s
release / build (, macos-arm64, macos-arm64) (push) Successful in 1m20s
release / build (amd64, linux-amd64, linux-amd64) (push) Successful in 1m7s
release / build (arm64, linux-arm64, linux-arm64) (push) Successful in 2m2s
release / release (push) Successful in 26s
Add database, aws, approle and ssh engines with credential caching
New OpenBao credential engines (database/PostgreSQL, aws, approle, ssh)
backed by a POST-capable BaoClient. Queries can set cache = true on
dynamic database and aws roles to reuse the credential until near lease
expiry (file store by default, optional keychain), revoking the old lease
on refresh. Adds [cache] store and --clear-cache.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-09 13:24:47 +00:00

114 lines
5.6 KiB
Markdown

# Configuration reference
File: `~/.envbao/config.toml`, or the path in `--config` / the `ENVBAO_CONFIG` environment variable (the flag wins). Unknown keys and wrong types are rejected, so typos fail loudly.
## `[server]`
| Key | Type | Default | Description |
|-----|------|---------|-------------|
| `address` | string | *required* | Base URL, e.g. `https://bao.example.com:8200`. No credentials in the URL. |
| `token` | string | | OpenBao token. Exactly one of `token` / `token_file` is required. |
| `token_file` | string | | Path (`~` expanded) to a file containing the token. Must pass the same permission policy (owner only, not a symlink). |
| `namespace` | string | | Sent as `X-Vault-Namespace`. |
| `ca_cert` | string | system store | PEM CA bundle used to verify the server. |
| `timeout` | number | `5` | Per-request timeout in seconds. |
| `allow_insecure_http` | bool | `false` | Permit `http://` to a non-loopback host. Loopback (`127.0.0.1`, `::1`, `localhost`) is always allowed over HTTP. Not recommended: the token travels in clear. |
## `[security]`
| Key | Type | Default | Description |
|-----|------|---------|-------------|
| `allow_protected` | list of strings | `[]` | Protected variable names (see [security.md](security.md)) that secrets may set, e.g. `["PATH"]`. |
| `exec_only` | bool | `false` | Refuse plain `envbao` (which prints every value) and `exec --no-redact`; only redacted `envbao exec` and `--check` work. Used by the Claude profile. |
## `[[query]]`
One table per secret source. Queries run in order; later ones override earlier ones.
Common keys:
| Key | Type | Default | Description |
|-----|------|---------|-------------|
| `engine` | string | `"kv"` | Secret engine. Currently only `kv`. |
| `name` | string | last `path` segment | Group name for `envbao exec -q NAME` (letters, digits, `.` `_` `-`). |
| `keys` | list of strings | all | Only export these keys from the secret. |
| `rename` | table | `{}` | Map secret key → variable name. Applied before `prefix`. |
| `prefix` | string | `""` | Prepended to every variable name. |
| `on_missing` | `"warn"` \| `"error"` | `"warn"` | What to do if the secret or a listed key does not exist. `error` aborts the whole run. |
### `engine = "kv"`
| Key | Type | Default | Description |
|-----|------|---------|-------------|
| `mount` | string | *required* | KV mount path, e.g. `secret`. |
| `path` | string | *required* | Secret path within the mount. |
| `kv_version` | `1` \| `2` \| `"auto"` | `"auto"` | `auto` queries `sys/internal/ui/mounts/<mount>`; set explicitly if the token cannot read that endpoint. |
Names that are not valid variable names (`[A-Za-z_][A-Za-z0-9_]*`) are skipped with a warning.
## Credential engines
Besides `kv`, queries can use `engine = "database" | "aws" | "approle" | "ssh"`. They go through the
same `[server]` and are filtered/renamed/prefixed like KV data. Only credential fields are exported;
lease metadata is dropped. Variable names are the returned field names, so use `rename` (or `prefix`)
to get the names your tools expect.
```toml
[[query]] # PostgreSQL via the OpenBao database engine
engine = "database"
role = "readonly" # required; mount defaults to "database"
# static = true # read static-creds/<role> instead of creating a user
name = "pg"
rename = { username = "PGUSER", password = "PGPASSWORD" }
[[query]]
engine = "aws" # role required; mount "aws"; kind = "creds" | "sts"; ttl = "15m"
role = "deploy"
rename = { access_key = "AWS_ACCESS_KEY_ID", secret_key = "AWS_SECRET_ACCESS_KEY", security_token = "AWS_SESSION_TOKEN" }
[[query]]
engine = "approle" # role required; mount "approle"; what = "both" | "role_id" | "secret_id"
role = "web"
[[query]]
engine = "ssh" # otp (default): needs ip; sign: needs public_key_file
role = "ops"
ip = "10.0.0.5"
```
### Caching dynamic credentials (`cache = true`)
Dynamic credentials are created on every fetch (a new database user or IAM user each time), which
would make `eval "$(envbao)"` in a shell startup file mint one per shell. Add `cache = true` to a
`database` (non-`static`) or `aws` query to reuse the credential until shortly before its lease
expires:
```toml
[cache]
store = "file" # default. "keychain" (fail if unavailable) or "auto" (keychain, else file)
[[query]]
engine = "database"
role = "readonly"
cache = true
```
* The credential is reused while more than `max(60s, 10% of the lease)` remains. After that a new one
is fetched and the old lease is revoked (best effort; it expires on its own if the token may not
call `sys/leases/revoke`).
* Storage (`[cache] store`): `file` (default) keeps a `0600` file in `~/.envbao/cache/`; `keychain` uses
the macOS Keychain (`security`) or Linux secret service (`secret-tool`) and fails if unavailable;
`auto` tries the keychain and falls back to the file. Secrets are never put on a command line.
* The key covers server address, namespace, engine and options; it ignores the token, so rotating
the token keeps the cache valid.
* `cache = true` is rejected for `kv`, `approle`, `ssh` (one-time passwords and certificates have no
reusable lease) and `database` with `static = true`.
* Without `cache = true`, prefer `envbao exec -q pg -- command` for dynamic engines.
* `envbao --clear-cache` revokes and deletes the cached credentials.
## Adding an engine
Implement `envbao.engines.Engine` (`validate` and `fetch`) in a new module under
`src/envbao/engines/`, register it in `ENGINES`, and document its options here. Filtering,
renaming, prefixing, name validation and rendering are shared.