Fetches only the named groups, injects them into the child environment and filters secret values (raw, JSON, URL-encoded) from stdout/stderr. Queries gain an optional 'name'; ENVBAO_CONFIG selects an alternative config. Includes plan 002. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
8.4 KiB
Let Claude use OpenBao credentials via envbao exec, plus faster startup
Context
Credentials now live in OpenBao (env/shell/<group>). The user wants Claude Code to be able to use them. Findings:
- Going through the
envbaobinary is fine functionally, but the PyInstaller onefile binary re-extracts itself on every call (~1.4 s measured, also paid on every shell start via.zshrc). - Letting Claude run
bao kv getor inherit the shell env puts every secret value into the transcript. This session already shows the risk:BAO_TOKENin the shell env is a root token, visible to any Claude command. - Chosen model: a run-with-secrets wrapper. Claude names the groups it needs;
envbao execfetches only those and runs the command with them in its environment; output is redacted so values never reach the transcript. Claude gets its own narrow token, not the root/shell one.
User choices: access via envbao exec wrapper; all nine groups allowed (gitea, github, youtrack, wiki, pkgs, elastic, photos, aws, proton — aws/proton flagged as highest-sensitivity, can be narrowed later by one policy edit); switch release to onedir for startup time.
Step 0 (first action once approved)
Copy this plan verbatim to the repo as docs/plans/002-claude-access-and-packaging.md (plan mode only allows writing the plan file; the user wants all plans kept in docs/plans/) and include it in the first commit.
1. envbao exec (new subcommand)
envbao [--config PATH] exec -q GROUP [-q GROUP …] [--no-redact] -- CMD [ARGS…](also--allis deliberately not provided).- Config: add optional
nameto[[query]](default = last path segment, e.g.shell/gitea→gitea); names must be unique (validated inconfig.py).-qselects queries by name; unknown name → exit 78 with list of valid names. - Reuses
resolve.run_query/BaoClient/ protected-variable filtering (src/envbao/resolve.py), same permission check (security.check_config_dir), fail-closed (no command run if any selected query fails). - Execution: build
env = os.environ | secrets; run the child withsubprocess.Popen, inherit stdin, pipe stdout/stderr through a redactor that replaces every secret value (len ≥ 6) with***, handling matches split across chunk boundaries via a rolling buffer; forward SIGINT/SIGTERM; propagate the child's exit code (127 if not found).--no-redactusesos.execvpe(exact exec, TTY-friendly) for interactive humans. - Audit log (
envbao.log/syslog): groups requested,argv[0]only (never arguments), exit status. Never values. - Files:
src/envbao/cli.py(subparser), newsrc/envbao/runner.py(env build, redactor, process handling),src/envbao/config.py(name),tests/test_runner.py,tests/test_cli.py.
2. Claude-specific credentials (provisioning script)
New scripts/setup_claude_access.py (uses the admin BAO_TOKEN once, like migrate_zshrc.py; reuse its Bao wrapper, write_private, install_config, policy_text patterns):
- Policy
envbao-claude: read onenv/data/shell/<g>for each allowed group +auth/token/lookup-self(+sys/internal/ui/mounts/env). - Token: orphan, periodic 720h,
display-name=envbao-claude, written to~/.envbao/claude-token(0600); never printed. ~/.envbao/claude.toml(0600) with the nine named queries pointing at that token file; existing files backed up, never overwritten without--force.- Reports whether an OpenBao audit device is enabled (
bao audit list) and says how to enable one if not (does not enable it unasked). - Optionally merges into
~/.claude/settings.json(backup first, JSON merge, shown as a diff before writing):env.ENVBAO_CONFIG=~/.envbao/claude.toml(new env var honoured byresolve_config_path),permissions.allow: ["Bash(envbao exec:*)"],permissions.deny: ["Bash(bao:*)", "Read(~/.envbao/**)", "Read(~/.zshrc)"]. - Tests with the stub-
baoapproach fromtests/test_migrate_zshrc.py.
3. Startup time: PyInstaller onedir
envbao.spec: switch toCOLLECT(onedir;exclude_binaries=True), outputdist/envbao/.release.yml/test.yml: smoke-testdist/envbao/envbao --version; packageenvbao-<ver>-<target>.tar.gz(directoryenvbao/), checksum those; release assets become tarballs.scripts/install.sh(new, POSIX sh): verify checksum ifSHA256SUMSpresent, extract to~/.local/lib/envbao/, symlink~/.local/bin/envbao→~/.local/lib/envbao/envbao, clear macOS quarantine flag, printenvbao --version. (This is where the symlink the user asked about earlier actually belongs.)- Verify startup drops well below the current 1.4 s (target ≲0.3 s).
3b. Native packages (so no folders need moving by hand)
The onedir build is a folder, so ship installable packages that place it and create the envbao symlink themselves:
- macOS
.pkg(built on themacos-arm64runner withpkgbuild --root … --identifier dev.daubney.envbao --version <ver> --install-location /usr/local/lib/envbao, plus apostinstallscript that symlinks/usr/local/bin/envbao→/usr/local/lib/envbao/envbaoand clears the quarantine flag). Unsigned/not notarised; docs notesudo installer -pkg … -target /(avoids the Gatekeeper prompt) or right-click → Open. Uninstall scriptscripts/packaging/uninstall-macos.sh. - Debian/Ubuntu/Raspberry Pi OS
.deb(built withdpkg-deb --buildfrom a staged tree, no extra tooling): files in/opt/envbao/, symlink/usr/bin/envbao,DEBIAN/control(Package: envbao,Versionfrom the tag with-prerelease mapped to~,Architecture: amd64|arm64,Depends: libc6, maintainer, description),postrmremoves nothing outside the package. Built onlinux-amd64(Debian/Ubuntu x86-64) andlinux-arm64(Ubuntu arm64 and 64-bit Raspberry Pi OS). 32-bit Raspberry Pi OS (armhf) is not covered — would need an armv7 runner; documented as unsupported. - glibc compatibility: Linux builds link to the build host's glibc; document the minimum (build on the oldest Debian/Ubuntu runner, ideally bookworm/22.04) in
docs/releasing.md. - New
scripts/packaging/(build_deb.sh,build_pkg.sh,postinstall,control.in) with tests that stage the tree and inspect it (dpkg-deb -c/--infowhere available;pkgutil --payload-fileson macOS; otherwise unit-test the generated control/postinstall text and the version mapping function). release.ymlmatrix produces per target:envbao_<ver>_amd64.deb,envbao_<ver>_arm64.deb,envbao-<ver>-macos-arm64.pkg, plus the generic.tar.gz+scripts/install.shfor other systems; oneSHA256SUMScovers all.- README Install section leads with:
sudo dpkg -i envbao_<ver>_<arch>.deb/sudo installer -pkg envbao-<ver>-macos-arm64.pkg -target /.
4. Docs & hygiene
- New
docs/claude.md(model, setup, how Claude should call it, redaction limits: a command can still exfiltrate a secret by transforming it, e.g. base64 — treat as defence in depth, not a sandbox); updatedocs/security.md,docs/configuration.md(name,ENVBAO_CONFIG),docs/usage.md(exec), README install section (tarball +install.sh),docs/releasing.md, CHANGELOG. - Recommend (and print in the setup script output) removing the root
BAO_TOKEN/BAO_ADDRexports from~/.zshrc(lines ≈2930–2931) so Claude and every child process stop inheriting a root token. Not edited automatically. - Next release: tag
v0.2.0after merging (tagging/pushing only when the user says so).
Verification
uv run pytest --cov(≥90%), ruff, mypy. Redactor tests: value split across chunks, multiple secrets, stderr, binary output, short values not redacted.envbao exec -q gitea -- sh -c 'echo $GITEA_TOKEN'prints***;-- sh -c 'test -n "$GITEA_TOKEN"'exits 0; unknown group exits 78 with no command run; exit codes propagate.- Run setup script; confirm
bao token lookupon the Claude token shows onlyenvbao-claudepolicy and that it is deniedenv/data/shell/<unlisted>andsys/policies. - Build onedir locally;
time dist/envbao/envbao --version; build the.pkglocally and inspect the payload (pkgutil --payload-files); build a.deblocally viadpkg-debif available (else in a Debian container) and check--info/-c; install viainstall.shinto a temp prefix. Pipeline run on tagv0.2.0produces all assets (checked after the user approves tagging/pushing). - From a Claude session with the new settings,
envbao exec -q youtrack -- curl …works and the transcript contains no secret value;bao kv get …is denied by permissions.