feat: support Bitwarden env alias mapping - #55886
Conversation
Related: part of the Bitwarden profile-scoped-secrets cluster with the open #51616 (canonical-aliasing in |
teknium1
left a comment
There was a problem hiding this comment.
Thanks for addressing a real profile-scoped secret problem. The current implementation needs to move to the active secret-source path before it can be salvaged.
Problems
hermes_cli/env_loader.py:341-346now delegates secret startup toregistry.apply_all(), which writes raw fetched names atagent/secret_sources/registry.py:339-368. The added mapping call is attached to the pre-registry direct Bitwarden path and therefore does not reach the current gateway startup flow.- The new tests mock legacy
apply_bitwarden_secrets; current active-loader tests mockfetch_bitwarden_secretsand exercise_apply_external_secret_sources()(tests/test_env_loader_secret_sources.py:91-105). - The proposed settings are not represented in
BitwardenSource.config_schema()(agent/secret_sources/bitwarden.py:616-640) or the Bitwarden config docs/example.
Suggested changes
- Rework mapping in the active
BitwardenSource/registry flow, preserving registry precedence, protected variables, and provenance. - Add an active-loader regression that proves
gateway/config.py:1501-1504receives canonicalDISCORD_BOT_TOKENand aliases are absent. - Coordinate the mapping contract with related open PRs #51616 and #50686 before defining docs/config surface.
Automated hermes-sweeper review.
| @@ -326,6 +423,11 @@ def _apply_external_secret_sources(home_path: Path) -> None: | |||
| server_url=str(bw_cfg.get("server_url", "") or "").strip(), | |||
There was a problem hiding this comment.
Current main no longer has this direct Bitwarden-result path: hermes_cli/env_loader.py:341-346 calls registry.apply_all(), which owns the actual environment writes. Please move aliasing into the active SecretSource/registry flow so it preserves precedence, protected-variable handling, and provenance.
| assert kwargs["project_id"] == "project-123" | ||
| secrets = { | ||
| "DISCORD_BOT_TOKEN_MEOS_DEV": "dev-token", | ||
| "DISCORD_BOT_TOKEN_MEOS_ACADEMIC": "academic-token", |
There was a problem hiding this comment.
This mocks the legacy apply_bitwarden_secrets entry point. Current startup tests stub fetch_bitwarden_secrets and exercise _apply_external_secret_sources() through the registry; use that live path so the test covers the implementation users run.
Summary\n- Add secrets.bitwarden.env_map to materialize profile-specific BWS secret aliases as runtime env vars\n- Add prune_env_keys/prune_env_prefixes so alias secrets do not remain in long-lived process env after mapping\n- Cover Discord multi-profile token aliasing with env-loader tests\n\n## Tests\n- uv run --with pytest --with pyyaml --with python-dotenv python -m pytest tests/test_bitwarden_secrets.py tests/hermes_cli/test_env_loader_bitwarden_env_map.py -q -o 'addopts='\n