Add database, aws, approle and ssh engines with credential caching
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

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>
This commit is contained in:
mattandClaude Sonnet 5.5 committed 2026-11-09 13:24:47 +00:00
1 parent 78ff2b0ddd
commit 0cde1ff7f7
20 files changed
+1708 -29

No files matched your search

+60
View File
@@ -46,6 +46,66 @@ Common keys:
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