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

+21 -4
View File
@@ -14,6 +14,7 @@ import sys
from collections.abc import Sequence
from pathlib import Path
from envbao.cache import CACHE_DIR_NAME, CredentialCache, make_store
from envbao.client import BaoClient
from envbao.config import Config, load_config, resolve_config_path
from envbao.errors import EXIT_FAILURE, EXIT_OK, ConfigError, EnvBaoError, PermissionPolicyError
@@ -85,6 +86,11 @@ def build_parser() -> argparse.ArgumentParser:
action="store_true",
help="create ~/.envbao with safe permissions and a template config.toml",
)
mode.add_argument(
"--clear-cache",
action="store_true",
help="revoke and delete cached dynamic credentials, then exit",
)
parser.add_argument("-v", "--verbose", action="count", default=0, help="log more to stderr")
parser.add_argument("--version", action=_VersionAction)
@@ -132,12 +138,17 @@ def _check(config: Config, client: BaoClient) -> None:
)
def _build_cache(config: Config, config_dir: Path) -> CredentialCache:
store = make_store(config.cache_store, config_dir)
return CredentialCache(store, config_dir / CACHE_DIR_NAME / ".lock")
def run(args: argparse.Namespace) -> int:
"""Execute the requested action and return the exit status."""
path = resolve_config_path(args.config)
if args.command == "exec" and (args.check or args.init):
raise ConfigError("--check/--init cannot be combined with exec")
if args.command == "exec" and (args.check or args.init or args.clear_cache):
raise ConfigError("--check/--init/--clear-cache cannot be combined with exec")
if args.init:
try:
init_config(path)
@@ -159,6 +170,12 @@ def run(args: argparse.Namespace) -> int:
_check(config, client)
return EXIT_OK
cache = _build_cache(config, path.parent) if any(q.cache for q in config.queries) else None
if args.clear_cache:
count = _build_cache(config, path.parent).clear(client, config)
sys.stderr.write(f"envbao: cleared {count} cached credential(s)\n")
return EXIT_OK
if config.exec_only and args.command != "exec" and not args.check:
raise ConfigError("this configuration only permits 'envbao exec' (security.exec_only)")
if args.command == "exec":
@@ -166,11 +183,11 @@ def run(args: argparse.Namespace) -> int:
raise ConfigError("--no-redact is not permitted (security.exec_only)")
argv = args.argv[1:] if args.argv[:1] == ["--"] else args.argv
queries = select_queries(config, args.query)
secrets = fetch_secrets(client, config, queries)
secrets = fetch_secrets(client, config, queries, cache)
log.info("exec: groups %s", ", ".join(q.name for q in queries))
return run_command(argv, secrets, redact=not args.no_redact)
env = resolve(client, config)
env = resolve(client, config, cache)
shell = detect_shell() if args.shell == "auto" else args.shell
output = render(env, shell)
log.info("exported %d variable(s) for %s", len(env), shell)