Read db passwords from the environment first - #123
Conversation
… to 3.0.15 Containers on CIRRUS get their db passwords injected as environment variables by a Kubernetes secret, so look them up there before the .pgpass file and OpenBao, and cache a password found by either of those back into the environment so that the child processes on local and PBS batch hosts inherit it instead of looking it up again. Name the secret from the db server node and the login name, so that the same name serves the OpenBao path (kv/gdex/<node>) and the environment variable (<NODE>_<KEY>). Prefer the node of the host being connected to, so that a node holding its own passwords, such as pgdb02, is served its own secrets, and fall back to the node mapped for the db name, such as pgdb01 for pgdb02, for a node that shares them without holding secrets of its own. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes recommended
Newly added docstrings describe host-conditional environment caching that the implementation does not enforce, which can mislead operators about runtime behavior.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR updates PgDBI’s credential resolution so PostgreSQL passwords are first read from the environment (to support CIRRUS/Kubernetes secret injection), with fallbacks to .pgpass and OpenBao, and adds an environment write-back cache to avoid repeated lookups in child processes. It also standardizes secret naming based on (db node, login) and bumps the package version to 3.0.15.
Changes:
- Add env-first password lookup and env write-back caching in
PgDBI, plus node-based OpenBao secret loading with fallback nodes. - Introduce node/key derivation helpers (
get_dbnodes,get_secret_name,get_envpassword,set_envpassword) and new mappings (DBNODES,DBSKEYS). - Bump package/version references from 3.0.14 → 3.0.15.
File summaries
| File | Description |
|---|---|
| src/rda_python_common/pg_dbi.py | Adds env-first password lookup, env caching, and node-based OpenBao secret resolution with fallback behavior. |
| src/rda_python_common/init.py | Bumps __version__ to 3.0.15. |
| README.md | Updates displayed “current version” to 3.0.15. |
| pyproject.toml | Bumps project version to 3.0.15. |
Review details
Suppressed comments (1)
src/rda_python_common/pg_dbi.py:2714
- This docstring restricts env caching to local/PBS batch hosts, but set_envpassword() is called without any such condition. Update the docstring (or add the missing condition).
Called for a password found in .pgpass or OpenBao, on local and PBS batch hosts,
so that the child processes of the current one inherit it and skip the lookup.
- Files reviewed: 4/4 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| finally falls back to OpenBao (get_baopassword()). A password found on local | ||
| or batch hosts is cached in the environment (set_envpassword()) so that the | ||
| child processes inherit it instead of looking it up again. |
Summary
.pgpassand OpenBao, for containers on CIRRUS where a Kubernetes secret injects it as<NODE>_<KEY>(PGDB01_DSSDBPASS,PGDB03_IVADDBPASS, ...)..pgpassor OpenBao back into the environment, so that child processes on local and PBS batch hosts inherit it instead of repeating the lookup.kv/gdex/<node>and the environment variable, so the two transports cannot drift.Test plan
PGDB02_*/kv/gdex/pgdb02when present and falls back toPGDB01_*/kv/gdex/pgdb01when missing; pgdb01 and pgdb03 unchanged.pytestpasses.