Add database password support via config fields and env vars#716
Add database password support via config fields and env vars#716
Conversation
Add `Password` and `MigrationPassword` fields to `DatabaseConfig`, allowing database credentials to be provided via YAML config or `THV_REGISTRY_DATABASE_PASSWORD` / `THV_REGISTRY_DATABASE_MIGRATIONPASSWORD` environment variables as an alternative to the PGPASSFILE mechanism. The change is fully backwards compatible: when no password fields are set, behavior is identical to today (pgx falls back to PGPASSFILE / ~/.pgpass). Password fields and `dynamicAuth` are mutually exclusive, enforced by config validation. Security hardening includes `json:"-"` tags to prevent accidental JSON serialization, an `slog.LogValuer` implementation to redact passwords from structured logs, and a Helm chart warning against placing passwords in the config block (which renders into a Kubernetes ConfigMap). Viper `SetDefault` calls ensure the env var overrides work even when the password keys are absent from the YAML config file. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #716 +/- ##
==========================================
- Coverage 60.76% 60.74% -0.02%
==========================================
Files 107 107
Lines 10394 10415 +21
==========================================
+ Hits 6316 6327 +11
- Misses 3534 3544 +10
Partials 544 544 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
The health and readiness endpoints moved to the internal server on port 8081. Update the docker-compose.smoke-test.yaml healthcheck to use the correct port and expose 8081 to the host for external probes. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Implementation PlanContextCurrently the only way to pass static DB passwords to the registry server is via PGPASSFILE ( This change is fully backwards compatible: when no password fields are set, behavior is identical to today (pgx falls back to PGPASSFILE). Changes1. Add password fields to
|
Summary
PasswordandMigrationPasswordfields toDatabaseConfig, enabling database credentials via YAML config orTHV_REGISTRY_DATABASE_PASSWORD/THV_REGISTRY_DATABASE_MIGRATIONPASSWORDenvironment variables as an alternative to the PGPASSFILE mechanismdynamicAuthis configuredjson:"-"tags,slog.LogValuerredaction, Helm chart ConfigMap warningbuildMigrationConnString()helper shared by all 4 migration callers (serve, migrate-up, migrate-down, prime-db)SetDefaultensures env var overrides work even when password keys are absent from YAMLFixes: #683
Precedence
Dynamic auth token (AWS RDS IAM) > config password field / env var > PGPASSFILE / ~/.pgpass
Test plan
task lint-fixpasses (0 issues)task testpasses for all changed packages (internal/config,cmd/thv-registry-api/app)THV_REGISTRY_DATABASE_PASSWORD+THV_REGISTRY_DATABASE_MIGRATIONPASSWORDenv vars (no PGPASSFILE)password+dynamicAuthtogether (unit test)🤖 Generated with Claude Code