Skip to content

feat(helm)!: pin MongoDB, add DB auth and probes - #99

Merged
uniqueg merged 11 commits into
devfrom
feat/helm-mongodb
Oct 20, 2026
Merged

uniqueg merged 11 commits into
devfrom
feat/helm-mongodb

Conversation

@uniqueg

@uniqueg uniqueg commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

Summary

Deployment fixes for MongoDB and probes (#68). Builds on #98 (Helm config overlays, merged).

  • Pinned MongoDB: mongodb.image defaults to mongo:7.0 (as in Docker Compose) instead of mongo:noble, which resolves to the latest release (currently MongoDB 9.0).
  • Recreate strategy for MongoDB: the ReadWriteOnce data volume can only be used by one pod, so no Multi-Attach errors and never two mongod processes on one data directory. The rollout deadline is longer than MongoDB's startup window.
  • Authentication, on by default (mongodb.auth.enabled, mongodb.auth.existingSecret): credentials come only from an existing Secret (keys root-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 explicit mongodb.auth.enabled: false.
    • MongoDB creates the root user. The init script creates an app user with readWrite on serviceStore only.
    • The app connects as that user via MONGO_USERNAME and MONGO_PASSWORD. FOCA puts serviceStore in the connection string, so the app authenticates against that database.
    • No Secret or credentials are rendered into ConfigMaps or values.
  • Init script: no longer creates collections and indexes, since FOCA creates them on startup. It is only rendered with auth.
  • Probes:
    • app: startup (up to 5 minutes), readiness and liveness on cloud_registry.probePath (default: the Swagger UI, which needs no authentication or database). The schema requires an absolute path;
    • MongoDB: TCP startup probe (up to 30 minutes, so the first-start initialisation or a recovery is not interrupted), readiness and liveness.
  • Docs (deployment/README.md):
    • version checks;
    • upgrades step by step;
    • downgrades are unsupported for Community Edition, with dump and restore as the alternative;
    • pinning the running version before upgrading from chart v2;
    • authentication setup, including the steps for existing databases (Secret, users, then upgrade) and password changes; privileged commands authenticate with the root credentials;
    • probes.
  • Tests: tests/test_chart.py renders the chart and checks:
    • the pin and the Recreate strategy;
    • probe types, paths, ports and startup windows; invalid and unset probe paths fail;
    • Secret references with auth on, and no literal credentials; auth off without a Secret;
    • the init script, its volume and mount, and the database name;
    • that a Secret name is required by default.
      CI also lints the chart with auth enabled and disabled.

Closes #68

Breaking changes

  • The default MongoDB image changes from mongo:noble (latest, now 9.0) to mongo:7.0. MongoDB 7.0 cannot read data written by newer versions, and Community Edition does not support binary downgrades. Existing deployments must set mongodb.image to their running version before upgrading (documented in deployment/README.md).
  • MongoDB authentication is enabled by default. Deployments must create a Secret with the credentials and set mongodb.auth.existingSecret, or set mongodb.auth.enabled: false explicitly. Existing databases without authentication need their users created first (documented in deployment/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.
  • Adversarial and quality review, two rounds before the first push and two rounds on the fixes for Sourcery's findings.
    • Fixed: the downgrade docs (now based on MongoDB's release notes), startup probes and windows, privileged commands with authentication, auth by default, configurable and validated probe path, the order of upgrade steps for existing databases, and test coverage.
    • Declined:
      • Digest pinning: the pin is to the minor version, so patch updates still arrive.
      • The auth-database concern: FOCA authenticates against serviceStore, where the user is created.
      • Expressing "Secret required if auth enabled" in the schema too: the template enforces it with a clearer error message.
  • Sourcery's 8 findings: 6 fixed, 2 declined with reasons (FOCA reads MONGO_USERNAME/MONGO_PASSWORD; the database name is fixed in code). All threads are resolved.
  • Not verified: an actual deployment. Docker and Kubernetes are not available locally, so auth and probes are checked through rendered manifests only.
  • CI on 995a5a7: all checks pass, including the "Check Helm chart" job (lint with and without auth, chart tests) and the Docker Compose run.

Decisions

  • Default MongoDB version: 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 set mongodb.image to the version they run (see deployment/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:

  • Add configurable application and MongoDB health probes with validated probe paths and extended startup windows.
  • Add Secret-based MongoDB authentication by default, including creation of a restricted application user.

Bug Fixes:

  • Prevent MongoDB data-volume multi-attach conflicts by using a recreate deployment strategy.
  • Pin the default MongoDB image to version 7.0 instead of tracking the latest release.
  • Remove database schema initialization from the MongoDB script so the application manages its own collections and indexes.

Enhancements:

  • Expand deployment documentation with MongoDB versioning, upgrade and migration guidance, authentication procedures, password changes, and probe behavior.

CI:

  • Lint the Helm chart with authentication both enabled and disabled, and include Helm chart rendering tests in CI.

Tests:

  • Add Helm rendering tests covering MongoDB versioning, deployment strategy, probes, authentication behavior, Secret handling, and initialization mounts.

Chores:

  • Refactor shared Helm rendering helpers for chart tests.

uniqueg and others added 6 commits October 20, 2026 08:26
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]>
@sourcery-ai

sourcery-ai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

The 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 connection

sequenceDiagram
    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
Loading

Flow diagram for safe MongoDB rollout

flowchart 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]
Loading

File-Level Changes

Change Details Files
Pins MongoDB to a compatible minor version and makes single-volume rollouts safe.
  • Changes the default image to mongo:7.0.
  • Switches the Deployment strategy to Recreate.
  • Extends the progress deadline to cover the startup window.
deployment/values.yaml
deployment/templates/mongo-deploy.yaml
deployment/README.md
tests/test_chart.py
Adds Secret-backed MongoDB authentication with an app-scoped database user and explicit unauthenticated mode.
  • Enables authentication by default and requires an existing Secret when enabled.
  • Injects root and application credentials through secretKeyRef environment variables without rendering literal credentials.
  • Creates the application readWrite user for serviceStore through a conditional init script.
  • Disables the init script and related volume when authentication is off.
  • Documents installation, existing-database migration, password changes, and version/authentication administration.
deployment/templates/_helpers.tpl
deployment/templates/cloud-registry-deploy.yaml
deployment/templates/mongo-deploy.yaml
deployment/templates/mongo-init-script.yaml
deployment/values.yaml
deployment/values.schema.json
deployment/README.md
deployment/ci/test-values.yaml
tests/helm.py
tests/test_chart.py
tests/test_config.py
Adds configurable HTTP application probes and TCP MongoDB probes with guarded startup periods.
  • Adds validated cloud_registry.probePath with a Swagger UI default.
  • Configures startup, readiness, and liveness probes for both Deployments.
  • Allows up to 5 minutes for the app and 30 minutes for MongoDB initialization or recovery.
deployment/values.yaml
deployment/values.schema.json
deployment/templates/cloud-registry-deploy.yaml
deployment/templates/mongo-deploy.yaml
deployment/README.md
tests/test_chart.py
Expands Helm validation and automated rendering tests for authenticated and unauthenticated configurations.
  • Runs chart lint in both authentication modes in CI.
  • Adds coverage for image pinning, rollout strategy, probe configuration and validation, Secret references, init-script mounts, database naming, and required Secret handling.
  • Centralizes Helm rendering helpers for chart and config tests.
.github/workflows/checks.yaml
tests/helm.py
tests/test_chart.py
tests/test_config.py
deployment/ci/test-values.yaml

Assessment against linked issues

Issue Objective Addressed Explanation
#68 Pin MongoDB to a supported major version in both the Helm chart and Docker Compose, and document safe upgrade steps for existing data. ❌ The Helm chart pins MongoDB to mongo:7.0 and the deployment README documents version checks and stepwise upgrades. However, the diff does not change docker-compose.yaml, which the issue says still uses mongo:3.6.
#68 Support optional MongoDB authentication using an existing Secret, with credentials passed to MongoDB and the app without exposing them in values or ConfigMaps. ✅
#68 Add app and MongoDB probes, prevent overlapping MongoDB pods on the ReadWriteOnce volume, remove obsolete collection initialization, and fix the listed deployment leftovers. ❌ The PR adds probes, sets MongoDB's strategy to Recreate, and changes the init script so it only creates the app user rather than duplicating collection setup. But the diff does not show fixes for the config Job's container name, the script's “WES APP NAME” log, or the README's deployments/ reference.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

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

codecov Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (2681f44) to head (c86bb42).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@uniqueg
uniqueg marked this pull request as ready for review October 20, 2026 14:10

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread deployment/values.yaml Resolved
Comment thread deployment/templates/mongo-deploy.yaml Resolved
Comment thread tests/test_chart.py Resolved
Comment thread deployment/README.md Resolved
uniqueg and others added 3 commits October 20, 2026 16:25
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]>
@uniqueg

uniqueg commented Oct 20, 2026

Copy link
Copy Markdown
Member Author

@sourcery-ai review

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread deployment/README.md Resolved
@uniqueg
uniqueg merged commit 8cbaf25 into dev Oct 20, 2026
11 checks passed
@uniqueg
uniqueg deleted the feat/helm-mongodb branch October 20, 2026 15:00
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.

Deployment: pin MongoDB, add DB auth, probes

1 participant