Skip to content

fix(dtrack): source DB password from externalDatabase.existingSecret#110

Open
dragonpaw wants to merge 2 commits into
artifact-keeper:mainfrom
dragonpaw:fix/dtrack-password-from-existing-secret
Open

fix(dtrack): source DB password from externalDatabase.existingSecret#110
dragonpaw wants to merge 2 commits into
artifact-keeper:mainfrom
dragonpaw:fix/dtrack-password-from-existing-secret

Conversation

@dragonpaw

@dragonpaw dragonpaw commented May 20, 2026

Copy link
Copy Markdown
Contributor

Summary

When postgres.enabled=false and externalDatabase.existingSecret is set, templates/secrets.yaml intentionally skips writing POSTGRES_PASSWORD into the chart-managed Secret (the operator owns the credential). dtrack, however, always referenced <release>-secrets:POSTGRES_PASSWORD, so the pod fails to start with CreateContainerConfigError because the key it points at does not exist.

This PR makes dtrack source ALPINE_DATABASE_PASSWORD from the operator-provided externalDatabase.existingSecret in that branch, using a new externalDatabase.existingPasswordKey value (default "POSTGRES_PASSWORD"). All other paths (in-cluster postgres, or external DB with inline password) keep their previous source, so the change is backwards compatible — helm template output is byte-identical for those cases.

Reproducer (before this PR):

helm template ak charts/artifact-keeper \
  --set postgres.enabled=false \
  --set externalDatabase.existingSecret=mysecret \
  --set externalDatabase.host=h --set externalDatabase.port=5432 --set externalDatabase.username=u \
  --set secrets.jwtSecret=jwt --set secrets.s3AccessKey=ak --set secrets.s3SecretKey=sk \
  --set opensearch.auth.password=op \
  --set dependencyTrack.enabled=true --set dependencyTrack.adminPassword=adminpw

The rendered dtrack pod env points at ak-artifact-keeper-secrets:POSTGRES_PASSWORD, but the rendered Secret has no such key.

Test Checklist

  • Helm template renders without errors (helm lint clean)
  • Terraform validates/plans cleanly (N/A — chart-only change)
  • Manually verified on staging cluster (CloudSQL + GKE)
  • Rollback strategy documented (pure additive value; revert is safe)

Infrastructure

  • Helm: helm template renders correctly across four value combinations (defaults; external DB inline password; external DB existingSecret; external DB existingSecret + custom existingPasswordKey)
  • Terraform: terraform validate passes (N/A)
  • Terraform: terraform plan shows expected changes (N/A)
  • ArgoCD: Application manifests are valid (N/A)
  • N/A - documentation only

Closes #150

@brandonrc

Copy link
Copy Markdown
Contributor

Thanks for this. Now that several chart PRs (including the v1.2.0 alignment #145 and the load-bearing image-tag change #78) have landed on main, this branch has merge conflicts. Could you rebase onto the latest main, resolve them, run cd charts/artifact-keeper && helm-docs if values changed, and push? CI will re-run after.

(The red SonarCloud check is a known non-blocking fork limitation and can be ignored.)

Ash Arnold added 2 commits June 3, 2026 16:38
When postgres.enabled=false and externalDatabase.existingSecret is set,
secrets.yaml intentionally skips writing POSTGRES_PASSWORD into the
chart-managed Secret. dtrack still referenced
{{ fullname }}-secrets:POSTGRES_PASSWORD, so the pod started with
CreateContainerConfigError because the referenced key did not exist.

Point ALPINE_DATABASE_PASSWORD at the operator-provided existingSecret
in that branch, using a new externalDatabase.existingPasswordKey value
(defaults to "POSTGRES_PASSWORD"). All other paths (in-cluster postgres,
or external DB with inline password) keep their previous source, so the
change is backwards compatible.
@dragonpaw dragonpaw force-pushed the fix/dtrack-password-from-existing-secret branch from b588dac to cec4108 Compare June 3, 2026 23:38
dragonpaw pushed a commit to dragonpaw/artifact-keeper-iac that referenced this pull request Jun 3, 2026
When `postgres.enabled=false` and `externalDatabase.existingSecret` is set
(the canonical external-DB path), `templates/dtrack-deployment.yaml` built
`ALPINE_DATABASE_URL` from `externalDatabase.host` / `externalDatabase.port`
plain-string values. Operators following the existingSecret pattern who
omit those plain values get an empty-host JDBC URL —
`jdbc:postgresql://:5432/dependency_track` — which JDBC interprets as
`localhost` and dtrack then fails on startup with `Connection refused`.

This change projects host/port out of the operator-provided Secret into
two leading env vars (`_DTRACK_DB_HOST`, `_DTRACK_DB_PORT`) and references
them from `ALPINE_DATABASE_URL` via Kubernetes `$(VAR)` expansion. Two new
values let operators point at custom keys in the Secret:

  externalDatabase.existingHostKey  (default "POSTGRES_HOST")
  externalDatabase.existingPortKey  (default "POSTGRES_PORT")

Mirrors the precedent set by `externalDatabase.existingPasswordKey`
(artifact-keeper#110). Strictly additive: when `existingSecret` is unset, the literal
host/port substitution is preserved — `helm template` output is
byte-identical for the in-cluster postgres and inline-host/port paths.
@dragonpaw

Copy link
Copy Markdown
Contributor Author

Rebased onto the latest main as requested — the conflicts are resolved and helm-docs (v1.14.2) was regenerated for the new externalDatabase.existingPasswordKey value. Also filed and linked a tracking issue (#150, Closes #150 footer) so the require-linked-issue check is green. helm lint/helm template clean. Ready for another look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dtrack pod CreateContainerConfigError when postgres.enabled=false + externalDatabase.existingSecret (POSTGRES_PASSWORD key absent)

2 participants