Add Claude access setup, onedir build and native packages

- scripts/setup_claude_access.py: narrow envbao-claude policy/token and an
  exec_only claude.toml; optional merge of Claude Code settings
- [security] exec_only refuses plain export mode and --no-redact
- PyInstaller onedir build (~0.06s start-up vs ~1.4s onefile)
- macOS .pkg, Debian/Ubuntu/Raspberry Pi OS .deb (pure-Python builder),
  tarball + scripts/install.sh; release pipeline updated
- docs: claude-access, install matrix, releasing, usage, security

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
mattandClaude Sonnet 5.5 committed 2026-10-16 11:57:47 +01:00
1 parent 08bacbc5a8
commit 952fa2ce63
22 files changed
+1110 -44

No files matched your search

+72
View File
@@ -0,0 +1,72 @@
# Using EnvBao credentials from Claude Code
Goal: let Claude Code *use* your credentials (call an API, push to a repo, query a service)
without the secret values ever entering the conversation transcript, and without handing it
your admin token.
## How it works
```
Claude ──▶ envbao exec -q gitea -- curl -H "Authorization: token $GITEA_TOKEN" …
│ 1. reads ~/.envbao/claude.toml ($ENVBAO_CONFIG)
│ 2. fetches ONLY group "gitea" with Claude's own narrow token
│ 3. runs the command with GITEA_TOKEN in its environment
└─ 4. replaces secret values in stdout/stderr with ***
```
* **Narrow token.** `scripts/setup_claude_access.py` creates the policy `envbao-claude` (read on
`env/shell/<group>` only) and an orphan, periodic token named `envbao-claude`. Revoke it at any
time without touching your own token.
* **`exec_only`.** The generated `claude.toml` sets `[security] exec_only = true`: plain
`envbao` (which prints `export` lines for everything) and `--no-redact` are refused.
* **Redaction.** Secret values (6+ characters; raw, JSON-escaped and URL-encoded forms) are masked
in the command's output, including across read boundaries.
* **Permissions.** Optional Claude Code rules deny `bao`, and reading `~/.envbao/**` and
`~/.zshrc`, so the only route to a secret is `envbao exec`.
* **Audit.** Every `exec` is logged (groups and the program name, never arguments or values) in
`~/.envbao/envbao.log`, and OpenBao's own audit device attributes reads to the
`envbao-claude` token.
## Setup (once)
With an admin `BAO_ADDR`/`BAO_TOKEN` in your shell:
```sh
uv run python scripts/setup_claude_access.py # policy, token, ~/.envbao/claude.toml
uv run python scripts/setup_claude_access.py --settings # also update ~/.claude/settings.json
```
Options: `--groups gitea,youtrack` (default: every group under `shell/`), `--mount`, `--force`.
`--settings` sets `ENVBAO_CONFIG` for Claude's sessions and merges these permission rules (a
`.bak` copy of the file is kept):
```json
{
"permissions": {
"allow": ["Bash(envbao exec:*)"],
"deny": ["Bash(bao:*)", "Read(~/.envbao/**)", "Read(~/.zshrc)"]
}
}
```
Then **remove the root `BAO_TOKEN`/`BAO_ADDR` exports from `~/.zshrc`**: every process started from
your shell, including Claude's tools, inherits them.
## Using it
```sh
envbao exec -q youtrack -- curl -s -H "Authorization: Bearer $YOUTRACK_TOKEN" "https://$YOUTRACK_URL/api/users/me"
envbao exec -q gitea -q github -- ./deploy.sh
```
Note that `$VAR` inside the command line is expanded by the *calling* shell, before envbao runs. To
have the child expand it, quote it: `envbao exec -q gitea -- sh -c 'curl -H "Authorization: token $GITEA_TOKEN" …'`.
Group names are the last path segment (`shell/gitea` → `gitea`) unless a query sets `name`.
## Limits
Redaction is defence in depth, not a sandbox. A command that deliberately transforms a secret
(base64, hashing, splitting it across lines) or sends it to a remote service defeats the filter.
Only grant Claude groups you are comfortable with it using; to narrow later, edit the
`envbao-claude` policy and `claude.toml` (re-run the setup script with `--groups … --force`).
`aws` and `proton` (cloud keys and your mail bridge password) are the most sensitive groups.
+3 -1
View File
@@ -1,6 +1,6 @@
# Configuration reference
File: `~/.envbao/config.toml`. Unknown keys and wrong types are rejected, so typos fail loudly.
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]`
@@ -19,6 +19,7 @@ File: `~/.envbao/config.toml`. Unknown keys and wrong types are rejected, so typ
| 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]]`
@@ -29,6 +30,7 @@ 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. |
+12 -1
View File
@@ -26,6 +26,8 @@ uv run pytest --cov # fails below 90 % coverage
| `resolve.py` | Runs queries, applies keys/rename/prefix, filters unsafe names |
| `render.py` | Name validation, quoting, shell dialects |
| `logging_setup.py` | stderr, private rotating file, syslog |
| `runner.py` | `exec`: secret selection, output redaction, process handling |
| `version.py` | Release/stamped version, git-derived version for checkouts |
| `errors.py` | Exceptions and exit codes |
## Testing approach
@@ -39,7 +41,7 @@ uv run pytest --cov # fails below 90 % coverage
```sh
uv run pyinstaller envbao.spec --clean --noconfirm
./dist/envbao --version
./dist/envbao/envbao --version
```
PyInstaller cannot cross-compile; build on the platform you target.
@@ -53,3 +55,12 @@ bao kv put -mount=secret myapp/prod DB_URL=postgres://x API_KEY=abc
envbao --init # then set address/token, add a [[query]] for secret/myapp/prod
envbao --check && envbao
```
## Packaging locally
```sh
python3 scripts/packaging/build_deb.py 0.2.0 arm64 dist out # .deb (pure Python, any OS)
sh scripts/packaging/build_pkg.sh 0.2.0 dist out # macOS .pkg (needs pkgbuild)
```
The binary inside is for the OS you built on, so only ship packages built on the matching runner.
+12 -8
View File
@@ -6,10 +6,13 @@
90 % coverage gate, and a PyInstaller build smoke test.
- **`release.yml`** - on a pushed tag `vMAJOR.MINOR.PATCH[-prerelease][+build]` ([SemVer 2.0.0](https://semver.org)):
1. `validate` rejects tags that are not valid SemVer (`scripts/version_from_tag.py`).
2. `build` runs tests then builds `envbao` with PyInstaller on each runner, stamping the version
from the tag into the binary and checking `envbao --version` matches.
3. `release` writes `SHA256SUMS` and creates a Gitea release (marked *prerelease* if the tag has a
`-suffix`) with all binaries attached.
2. `build` runs tests then builds the one-directory `envbao` app with PyInstaller on each runner,
stamping the version from the tag and checking `envbao --version` matches. It then packages it:
`envbao-<ver>-<target>.tar.gz` everywhere, plus `envbao_<ver>_<arch>.deb` (linux, built in pure
Python by `scripts/packaging/build_deb.py`) or `envbao-<ver>-macos-arm64.pkg` (macOS, via
`pkgbuild` in `scripts/packaging/build_pkg.sh`).
3. `release` writes one `SHA256SUMS` and creates a Gitea release (marked *prerelease* if the tag
has a `-suffix`) with all packages attached.
## Cutting a release
@@ -41,7 +44,8 @@ Runners need network access to fetch `astral-sh/setup-uv` and Python packages.
## Notes
- `actions/upload-artifact@v3` / `download-artifact@v3` are used because Gitea does not yet support v4.
- Linux binaries link against the glibc of the build host; build on the oldest distro you want to
support.
- macOS binaries are unsigned; first run may need `xattr -d com.apple.quarantine envbao` if downloaded
through a browser.
- Linux builds link against the glibc of the build host, and the `.deb` declares `libc6 (>= 2.31)`:
keep the Linux runners on Debian 11 / Ubuntu 20.04 or newer, ideally the oldest you want to
support. Pre-release tags map to Debian `~` versions (`1.0.0-rc.1` → `1.0.0~rc.1`).
- Raspberry Pi OS 64-bit is covered by the arm64 `.deb`; 32-bit (armhf) would need an armv7 runner.
- The macOS `.pkg` is unsigned and not notarised; install with `sudo installer -pkg … -target /`.
+7 -1
View File
@@ -31,12 +31,18 @@ variables are exported (any child process inherits them).
syslog for WARNING and above. Events: permission violations, auth failures, per-query outcome,
overrides, refused variables, count of exported variables.
8. **`exec` mode** - `envbao exec` injects only the requested groups into one child process and masks
their values (raw, JSON, URL-encoded) in its output; with `[security] exec_only = true` plain
export mode and `--no-redact` are refused. Masking is defence in depth, not a sandbox (see
[claude-access.md](claude-access.md)).
## Recommendations
- Use a token with a narrow read-only policy and a TTL; renew it periodically.
- Prefer `token_file` if you want to rotate the token without editing the config.
- Keep `~/.envbao` out of backups/sync tools that change permissions.
- Verify release binaries against `SHA256SUMS`.
- Verify release packages against `SHA256SUMS`.
- Do not keep a root/admin `BAO_TOKEN` exported in your shell profile.
## Reporting a vulnerability
+13
View File
@@ -2,6 +2,7 @@
```
envbao [--config PATH] [--shell {auto,bash,zsh,sh,fish}] [-v|-vv] [--check | --init]
envbao [options] exec -q GROUP [-q GROUP ...] [--no-redact] -- COMMAND [ARGS ...]
envbao --version
```
@@ -14,6 +15,18 @@ envbao --version
| `--init` | Create `~/.envbao` (0700) and a template `config.toml` (0600). Never overwrites. |
| `-v` / `-vv` | Show INFO / DEBUG messages on stderr. |
## `exec`: run a command with secrets
```sh
envbao exec -q gitea -q youtrack -- ./script.sh
```
Fetches only the named groups (see `name` in the configuration reference), runs `COMMAND` with
them as environment variables, and returns the command's exit status. Its stdout/stderr are filtered
so secret values appear as `***`; `--no-redact` replaces the process with the command instead (not
available when `exec_only` is set). Nothing runs if any selected group cannot be fetched. See
[claude-access.md](claude-access.md).
## Shell integration
bash / zsh: