Skip to content

feat(staging): in-cluster MongoDB (no shared Atlas cred) + env doc - #2430

Merged
lilyshen0722 merged 3 commits into
mainfrom
staging-environment-doc
Oct 22, 2026
Merged

lilyshen0722 merged 3 commits into
mainfrom
staging-environment-doc

Conversation

@lilyshen0722

Copy link
Copy Markdown
Contributor

Staging: in-cluster MongoDB (no shared Atlas credential) + environment doc

Enables the chart's single-replica in-cluster mongodb StatefulSet in values-staging.yaml (spot pool, 5Gi PVC, mongo:7, staging-only root password), and adds docs/runbooks/staging-environment.md.

Why: the only Atlas credential on the host is the prod user, which carries atlasAdmin — cluster-wide admin including prod data. Staging auto-deploys every merge and is the deliberately reckless lane, so sharing that credential is unacceptable. The in-cluster mongod removes the shared credential entirely; it holds no prod data and is resettable. Postgres still uses the Aiven commonly_staging db with a db-scoped (non-admin) role.

Render verified: prod render byte-identical to main (sha256 a78fc9fa…; mongodb.enabled stays false outside staging); staging render gains the StatefulSet + Service and still has 0 Ingress objects.

Part of the Thu staging-secrets task; gates the staging install. Not for the prod lane.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Nju36GWpimrACHLKahbB4L

@lilyshen0722 lilyshen0722 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Unasked review of cbd6a222c67cc6c01d366dbd5d175497cf905c87 (tree 1a1defb9e8a407c72824cad83e277d9eb1bf6c81) — unreviewed, base current, mergeStateStatus CLEAN. No GATE: line; none was requested.

The core decision is right, and it closes the thing I flagged on #2405. There I noted that of the seven GCP Secret Manager keys staging shares with prod, commonly-github-pat was the one with teeth, and that the database story rested on deploy-time private values. This removes a sharper version of that problem outright: the comment's reason — "The prod Mongo user is atlasAdmin (cluster-wide admin, including prod data), and staging auto-deploys every merge and is the deliberately reckless lane" — is exactly the argument, and a staging-only root password in commonly-staging-mongo-password with its own commonly-staging-mongo-uri is the right shape. Postgres keeping a db-scoped non-admin role on Aiven is consistent.

The template exists, and staging is its first user. templates/databases/mongodb-statefulset.yaml and -service.yaml are on main, and mongodb.enabled is false in both values.yaml and values-dev.yaml. So this is the first environment to run that StatefulSet at all — worth knowing, because nothing has exercised it yet and a first run is where a chart bug surfaces.

Finding — this is the first stateful workload any environment puts on the spot pool, and ADR-015 is not mentioned.

The block sets nodeSelector: workload-tier: spot with a 5Gi ReadWriteOnce PVC. ADR-015 is titled "spot node pool for stateless workloads", and its placement table keeps redis on the on-demand pool even though "its data is ephemeral" — the stated reason is availability, after a 2026-07-11 reclaim took the shell offline with two user-visible 503s. A mongod with a PVC is a stronger case than Redis by that reasoning.

I do not think the placement is wrong. Staging is the reckless lane, a few minutes of staging downtime costs nothing, and the runbook says the database "may be reset freely" — which is precisely why ADR-015's reasoning (user-visible 503s, "agents are always there") does not reach here. The gap is that nobody reading either document would learn that. grep -c ADR-015 in the new runbook returns 0, and the values comment justifies spot on cost and recklessness without naming the decision it departs from.

One line in the runbook — "staging's mongod sits on spot deliberately: ADR-015 keeps stateful and availability-critical workloads on demand for the prod release, and neither reason applies to a resettable staging database" — makes the exception discoverable from the direction a reader arrives, which is the same repair CLAUDE.md records for adjacent ADRs after the #963 regression.

And one thing the "resettable" argument should make a requirement rather than an assumption. It is what makes spot acceptable, so the reseed path needs to exist and be named. The runbook mentions reset once, in passing at :50, as a property ("may be reset freely") rather than a procedure — no command, no seed source, and nothing about the spot-reclaim case specifically (an unclean mongod stop; journaling usually recovers, but "usually" is the whole argument for having a documented reseed). A short "Reset staging's database" section with the actual commands would turn the load-bearing assumption into something an operator can act on at 2am.

@lilyshen0722 lilyshen0722 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

#2430 HOLD at cbd6a22.

One blocking documentation defect: docs/runbooks/staging-environment.md:17-24 describes the secret inventory as disjoint apart from the shared CA and reports 38 api-keys / 41 keys overall. The actual staging render has 44 api-keys entries: 38 staging-prefixed and six shared, plus three database entries and one shared CA entry (48 total). The six unprefixed remote refs are commonly-cloudflare-workers-ai-token, commonly-cloudflare-account-id, commonly-deepseek-api-key, commonly-github-pat, commonly-git-user-name, and commonly-git-user-email. In particular, the shared PAT becomes api-keys.GITHUB_PAT and is wired into the staging backend and gateway containers. This is existing chart behavior, not a new credential leak introduced by the Mongo values, but the new security runbook teaches a false isolation boundary and omits operationally required remote keys. Correct the inventory to distinguish the 41 staging-prefixed entries from the seven shared entries, and explicitly distinguish placeholder GitHub-App/OAuth credentials from the shared PAT. If fully disjoint credentials are intended, enforce that instead; this finding does not require changing the existing sharing policy merely to document it accurately.

Own exact-head checks pass:

  • Production: 38 objects, complete Helm stdout byte-identical to main 40ce85e. SHA256 a78fc9fa4d4b5eaa80ae9d3fbe0168c663c59400867806c0e3cb353143f09f4d. Mongo remains absent outside staging.
  • Staging: 21 -> 23 objects; every original object's complete YAML chunk is byte-identical. Sole additions are StatefulSet/mongodb and Service/mongodb. No Ingress. All four baseline/head renders strict-parse using js-yaml loadAll, with Helm stderr captured separately and empty.
  • Mongo image mongo:7, one replica, 5Gi standard-rwo PVC, spot selector/toleration and requested resource bounds match the change. Root password consumes database-credentials/mongo-password; backend MONGO_URI consumes database-credentials/mongo-uri; ESO resolves those to commonly-staging-mongo-password and commonly-staging-mongo-uri. Neither Mongo credential is a literal in the changed files. No private project ID, Workload Identity email or external database host appears in the complete two-file addition; the internal mongodb Service name is not a private database endpoint.
  • The secret-inventory probe positively identifies the shared PAT reference. Its initial assertion used the wrong target-key spelling (github-pat rather than GITHUB_PAT); corrected against the actual template and rerun successfully. This was a probe error, not a product defect.

Scope of the Atlas assurance: the chart selects staging-specific Mongo remote keys and contains no direct prod Atlas URI/user reference. It does not validate the opaque URI's contents, nor does a namespaced SecretStore prove the shared GCP accessor cannot read other secrets. The private URI, actual IAM grants and live cluster reachability were not inspected. Thus this review cannot certify the broader phrase “nothing ... can reach the prod Atlas user.” Verify the resolved staging URI/credentials at install without publishing their values.

Rulings on the two requested doc points:

  • (a) Nonblocking for this change. ADR-015's stated reason protects live availability and in-flight agent/session state; the PR explicitly proposes disposable staging data with no production dependency. Add an explicit staging-only exception/cross-reference and acknowledge spot/PVC reattachment downtime. Do not describe this as changing the production placement rule, or assert an unverified “first stateful workload” history.
  • (b) Nonblocking for enabling the initial empty staging database. A named, namespace-scoped reset/reseed procedure is useful before relying on recovery, especially because a retained PVC is not cleared by merely restarting the StatefulSet. No recovery/reseed demonstration is claimed here.

Additional nonblocking wording correction at runbook:29-30: disabled SMTP2GO removes its ESO remote refs, but four optional SMTP2GO secretKeyRefs still exist in backend env. Say “no SMTP2GO remote keys are fetched,” rather than “the render references none.”

Full two-file merge-base diff (103 additions) read; diff check clean; base/main 40ce85e. REVIEW and checklist at the reviewed ref are unchanged from main. GitHub reports 21 successful and 3 skipped checks. No application-test rerun, live Mongo initialization, reset, cluster mutation or deployment was performed; these are local chart/render/source checks. Fetched and live head match.

Written by Rhea — https://commonly.me/pods/6a8f6dc7a1dccf2e02f31015

Written by Rhea, a Commonly agent — https://commonly.me/v2/pods/6a8f6dc7a1dccf2e02f31015

GATE: HOLD

@lilyshen0722

Copy link
Copy Markdown
Contributor Author

Closing and reopening only to trigger CI: the pull_request workflows never ran for head 1c7caba (only CodeQL did).

lilyshen0722 and others added 3 commits October 22, 2026 14:53
…+ env doc

Staging must never hold an Atlas credential: the only Atlas cred on the host is
the prod user, which carries atlasAdmin (cluster-wide, incl prod data), and
staging auto-deploys every merge as the reckless lane. Enable the chart's
single-replica in-cluster mongod in values-staging (spot pool, 5Gi PVC, mongo:7)
with a staging-only root password; the backend URI points at the in-cluster
Service. Postgres still uses the Aiven commonly_staging db with a db-scoped
(non-admin) role.

Adds docs/runbooks/staging-environment.md. Prod render byte-identical to main
(mongodb.enabled stays false outside staging); staging render gains the
StatefulSet + Service and still has 0 Ingress objects.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Nju36GWpimrACHLKahbB4L
…shared)

Rhea HOLD: the inventory undercounted. The staging render references 48 keys —
41 commonly-staging-* plus 7 shared commonly-* (6 in api-keys including the real
commonly-github-pat, plus the CA). Enumerate the placeholders (OAuth / GitHub-App
/ codex / external-bot), name the copied vs freshly generated staging keys, and
flag the PAT as the real prod credential being removed from the staging render in
a follow-up (no prod write power on the reckless lane).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Nju36GWpimrACHLKahbB4L
…ower on the reckless lane)

Cofounder's ruling: the shared commonly-github-pat has write power over prod
repos and staging auto-deploys every merge, so it must not reach staging (same
principle that keeps atlasAdmin off staging). Gate the api-keys GITHUB_PAT ref
behind githubPat.enabled (default true; false in values-staging) so the staging
render omits it entirely. The backend reads GITHUB_PAT lazily and degrades
(GitHub routes report not-configured) rather than crashing.

Updates the runbook inventory to the result: 47 render refs = 41 staging-prefixed
+ 6 shared (PAT excluded). Prod render byte-identical to main (a78fc9fa; the PAT
is still present in prod); staging render has 0 commonly-github-pat refs, 0
Ingress, strict-parse clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Nju36GWpimrACHLKahbB4L
@samxu01
samxu01 force-pushed the staging-environment-doc branch from 1c7caba to dae4487 Compare October 22, 2026 21:54

@lilyshen0722 lilyshen0722 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

#2430 CLEARED at dae4487.

The secret-inventory HOLD in review 5619542410 is closed. The runbook accurately distinguishes 41 staging-prefixed remote refs from six shared refs (47 total), and the new staging opt-out removes the shared GitHub PAT from ESO's requested keys. No blocking defect found.

Own exact-head evidence against main 3c578d6:

  • Production: all 39 objects and complete Helm stdout byte-identical to main; the GITHUB_PAT remote ref remains present. SHA256 3f41646b03ec23db359a02a42823ac02ecf6c569a79ef12a5bbcfa3664852b74. The PR body's old a78fc9fa hash is stale after the rebase; it is not the hash of this comparison.
  • Staging: 21 -> 23 objects. The only additions are StatefulSet/mongodb and Service/mongodb. api-keys loses exactly the three-line GITHUB_PAT entry; every other pre-existing object's complete YAML chunk is byte-identical. No commonly-github-pat remote ref, Ingress or ops-runner Deployment remains. All four baseline/head renders strict-parse with js-yaml loadAll; separately captured Helm stderr is empty.
  • Inventory: api-keys 43 (38 prefixed + five shared), database-credentials three prefixed, CA one shared. The shared set is exactly Cloudflare Workers-AI token/account ID, DeepSeek API key, Git author name/email and Postgres CA, matching the runbook.
  • Both rendered staging PAT consumers mark the missing key optional. Source inspection across all chart templates finds five PAT secretKeyRef consumers across four templates, including the GH_TOKEN alias; all five are optional. Gateway and cloud-codex credential setup checks for nonempty GITHUB_PAT. Backend PAT handling is lazy; skills refresh omits its Authorization header when absent. This verifies the missing-key wiring, not a live pod-start or all GitHub-route behavior test.
  • Own mutation in the temporary chart: removing the PAT conditional restores the forbidden shared ref and increases the staging inventory to 48; the absence assertion rejects that output. Restored the template byte-for-byte. Production PAT-present is the positive control.
  • Rebase/range-diff checked: the Mongo values block is byte-identical to the prior reviewed version and main's opsRunner.enabled:false is retained. Full four-file merge-base diff (139 additions) read, diff check clean, REVIEW/checklist unchanged. No credential literal, private project ID, Workload Identity email or external database host in the added material.

The three previously nonblocking items may remain in the stated follow-up: an explicit staging-only ADR-015 exception, a named reset/reseed procedure, and correcting “render references none” to “no SMTP2GO remote keys are fetched” (four optional backend refs remain). They do not reopen this gate.

Atlas assurance remains limited to the chart selecting staging-prefixed Mongo keys and containing no direct prod Atlas credential reference. Resolved URI contents, actual IAM grants and live cluster behavior are outside this review; the operator's install-time check is not claimed as my evidence. Removing an ESO ref is also not a certification that credentials persisted by an earlier deployment have been revoked or erased. No deployment, live Mongo initialization/reseed, application-test rerun or live credential read was performed.

GitHub reports 21 successful and two skipped checks. Fetched and live head match.

Written by Rhea — https://commonly.me/pods/6a8f6dc7a1dccf2e02f31015

Written by Rhea, a Commonly agent — https://commonly.me/v2/pods/6a8f6dc7a1dccf2e02f31015

GATE: PASS

@lilyshen0722
lilyshen0722 added this pull request to the merge queue Oct 22, 2026
Merged via the queue into main with commit 851fcda Oct 22, 2026
24 checks passed
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.

1 participant