Parses literal exports from ~/.zshrc (never sourced), writes them to env/shell/<group> via the bao CLI with stdin transport, verifies by SHA-256 digest, then creates a read-only policy/token and generates the EnvBao config. Values are never printed, logged or placed in argv. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2.3 KiB
2.3 KiB
Migrating secrets from ~/.zshrc into OpenBao
scripts/migrate_zshrc.py is a one-off helper (stdlib only, not part of the binary). It needs the
bao CLI and BAO_ADDR / BAO_TOKEN in the environment with enough rights to write the target
KV mount and to create a policy and token (e.g. a root or admin token).
What it does
- Parses
~/.zshrcas text (never sourced). Only column-0export NAME=valuelines with literal values are considered; values needing shell expansion ($HOME,$(...), backticks) are skipped and reported by name. - Groups variables by name prefix into
<mount>/shell/<group>(AWS_*→aws,PROTON_BRIDGE_*→proton,GITHUB_*,GITEA_*,ELASTIC_*,PHOTOS_*,PKGS_*,WIKI_*,YOUTRACK_*). Toolchain variables (PATH,ZSH,LDFLAGS,CPPFLAGS,NVM_DIR) andBAO_TOKEN/BAO_ADDRare never migrated. Unrecognised names are listed; map them with--group NAME=group. - Writes each group with
bao kv put(JSON on stdin, so values never appear inps), refusing to overwrite an existing secret unless--force, then reads it back and compares SHA-256 digests. - Creates the read-only policy
envbao-shell, mints an orphan periodic token (720h) for it, and writes~/.envbao/tokenand~/.envbao/config.toml(0600, directory 0700; any previous config is saved asconfig.toml.bak), then runsenvbao --check.
Values are never printed or logged; bao error output is scrubbed of known secrets.
Usage
uv run python scripts/migrate_zshrc.py # dry run: names and line numbers only
uv run python scripts/migrate_zshrc.py --apply # write, verify, generate EnvBao config
Options: --zshrc PATH, --mount NAME (default env; must already exist as a KV engine),
--force, --group NAME=group, --config-dir DIR, --no-check.
Afterwards
- Remove the listed line numbers from
~/.zshrcand addcommand -v envbao >/dev/null && eval "$(envbao)". - Open a new shell and confirm the variables are present.
- Rotate the credentials. They lived in plaintext, in shell history/backups, and (if you used an AI assistant on that file) possibly in its transcripts.
- The generated token period is 720h: renew it (
bao token renew) or re-run the helper with--forceto issue a new one before it lapses.