Skip to content

[codex] Fix backend runtime config validation - #8651

Merged
Git-on-my-level merged 3 commits into
mainfrom
codex/backend-runtime-config-preflight
Jun 30, 2026
Merged

Git-on-my-level merged 3 commits into
mainfrom
codex/backend-runtime-config-preflight

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Jun 30, 2026 •

Copy link
Copy Markdown
Member

Summary

  • make backend Google credentials deterministic from runtime SERVICE_ACCOUNT_JSON and block accidental google-credentials.json image baking
  • require Cloud Run env/secrets/network config in the canonical runtime manifest, including prod credential bindings
  • deploy Cloud Run revisions with no traffic, validate runtime config, verify captured revisions, then shift traffic to exact validated revisions
  • extend runtime-env validation to check workflow secrets, workflow VPC flags, and live Cloud Run network annotations

Root Cause

Cloud Run and GKE backend runtime config drifted because env vars, secrets, credentials, and private networking were defined across separate deploy surfaces. Cloud Run revisions could be created before all expected runtime config was present, including the credential binding needed to materialize google-credentials.json.

Review

  • consulted the Tailnet Oracle and implemented its P1/P2 prescriptions
  • ran two subagent review passes; the first found P2 gaps, the second reported no remaining P1/P2 findings

Validation

  • python3 backend/scripts/validate-backend-runtime-env.py --env dev --check-workflows
  • python3 backend/scripts/validate-backend-runtime-env.py --env prod --check-workflows
  • python3 -m pytest backend/tests/unit/test_backend_runtime_env_validator.py backend/tests/unit/test_google_credentials.py -q
  • python3 -m py_compile backend/utils/google_credentials.py backend/scripts/validate-backend-runtime-env.py backend/main.py backend/database/_client.py
  • git diff --check
  • bash backend/test-preflight.sh (passed; warns that optional local packages/services like Firestore/Redis are not installed)

Fixes #8515

Review in cubic

@cubic-dev-ai cubic-dev-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.

1 issue found across 11 files

Confidence score: 3/5

  • In backend/utils/google_credentials.py, the current write-then-chmod flow can briefly leave SERVICE_ACCOUNT_JSON readable with broader permissions (especially in /tmp or if the target already exists with permissive mode), creating a real secret-exposure risk if merged as-is — create/open the file with 0600 from the start before writing the JSON.

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread backend/utils/google_credentials.py Resolved

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3d5ca460be

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread .dockerignore Resolved
@Git-on-my-level
Git-on-my-level force-pushed the codex/backend-runtime-config-preflight branch from 3d5ca46 to 2c6a184 Compare June 30, 2026 00:58
@Git-on-my-level

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2c6a184967

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread backend/database/google_credentials.py Resolved
@Git-on-my-level
Git-on-my-level force-pushed the codex/backend-runtime-config-preflight branch from 2c6a184 to 7fcbd35 Compare June 30, 2026 02:10
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Addressed the credential runtime feedback.

What changed:

  • Removed the pusher image dependency on backend/google-credentials.json from backend/pusher/Dockerfile.
  • Removed the pusher deploy workflow step that wrote backend/google-credentials.json into the Docker build context.
  • Added SERVICE_ACCOUNT_JSON to prod backend-listen env and to the runtime manifest so validation enforces it.
  • Added SERVICE_ACCOUNT_JSON to prod pusher runtime env so the pusher image no longer depends on a baked credential file.

Verification passed:

  • python3 backend/scripts/validate-backend-runtime-env.py --env dev --check-workflows
  • python3 backend/scripts/validate-backend-runtime-env.py --env prod --check-workflows
  • python3 -m pytest backend/tests/unit/test_backend_runtime_env_validator.py backend/tests/unit/test_google_credentials.py -q (11 passed)
  • python3 -m py_compile backend/utils/google_credentials.py backend/scripts/validate-backend-runtime-env.py backend/main.py backend/database/_client.py
  • git diff --check
  • checked that the pusher Dockerfile/workflow no longer reference the baked backend/google-credentials.json path

@Git-on-my-level

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7fcbd35f13

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

- name: Capture ${{ env.SERVICE }} revision
id: capture-backend-revision
run: |
revision="$(gcloud run services describe backend --region=${{ env.REGION }} --format='value(status.latestCreatedRevisionName)')"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Capture this deploy's revision deterministically

In this no-traffic flow, the capture step reads the service-wide status.latestCreatedRevisionName; if two auto-dev pushes overlap (this workflow has no concurrency guard), an earlier run can capture a revision created by the later run and then shift traffic to that image while its GKE listen deployment still uses the earlier SHA. Use a deterministic revision suffix/tag for this deploy or serialize runs before relying on the captured revision.

Useful? React with 👍 / 👎.

Comment thread backend/database/_client.py Outdated
from google.cloud import firestore

from database.document_ids import document_id_from_seed
from utils.google_credentials import prepare_google_credentials

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep database from importing the utils layer

backend/AGENTS.md requires the import hierarchy database/ -> utils/ -> routers/ -> main.py, with higher layers importing lower ones; this new database → utils edge violates that contract and can turn the many existing utils imports of database into startup circular-import failures. Move the credential helper into a lower-level module or keep preparation outside database/_client.py.

Useful? React with 👍 / 👎.

from utils import google_credentials


def test_service_account_json_materializes_credentials_file(monkeypatch, tmp_path):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Add the new credential tests to the backend runner

backend/AGENTS.md says new backend test files must be added to backend/test.sh; this new pytest module is not listed there, so the CI source-of-truth runner will skip these credential-materialization tests. Add a pytest tests/unit/test_google_credentials.py -v entry alongside the other unit tests.

Useful? React with 👍 / 👎.

@Git-on-my-level
Git-on-my-level merged commit ea411d7 into main Jun 30, 2026
7 checks passed
@Git-on-my-level
Git-on-my-level deleted the codex/backend-runtime-config-preflight branch June 30, 2026 03:18
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.

Create canonical backend runtime config to prevent Cloud Run/GKE env drift

1 participant