Repository navigation
Description
Summary
All Omi backend services currently authenticate to GCP (Firestore, Firebase Auth, GCS, Pub/Sub, etc.) using a long-lived service-account JSON key — either shipped as a file (google-credentials.json) or injected as an env var (SERVICE_ACCOUNT_JSON). This is flagged by Google as one of the highest-risk credential patterns and should be replaced with keyless authentication (Application Default Credentials backed by GKE Workload Identity, Workload Identity Federation for Modal/CI, and user ADC for local dev).
Why this is a problem
Long-lived service-account keys have well-known drawbacks:
- Never expire — if leaked (git history, image layer, log line, backup, laptop compromise), an attacker has persistent access until the key is manually rotated.
- Hard to rotate — rotation requires coordinated redeploys across every service that embeds the key.
- Blast radius — the same key is reused across multiple services, making least-privilege IAM and audit attribution difficult.
- Baked into Docker images — in at least one service the key is
COPY'd into the image at build time (see below), meaning anyone with pull access to the registry has the key. - Developer machines hold production-adjacent keys — the setup docs instruct developers to place a JSON key on disk.
- OWASP A02 (Cryptographic Failures) / A07 (Identification & Authentication Failures) — secrets-at-rest and broken authentication exposure.
- Google's own guidance: [Best practices for managing service account keys](https://cloud.google.com/iam/docs/best-practices-for-managing-service-account-keys) explicitly recommends avoiding keys in favor of Workload Identity / WIF.
Current state in the codebase
1. SERVICE_ACCOUNT_JSON env var carrying the full key
main.py
if os.environ.get('SERVICE_ACCOUNT_JSON'):
service_account_info = json.loads(os.environ["SERVICE_ACCOUNT_JSON"])
credentials = firebase_admin.credentials.Certificate(service_account_info)
firebase_admin.initialize_app(credentials)
else:
firebase_admin.initialize_app()Same pattern in:
- main.py
- job.py
2. GOOGLE_APPLICATION_CREDENTIALS pointing at a JSON key file on disk
main.py
cred_path = os.environ.get("GOOGLE_APPLICATION_CREDENTIALS")
if cred_path:
firebase_admin.initialize_app(credentials.Certificate(cred_path))
else:
firebase_admin.initialize_app()3. Key file copied directly into a container image
Dockerfile
# CI writes google-credentials.json to backend/ before build (gcp_backend_pusher.yml)
COPY backend/google-credentials.json ./google-credentials.json
4. Helm chart injecting the key path from a K8s Secret
prod_omi_backend_listen_values.yaml
- name: GOOGLE_APPLICATION_CREDENTIALS
valueFrom:
secretKeyRef:
name: ...
key: GOOGLE_APPLICATION_CREDENTIALS5. Developer setup instructs copying a key onto local disk
Backend_Setup.mdx
cp ~/.config/gcloud/application_default_credentials.json ./google-credentials.json
6. Tests force a JSON key even though they call ApplicationDefault()
conftest.py
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = backend_dir + "/" + os.getenv('GOOGLE_APPLICATION_CREDENTIALS')
...
cred = credentials.ApplicationDefault()
firebase_admin.initialize_app(cred)Also affected: 001_enhanced_protection_default.py and all sibling migration scripts (002–006), plus backend/scripts/stt/* which prepend paths to GOOGLE_APPLICATION_CREDENTIALS.
Proposed fix — keyless authentication end-to-end
Target state: every service calls firebase_admin.initialize_app() / credentials.ApplicationDefault() with no JSON key anywhere. The environment supplies the identity.
GKE workloads (backend, pusher, diarizer, agent-proxy)
-
Create one GCP service account per workload, least-privilege IAM (e.g.
backend-listen-sa,pusher-sa,agent-proxy-sa). -
Enable GKE Workload Identity on the cluster (if not already).
-
Bind each K8s ServiceAccount to its GCP SA via
roles/iam.workloadIdentityUserand annotate:serviceAccount: annotations: iam.gke.io/gcp-service-account: backend-listen-sa@<project>.iam.gserviceaccount.com
-
Remove
GOOGLE_APPLICATION_CREDENTIALS,SERVICE_ACCOUNT_JSON, and any JSON-key mounts from:backend/charts/backend-listen/*values.yamlbackend/charts/pusher/*values.yamlbackend/charts/diarizer/*values.yamlbackend/charts/agent-proxy/*values.yaml
-
Remove
COPY backend/google-credentials.jsonfrom Dockerfile (and any other Dockerfiles that bake it in). -
Simplify [main.py](http://main.py/) in each service to just
firebase_admin.initialize_app()— the google-auth library discovers the metadata-server identity automatically.
Modal workloads (job.py, vad)
Modal doesn't run on GCP, so metadata-server ADC isn't available. Preferred:
- Workload Identity Federation with OIDC: configure a WIF pool that trusts Modal's OIDC issuer, exchange the token for a short-lived GCP access token at startup.
- Fallback: store the key in Modal Secrets (never in the image), scope the SA to only what the job needs, and enable periodic rotation.
CI / GitHub Actions
- Replace any JSON-key usage with
google-github-actions/auth@v2usingworkload_identity_provider+service_account. - Remove any step that writes
google-credentials.jsoninto the repo/build context (e.g. the one referenced ingcp_backend_pusher.yml).
Local development
Update Backend_Setup.mdx to recommend:
gcloud auth application-default login
# optionally impersonate a lower-privilege SA:
gcloud auth application-default login \\
--impersonate-service-account=dev-readonly@<project>.iam.gserviceaccount.comand drop the instruction to copy the key to ./google-credentials.json. Ensure google-credentials.json stays in .gitignore and .dockerignore.
Tests
In conftest.py, stop forcing GOOGLE_APPLICATION_CREDENTIALS to a committed-style file path; let ADC discover the developer's gcloud login:
cred = credentials.ApplicationDefault()
firebase_admin.initialize_app(cred)Migrations and backend/scripts/stt/* should follow the same pattern.
Org-level hardening (once migration is complete)
- Enable Org Policies:
constraints/iam.disableServiceAccountKeyCreationconstraints/iam.disableServiceAccountKeyUploadconstraints/iam.serviceAccountKeyExpiryHours(belt-and-suspenders if any keys remain)
- Delete all existing JSON keys for the affected service accounts after cutover.
- Add a CI check that fails on any
google-credentials.jsonorSERVICE_ACCOUNT_JSONreference incharts/, Dockerfiles, or.envexamples. - Add Security Command Center / Cloud Asset Inventory alert on any new SA key creation.
Migration plan (low-risk order)
- Inventory every GCP SA currently in use and map → service + required IAM roles.
- Create per-service GCP SAs with least-privilege roles.
- Enable GKE Workload Identity on the target cluster.
- Migrate
agent-proxyfirst (lowest traffic), verify in prod. - Migrate
diarizer, thenpusher, then backend. - Migrate Modal jobs (
notifications-job,vad) via WIF-OIDC. - Migrate GitHub Actions workflows to WIF.
- Update Backend_Setup.mdx and [conftest.py](http://conftest.py/).
- Rotate & delete all remaining JSON keys.
- Enable org policies blocking new key creation.
- Add CI guardrail grepping for forbidden patterns.
Acceptance criteria
- No service reads
SERVICE_ACCOUNT_JSONor a JSON key file at startup. - No Helm chart, Dockerfile, or CI workflow contains
google-credentials.jsonor injectsGOOGLE_APPLICATION_CREDENTIALSpointing at a key. - All existing service-account keys listed in GCP IAM for these workloads are deleted.
- Org policy
iam.disableServiceAccountKeyCreationis enforced. - Local dev and integration tests work with only
gcloud auth application-default login. - CI guardrail rejects PRs reintroducing key-file patterns.
References
- [Google: Best practices for managing service account keys](https://cloud.google.com/iam/docs/best-practices-for-managing-service-account-keys)
- [GKE Workload Identity](https://cloud.google.com/kubernetes-engine/docs/concepts/workload-identity)
- [Workload Identity Federation](https://cloud.google.com/iam/docs/workload-identity-federation)
- [google-github-actions/auth](https://github.com/google-github-actions/auth)
Activity
undivisible commentedon Jul 26, 2026
Partial hardening in #10678: Pusher stops mounting Kubernetes API credentials and removes its redundant GOOGLE_APPLICATION_CREDENTIALS binding, while retaining SERVICE_ACCOUNT_JSON for compatibility. The broader keyless Workload Identity migration in this issue remains open.
Mukeshkr-19 commentedon Aug 2, 2026
Hi! I investigated the current main branch, issue history, PR #6980, the OpenTofu/WIF work (#9846, #9848, #9884), and later partial credential changes including #9169, #9733, #9893, #10173, and #10678.
I do not want to claim the full #6800 migration. Several GKE workloads, Cloud Run jobs, backend paths, and GitHub Actions workflows still have compatibility dependencies on JSON credentials, and safely removing them requires live IAM and runtime preparation.
As an independently testable first phase, would maintainers welcome a repository-only CI ratchet that prevents any new long-lived Google service-account JSON paths while baselining the current known compatibility paths?
The proposed checker would cover new or expanded production usage in:
It would ignore documentation, tests, explicit negative fixtures, and unrelated firmware keys. It would not remove or alter any existing deployment credentials, require GCP access, or interfere with reductions in current key usage. I would integrate it with the existing checks manifest and add deterministic positive and negative tests.
Is this narrow phase welcome, and is anyone already implementing something similar?
aryanorastar commentedon Aug 5, 2026
Shipping the repository-only first phase as #11125: a shrink-only CI ratchet on charts/deploy/modal/workflows + critical backend load sites (
google-credentials.json,SERVICE_ACCOUNT_JSON,from_service_account_info,credentials_json:), plus Backend_Setup ADC guidance (no more copy-to-./google-credentials.json).This matches @Mukeshkr-19's 2026-08-02 proposal — no live IAM/runtime credential removal in this PR. Follow-ups still needed for agent-proxy WI, GCS signed-URL
signBlob, Modal OIDC→WIF, and Actions WIF.fix(ci): tighten GCP SA key ratchet coverage (BasedHardware#6800)
fix(ci): keep empty GCP SA key baseline shrink-only (BasedHardware#6800)
fix(ci): ratchet long-lived GCP SA key paths (BasedHardware#6800)
fix(ci): tighten GCP SA key ratchet coverage (BasedHardware#6800)
fix(ci): keep empty GCP SA key baseline shrink-only (BasedHardware#6800)
chore(ci): rebase SA key baseline for main remove-env-vars hit (Based…
fix(ci): ratchet long-lived GCP SA key paths (#6800) (#11125)