fix(cron): resolve BSM secrets in scheduler run_job (#33465)#33667
fix(cron): resolve BSM secrets in scheduler run_job (#33465)#33667trac3r00 wants to merge 1 commit into
Conversation
Replaces bare dotenv.load_dotenv() with load_hermes_dotenv() from hermes_cli.env_loader so Bitwarden Secrets Manager (BSM) credentials are pulled for cron jobs. - load_hermes_dotenv uses _load_dotenv_with_fallback (same UTF-8/latin-1 fallback as the old code) then calls _apply_external_secret_sources, which is already process-level deduplicated (de76f4d) so redundant BSM calls are avoided on subsequent ticks. Closes #33465
|
I found one issue worth fixing before merge.
The production code uses a local import inside # cron/scheduler.py, inside _run_job_impl()
from hermes_cli.env_loader import load_hermes_dotenv
load_hermes_dotenv(hermes_home=_get_hermes_home())But the test patches at the module level: monkeypatch.setattr("cron.scheduler.load_hermes_dotenv", _fake_load_hermes_dotenv)Because the import is local (inside the function body), Python resolves The test passes by accident: the real function loads Actually, The same pattern affects all Suggested fix — either:
# At top of cron/scheduler.py
from hermes_cli.env_loader import load_hermes_dotenvThen the Option (1) is the minimal change. Option (2) is more consistent with how |
Replaces bare
dotenv.load_dotenv()withload_hermes_dotenv()fromhermes_cli.env_loaderincron/scheduler.pyso Bitwarden Secrets Manager (BSM) credentials are resolved for cron jobs.Root cause:
run_jobloaded env via plain python-dotenv, skipping the_apply_external_secret_sourcespath entirely. Any cron job needing a BSM-managed key failed with HTTP 401.What changed:
cron/scheduler.py: 5-line bare dotenv block → singleload_hermes_dotenv(hermes_home=_get_hermes_home())calldotenv.load_dotenvmocks acrosstest_scheduler.py,test_cron_profile.py",test_cron_workdir.pyto mockcron.scheduler.load_hermes_dotenv` insteadtest_cron_bsm_resolution.pyregression test verifying the scheduler callsload_hermes_dotenvduringrun_jobDeduplication:
_apply_external_secret_sourcesalready guards by_APPLIED_HOMES(per commit de76f4d), so redundant BSM pulls on subsequent ticks are avoided.Closes #33465