Repository navigation
feat(helm)!: pin MongoDB, add DB auth and probes - #99
Conversation
Replace the config Job, which rewrote the image's config with yq and patched a ConfigMap with namespace admin rights, with a ConfigMap rendered by Helm. It holds a FOCA config overlay (`FOCA_CONFIG_OVERLAY`) generated from `host_name` (HTTPS on port 443, as before) and merged with the new free-form `config` value, which takes precedence. The Deployment mounts it as a directory and rolls on config changes. This also fixes the public URL: the Job set `.endpoints.service` instead of `.custom.endpoints.service`, so `host_name` was never used. Remove `update-config-map.sh` and its tools from the image, and install the app non-editably. Document configuration via overlays for Helm and Docker Compose. CI lints and renders the chart and validates the rendered overlay against the app's config models. Closes #67 BREAKING CHANGE: the chart (version 3.0.0) no longer creates the `app-config` ConfigMap, the config Job, its ServiceAccount and RoleBinding, and drops the `apiServer` value; config changes made to `app-config` must be moved to `config` in the values file. The image no longer contains the app's source in `/app`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Test the config overlay rendered by `helm template` with pytest (when helm is installed, as on GitHub-hosted runners) instead of an inline script in CI: generated values, precedence of `config`, and recursive merging of overlays. Require `host_name`, validate the types of `host_name` and `config` with a values schema, and document that the chart needs an image with FOCA 0.14 or later, which keys it expects unchanged, and that `config` must not contain secrets. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Test the values schema, precedence of later overlays, and that the Deployment mounts the overlay ConfigMap where `FOCA_CONFIG_OVERLAY` points; share the config parsing helper. Install all CI requirements in one step and fail the chart tests if helm is missing. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Pin MongoDB to 7.0 (as in Docker Compose) instead of `mongo:noble`, which resolves to the latest version, and replace its pod with the `Recreate` strategy, as the data volume can only be used by one pod. Add optional MongoDB authentication (`mongodb.auth`): credentials come from an existing Secret; MongoDB creates the root user and, via the init script, an app user with access to the app's database only, which the app connects as (`MONGO_USERNAME`, `MONGO_PASSWORD`). The init script no longer creates collections and indexes, which FOCA does on startup. Add readiness and liveness probes to the app (Swagger UI) and MongoDB (TCP). Document version upgrades and downgrades, authentication and probes, and test the rendered manifests. Closes #68 BREAKING CHANGE: the default MongoDB image changes from `mongo:noble` (MongoDB 8.x) to `mongo:7.0`; databases written by MongoDB 8.0 must be downgraded first or keep their version via `mongodb.image` (see the deployment docs). Co-Authored-By: Claude Opus 5.5 <[email protected]>
`mongo:noble` may resolve to MongoDB 8.2, whose data cannot be read by 7.0 (or 8.0) directly. Document checking the version and the feature compatibility version before changing the image, downgrading one version at a time, and pinning the running version before upgrading from chart version 2. Document privileged commands with authentication and password changes. Add a startup probe to MongoDB, so that the liveness probe cannot interrupt the initialization of an empty data directory (which would skip creating the users). Render the Secret references with a helper, add the MongoDB values to the schema, and test probes and init script mounts in detail; move the Helm test helpers to `tests/helm.py`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
MongoDB Community Edition does not support binary downgrades, and `mongo:noble` now resolves to MongoDB 9.0. Tell users upgrading from chart version 2 to pin the running version, document dump and restore as the way to an older version, and print both the version and the FCV. Move the probes to their own section and describe all of them, test that the init script uses the configured database, lint the chart with authentication enabled, and note the order of Secret variables. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideThe chart now pins MongoDB and uses safe Recreate rollouts, enables Secret-backed database authentication by default with an app-scoped user, adds configurable application and MongoDB probes, documents upgrade and migration procedures, and verifies both auth modes through Helm lint and rendering tests. Sequence diagram for MongoDB initialization and app connectionsequenceDiagram
participant K as Kubernetes
participant M as MongoDB
participant S as Init script
participant A as Cloud Registry
participant F as FOCA
K->>M: Start with Secret-backed environment
M->>S: Run create-app-user.js on empty data directory
S->>M: createUser with readWrite on serviceStore
A->>F: Start with MONGO_USERNAME and MONGO_PASSWORD
F->>M: Connect to serviceStore
F->>F: Create collections and indexes
Flow diagram for safe MongoDB rolloutflowchart TD
Change[MongoDB image or configuration change] --> Stop[Stop existing MongoDB pod]
Stop --> Recreate[Recreate strategy starts one pod]
Recreate --> Startup[TCP startup probe allows initialization or recovery]
Startup --> Ready[Readiness probe accepts connections]
Ready --> Serve[MongoDB serves the single ReadWriteOnce volume]
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
# Conflicts: # .github/workflows/checks.yaml # deployment/README.md # deployment/templates/cloud-registry-deploy.yaml # deployment/values.schema.json # tests/test_config.py
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #99 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 7 7
Lines 224 224
=========================================
Hits 224 224 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Hey - I've found 8 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="deployment/values.yaml" line_range="59" />
<code_context>
+ auth:
+ # Require credentials; only applied when MongoDB starts with an empty
+ # data directory (see the deployment docs for existing databases)
+ enabled: false
+ # Name of an existing Secret with keys `root-username` and
+ # `root-password` (MongoDB root user) and `username` and `password` (app
</code_context>
<issue_to_address>
**Cluster pods can modify database**
When the chart is installed with its default values and an untrusted or compromised pod can reach the cluster service, a compromised or untrusted pod that can reach the cluster network can connect to `mongodb:27017` without credentials and read or modify registry data.
Require MongoDB authentication by default, or restrict access to the MongoDB service with a NetworkPolicy and clearly require that protection for deployments with untrusted workloads.
</issue_to_address>
### Comment 2
<location path="deployment/templates/cloud-registry-deploy.yaml" line_range="32-36" />
<code_context>
env:
- name: FOCA_CONFIG_OVERLAY
value: /etc/cloud-registry/overlay.yaml
+ {{- if .Values.mongodb.auth.enabled }}
+ {{- include "cloud-registry.mongodbSecretEnv" (dict "root" . "vars" (dict
+ "MONGO_USERNAME" "username"
+ "MONGO_PASSWORD" "password"
+ )) | trim | nindent 8 }}
+ {{- end }}
ports:
</code_context>
<issue_to_address>
**Authenticated app requests fail**
When `mongodb.auth.enabled` is true, the Deployment exposes `MONGO_USERNAME` and `MONGO_PASSWORD`, but FOCA receives a config with no credentials and no application code consumes those variables. Its MongoDB client connects without credentials, so database requests fail.
Pass the Secret credentials into FOCA's MongoDB configuration or client instead of only exposing them as environment variables.
</issue_to_address>
### Comment 3
<location path="deployment/templates/mongo-init-script.yaml" line_range="15-18" />
<code_context>
+ // Create the app user with access to the app's database only; FOCA puts
+ // the database in the connection string, so the app authenticates
+ // against it. Change the database here if `db.dbs` in the config does.
+ db.getSiblingDB('serviceStore').createUser({
+ user: process.env.MONGO_APP_USERNAME,
+ pwd: process.env.MONGO_APP_PASSWORD,
+ roles: [{ role: 'readWrite', db: 'serviceStore' }],
+ });
+{{- end }}
</code_context>
<issue_to_address>
**Configured database rejects app user**
When authentication is enabled and `config.db.dbs` selects a database other than `serviceStore`, the init script creates the app user with access only to `serviceStore`, while FOCA uses the configured database. The user cannot access that database, so authenticated database operations fail.
Create the app user with access to the database or databases selected by `config.db.dbs`.
</issue_to_address>
### Comment 4
<location path="deployment/templates/cloud-registry-deploy.yaml" line_range="49-55" />
<code_context>
+ periodSeconds: 10
+ timeoutSeconds: 5
+ failureThreshold: 3
+ livenessProbe:
+ httpGet:
+ path: /ga4gh/registry/v1/ui/
+ port: 8080
+ initialDelaySeconds: 30
+ periodSeconds: 20
+ timeoutSeconds: 5
+ failureThreshold: 3
resources: {{- toYaml .Values.cloud_registry.resources | nindent 10 }}
</code_context>
<issue_to_address>
**Slow app startup loops**
When app initialization takes roughly 70 seconds or more, such as on a constrained node or while the database is slow to accept the initialization query, the liveness probe starts after 30 seconds and can fail three times at 20-second intervals before the app binds its port. Kubernetes restarts the container before it can finish starting and become ready.
Add a startup probe with enough time for initialization to finish before liveness checks begin.
</issue_to_address>
### Comment 5
<location path="deployment/templates/mongo-deploy.yaml" line_range="38-42" />
<code_context>
+ # MongoDB listens on localhost only while initializing an empty data
+ # directory, so allow up to 5 minutes before liveness checks start, as
+ # interrupting the initialization skips it on the next start
+ startupProbe:
+ tcpSocket:
+ port: 27017
+ periodSeconds: 10
+ failureThreshold: 30
+ readinessProbe:
+ tcpSocket:
</code_context>
<issue_to_address>
**Mongo initialization is interrupted**
When initialization or recovery takes longer than five minutes, the startup probe restarts `mongod` after roughly five minutes, interrupting initialization or recovery. Because the persistent data directory then makes the Mongo image skip initialization scripts, the database can remain unavailable or lack users created by those scripts.
Give MongoDB initialization and recovery a startup-probe window long enough to finish, and make the documented recovery command authenticate with root credentials.
Also at `deployment/README.md:169`.
</issue_to_address>
### Comment 6
<location path="deployment/templates/cloud-registry-deploy.yaml" line_range="44" />
<code_context>
+ # All API endpoints require authentication, so probe the Swagger UI
+ readinessProbe:
+ httpGet:
+ path: /ga4gh/registry/v1/ui/
+ port: 8080
+ periodSeconds: 10
</code_context>
<issue_to_address>
**Configured route never becomes ready**
When the config overlay changes the API path or disables the Swagger UI route, the probes keep requesting the fixed Swagger UI path, so readiness never succeeds and liveness can restart the app even though it serves its configured route. Kubernetes keeps the deployment unavailable.
Make the probe path configurable and align it with the route set by the config overlay.
Also at `deployment/templates/cloud-registry-deploy.yaml:51`.
</issue_to_address>
### Comment 7
<location path="tests/test_chart.py" line_range="44" />
<code_context>
+ var["valueFrom"]["secretKeyRef"]["key"],
+ )
+ for var in container.get("env", [])
+ if "secretKeyRef" in var.get("valueFrom", {})
+ }
+
</code_context>
<issue_to_address>
**Literal credentials pass auth test**
When a rendered app or MongoDB container includes a literal credential environment variable alongside the expected Secret references, `_secret_refs` filters out environment variables without `secretKeyRef`, so `test_auth_enabled` still matches its expected refs when literal credential variables are also rendered; the test passes despite credentials being exposed outside the Secret.
Assert the complete environment-variable configuration and reject credential variables that use literal values.
</issue_to_address>
### Comment 8
<location path="deployment/README.md" line_range="102" />
<code_context>
+
+```bash
+kubectl exec deploy/mongodb -n <namespace> -- mongosh --quiet --eval \
+ "printjson({version: db.version(), fcv: db.adminCommand({getParameter: 1, featureCompatibilityVersion: 1}).featureCompatibilityVersion})"
+```
+
</code_context>
<issue_to_address>
**Authenticated version check fails**
When mongoDB authentication is enabled and a user follows the documented version/FCV check, the version/FCV command runs `mongosh` without credentials, so MongoDB rejects its privileged `getParameter` request when authentication is enabled and users cannot check the FCV as instructed.
Add the root username, password, and `--authenticationDatabase admin` arguments to the version/FCV command.
</issue_to_address>Sourcery assessment
Approval pending. 8 findings to address first.
Blocking findings: deployment/values.yaml:59, deployment/templates/cloud-registry-deploy.yaml:36, deployment/templates/mongo-init-script.yaml:18, deployment/templates/cloud-registry-deploy.yaml:55, deployment/templates/mongo-deploy.yaml:42, and 3 more
Address the Sourcery review of #99: - Enable MongoDB authentication by default; without it, any pod that can reach the MongoDB service can read and modify the data. Running without authentication now needs `mongodb.auth.enabled: false`. - Add a startup probe to the app (up to 5 minutes), so that a slow start is not cut short by the liveness probe, and make the probe path configurable (`cloud_registry.probePath`). - Allow MongoDB up to 30 minutes to start, as recovery after an unclean shutdown can take a while. - Test that no credentials are passed as literal environment variables. - Docs: the version check and recovery commands authenticate as root. BREAKING CHANGE: `mongodb.auth.existingSecret` is required unless `mongodb.auth.enabled` is set to false. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Address review findings on the auth and probe changes: - test the default without a Secret name (fails) and disabled authentication without one (works), also in the CI lint - test the startup windows and that liveness probes have no initial delay - require and quote the probe path; test invalid and unset paths - correct the comment on when authentication is enforced: on every start, while users are only created on an empty data directory - describe the MongoDB values in the schema; point the upgrade notes to the authentication docs Co-Authored-By: Claude Opus 5.5 <[email protected]>
For existing databases without authentication, list the steps (Secret, users, then upgrade) and point to them from the error shown when the Secret name is missing. Let the MongoDB rollout take longer than its 30-minute startup window, and check that invalid probe paths fail for that reason. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@sourcery-ai review |
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="deployment/templates/mongo-init-script.yaml" line_range="15-18" />
<code_context>
+ // Create the app user with access to the app's database only; FOCA puts
+ // the database in the connection string, so the app authenticates
+ // against it. Change the database here if `db.dbs` in the config does.
+ db.getSiblingDB('serviceStore').createUser({
+ user: process.env.MONGO_APP_USERNAME,
+ pwd: process.env.MONGO_APP_PASSWORD,
+ roles: [{ role: 'readWrite', db: 'serviceStore' }],
+ });
+{{- end }}
</code_context>
<issue_to_address>
**Configured database access fails**
When a config overlay changes `db.dbs` from `serviceStore`, the init script always creates the app user and grants `readWrite` access in `serviceStore`, while the app connects to the database selected by its merged config. MongoDB rejects access to that database, so database operations fail.
Use the effective `db.dbs` value when creating the app user and granting its database role.
</issue_to_address>
### Comment 2
<location path="deployment/README.md" line_range="171-175" />
<code_context>
+ --authenticationDatabase admin --eval "db.version()"'
+```
+
+Changing the Secret does not change the users: to change a password, first
+change it in MongoDB (e.g.,
+`db.getSiblingDB("serviceStore").changeUserPassword("cloud-registry", "<new password>")`),
+then update the Secret and restart the app (`kubectl rollout restart
+deploy/<appName> -n <namespace>`).
+
+For an existing database without authentication (e.g., from chart version
</code_context>
<issue_to_address>
**Password rotation interrupts database requests**
When an operator follows the documented app-user password-change procedure while the app is serving requests, the documented order changes the MongoDB user's password before updating the Secret and restarting the app. During that gap, the running app pod still has the old password and its database requests fail; the rolling restart can also briefly serve traffic from that stale pod.
Document a staged rotation that creates a second app user, rolls the app to its credentials, then removes the old user, or explicitly warn that the documented rotation causes database-request failures during the transition.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 2 findings to address first, and enabling MongoDB authentication changes how the app and other clients can access the database; an existing database without the expected users can become inaccessible to the app after upgrade. Reverting the chart can restore the prior auth behavior, though users created on a fresh database remain until explicitly removed.
Blocking findings: deployment/templates/mongo-init-script.yaml:18, deployment/README.md:175
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
Deployment fixes for MongoDB and probes (#68). Builds on #98 (Helm config overlays, merged).
mongodb.imagedefaults tomongo:7.0(as in Docker Compose) instead ofmongo:noble, which resolves to the latest release (currently MongoDB 9.0).Recreatestrategy for MongoDB: theReadWriteOncedata volume can only be used by one pod, so noMulti-Attacherrors and never twomongodprocesses on one data directory. The rollout deadline is longer than MongoDB's startup window.mongodb.auth.enabled,mongodb.auth.existingSecret): credentials come only from an existing Secret (keysroot-username,root-password,username,password). Rendering fails without a Secret name; the error points to the docs for existing databases. Running without authentication needs an explicitmongodb.auth.enabled: false.readWriteonserviceStoreonly.MONGO_USERNAMEandMONGO_PASSWORD. FOCA putsserviceStorein the connection string, so the app authenticates against that database.cloud_registry.probePath(default: the Swagger UI, which needs no authentication or database). The schema requires an absolute path;deployment/README.md):tests/test_chart.pyrenders the chart and checks:Recreatestrategy;CI also lints the chart with auth enabled and disabled.
Closes #68
Breaking changes
mongo:noble(latest, now 9.0) tomongo:7.0. MongoDB 7.0 cannot read data written by newer versions, and Community Edition does not support binary downgrades. Existing deployments must setmongodb.imageto their running version before upgrading (documented indeployment/README.md).mongodb.auth.existingSecret, or setmongodb.auth.enabled: falseexplicitly. Existing databases without authentication need their users created first (documented indeployment/README.md).Verification
pytest(Helm 3.18.6 on PATH): 103 passed.ruff check,ruff format --check,mypy cloud_registry tests: clean.helm lint --strict, with auth (Secret set) and without auth (no Secret): passes.gitleaks dir .: no leaks.serviceStore, where the user is created.MONGO_USERNAME/MONGO_PASSWORD; the database name is fixed in code). All threads are resolved.Decisions
mongo:7.0(decided 2026-10-20). It starts on all kernels (MongoDB 8.x refuses to start on Linux 6.19 to 7.0.13, SERVER-121912) and is supported until 31 August 2027; the move to 8.0 is planned in build: move to MongoDB 8.0 before 7.0 EOL #103. The production deployment will be reinstalled with an empty database, so its current MongoDB version doesn't matter; deployments that keep their data must first setmongodb.imageto the version they run (seedeployment/README.md).🤖 Generated with Claude Code
Summary by Sourcery
Harden the Helm deployment by pinning MongoDB, enabling secure authentication by default, adding resilient probes, and documenting the resulting upgrade requirements.
New Features:
Bug Fixes:
Enhancements:
CI:
Tests:
Chores: