Skip to content

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

Closed

Description

@Git-on-my-level

Context

The LLM Gateway rollout exposed a broader infra smell: backend runtime config is split across GKE Helm values, Cloud Run deploy workflow YAML, Secret Manager sync scripts, and live cloud state. This made it easy for backend-listen to have OMI_LLM_GATEWAY_URL while Cloud Run backend, backend-sync, and backend-integration did not.

Recent tactical fixes:

This issue tracks the long-term fix so future backend env changes cannot drift between Cloud Run and GKE.

Root Causes

  • Backend config is split across deploy planes:
    • GKE backend-listen env is declared in Helm values, for example backend/charts/backend-listen/dev_omi_backend_listen_values.yaml and prod_omi_backend_listen_values.yaml.
    • Cloud Run backend, backend-sync, and backend-integration env is declared separately in GitHub Actions workflows.
  • Secrets and non-secrets propagate differently:
    • GKE secret names flow through the backend-secrets chart and ExternalSecret.
    • Cloud Run secret bindings are patched by backend/scripts/sync_cloudrun_secrets_from_chart.sh.
    • Non-secret env vars have no shared manifest or equivalent sync path.
  • Service discovery is platform-specific but not modeled explicitly:
    • GKE callers use Kubernetes DNS.
    • Cloud Run callers need VPC/private endpoint routing, currently a dev internal ILB/IP for LLM Gateway.
  • Validation is too narrow:
    • backend/scripts/validate-llm-gateway-env.py checks chart-to-chart wiring only.
    • Backend Cloud Run deploys do not prove the deployed revision has required env/secrets or can reach internal services.

Target Architecture

Create one repo-owned backend runtime config manifest per environment, separating:

  • non-secret env vars: checked in and reviewable
  • secret bindings: checked-in names only, values remain in Secret Manager
  • service discovery endpoints: explicit per caller platform, e.g. GKE DNS vs Cloud Run private ILB/DNS
  • service-specific overrides: backend, backend-sync, backend-integration, backend-listen, llm-gateway

Use that manifest to generate or validate:

  • Helm-compatible env lists
  • Cloud Run env_vars
  • Cloud Run secret bindings
  • required private networking settings for Cloud Run callers

Prefer stable internal DNS or named internal load balancer addresses over undocumented raw IPs for Cloud Run-to-GKE service discovery.

Migration Plan

  1. Inventory current backend env vars from backend-listen Helm values and live Cloud Run services.
  2. Classify each var as non-secret, secret binding, service discovery, or service-specific override.
  3. Add a canonical manifest, for example backend/deploy/env/{dev,prod}.yaml.
  4. Build a renderer/validator that emits or verifies Helm env blocks, Cloud Run env vars, and Cloud Run secret bindings.
  5. Replace hardcoded Cloud Run values with manifest-derived values.
  6. Extend CI so PRs fail when backend runtime env changes are not represented in the manifest.
  7. Add deploy-time validation before traffic shift:
    • required env vars exist on the new Cloud Run revision
    • required secret bindings exist on the new Cloud Run revision
    • private networking settings are present when private endpoints are configured
    • same-network probe can reach required internal endpoints
  8. Remove duplicated definitions after the generated/validated path is proven in dev and one prod deploy.

Acceptance Criteria

  • Adding or changing a backend runtime env var fails CI unless it is classified in the canonical manifest.
  • Dev/prod Cloud Run backend services receive required secret bindings consistently with GKE when applicable.
  • Non-secret env vars required by backend runtime, including gateway config, are present on all intended Cloud Run services.
  • GKE backend-listen continues to use Kubernetes DNS for in-cluster service calls.
  • Cloud Run backend services use stable private service discovery instead of undocumented raw IPs.
  • Backend deploy workflows fail before traffic shift if rendered config and live revision config diverge.
  • LLM Gateway deploys keep their /ready and chat-completions smoke checks, and backend deploys also verify caller reachability.

Risks / Constraints

  • Some env vars intentionally differ between backend, backend-sync, and backend-integration; the manifest needs explicit override support.
  • A generator can become another drift source unless CI validates generated/rendered output.
  • Secret rotation must stay additive and non-disruptive during migration.
  • Cloud Run-to-GKE networking may need DNS/ILB cleanup before raw IPs can be fully removed.

Activity

  1. Git-on-my-level commented on Jun 29, 2026

    @Git-on-my-level
    MemberAuthor

    Additional production evidence from a read-only observability sweep on 2026-06-29 UTC supports this runtime-config drift issue.

    Sanitized Cloud Logging sweep:

    • Project: based-hardware
    • Service: Cloud Run backend-sync
    • Window: latest 24h at triage
    • Query: severity>=ERROR, bucketed by final exception / platform message

    Observed buckets:

    Bucket Sampled count Sanitized detail
    Startup TCP probe failures 99 Container did not start/listen on PORT=8080; connection failed with status CANCELLED.
    Missing credentials file 96 google.auth.exceptions... File google-credentials.json was not found.
    Memory document stale update 3 No document to update under sanitized users/<id>/memories/<id> paths.

    Current service state at triage was Ready, so this did not look like an active outage:

    • latestReadyRevisionName: backend-sync-00700-fw2
    • latestCreatedRevisionName: backend-sync-00700-fw2
    • service URL reported Ready by gcloud run services describe

    Why this belongs here: the google-credentials.json was not found startup burst is another concrete example of Cloud Run runtime/env/secret configuration drifting or failing validation during rollout. A future fix for this issue should include a deploy-time/runtime preflight that catches missing credential bindings before a revision receives traffic.

    No raw log payloads, user IDs, credentials, tokens, or request bodies are included here.

  2. Git-on-my-level commented on Jun 29, 2026

    @Git-on-my-level
    MemberAuthor

    One extra implementation note for this runtime-config issue: the 2026-06-29 backend-sync evidence specifically involved a revision that failed startup because google-credentials.json was missing, then recovered on the current ready revision.

    For the long-term fix, please make sure the canonical runtime config/preflight covers both styles used in this repo:

    • SERVICE_ACCOUNT_JSON / mounted-file expectations used by backend local/dev docs.
    • Any Cloud Run secret/file binding expected to materialize as google-credentials.json at runtime.

    The guard should fail before traffic if a revision expects a credential file/env binding that is absent. This would have caught the sampled backend-sync startup-probe burst without needing to wait for Cloud Logging.

  3. added a commit that references this issue on Jun 30, 2026
    ea411d7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions