Repository navigation
fix(security): phase-1 agent VM harden (keep NAT, defer private cutover) - #9261
Git-on-my-level wants to merge 5 commits into
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f5ad7e46dc
ℹ️ 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".
There was a problem hiding this comment.
4 issues found across 6 files
Confidence score: 2/5
- In
desktop/macos/Backend-Rust/src/routes/agent.rs, removingaccessConfigsmeanscreate_gce_vmcan no longer produce an external IP while itsResult<String>contract and downstream consumers still treat it as reachable over public network; merging as-is is likely to break agent provisioning/reachability flows — either restore external IP assignment or change the return contract and all callers before merging. AGENTS.mddescribesagent-vm-firewallas denying only publictcp:8080, butbackend/charts/agent-vm-firewall/firewall-rule.yamlusessourceRanges: [0.0.0.0/0]on a DENY ingress rule, which effectively blocks that port from everywhere and can cut off intended internal access paths — align the rule or documentation to the intended policy and verify expected traffic still works.backend/scripts/agent-vm-reachability-check.shrelies on Pythonassertfor firewall contract checks, andbackend/scripts/apply-agent-vm-firewall.shvalidates onlyDENYwhile not enforcing full contract fields (like ingress/public source ranges), so CI/deploy validation can silently pass unsafe or incorrect rules in some environments — replaceassertwith explicit runtime checks and enforce all security-critical fields before merging.
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Remove ONE_TO_ONE_NAT accessConfigs from GCE insert payload so new agent VMs are private-network only. Add Rust contract test guarding the provision JSON shape. Verification: cd desktop/macos/Backend-Rust && cargo test provision Related #7326 Co-authored-by: Cursor <[email protected]>
Add GCP firewall IaC for tag omi-agent-vm that denies public tcp:8080, with apply/reachability scripts and hermetic contract tests. Extend the Rust provision JSON contract to assert omi-agent-vm tagging and no public IP fields in the insert payload. Verification: cd desktop/macos/Backend-Rust && cargo test provision cd backend && python3 -m pytest tests/unit/test_agent_vm_firewall_contract.py -v backend/scripts/agent-vm-reachability-check.sh Closes #7326 Related #6611 Co-authored-by: Cursor <[email protected]>
f5ad7e4 to
d77624e
Compare
|
Monitor follow-up for PR #9261:
Verification passed:
|
Keep public NAT and tag omi-agent-vm; gate firewall apply as deferred phase-3. Auth-gate VM /health and update desktop + agent-proxy callers. Verification: cargo test agent::contract python3 -m pytest backend/tests/unit/test_agent_vm_firewall_contract.py -v Related #7326 Co-authored-by: Cursor <[email protected]>
Co-authored-by: Cursor <[email protected]>
|
Superseded by #10391 Rebuilt from current Closing this draft as CONFLICTING/stale since Jul 12. |
|
Superseded by #10391 (phase-1 /health auth, keep NAT). |
|
Hey @Git-on-my-level 👋 Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request. After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:
Before your next PR, please skim:
If this was declined for direction or taste, maintainers should cite an invariant ID or open a proposed one — ask if that citation is missing. Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out. Thank you for being part of the Omi community! |
Records the #7326 phase-1 contract: public agent VM /health must not expose readiness without the VM token. Evidence: prior attempt #9261. Failure-Class: none Co-authored-by: Cursor <[email protected]>
Records the #7326 phase-1 contract: public agent VM /health must not expose readiness without the VM token. Evidence: prior attempt #9261. Failure-Class: none Co-authored-by: Cursor <[email protected]>
Records the #7326 phase-1 contract: public agent VM /health must not expose readiness without the VM token. Evidence: prior attempt #9261. Failure-Class: none Co-authored-by: Cursor <[email protected]>
Records the #7326 phase-1 contract: public agent VM /health must not expose readiness without the VM token. Evidence: prior attempt #9261. Failure-Class: none Co-authored-by: Cursor <[email protected]>
) ## Summary Fixes the **cost half** of #7326: stopped `omi-agent-*` VMs keep billing ~50 GB `pd-balanced` boot disks because `autoDelete: true` only fires on instance **delete**, not stop. **Approach:** enable/fix the existing `backend/charts/agent-vm-reaper` CronJob (it was written but never deployed — no GSA, no CronJob in `prod-omi-backend`). Prefer reusing that machinery over new systems. - Extract selection/delete into `backend/scripts/agent_vm_reaper.py` (dry-run default; live gated) - Add refuse-by-default `backend/scripts/apply-agent-vm-reaper.sh` (creates GSA + WI + ConfigMap + CronJob) - TERMINATED grace: `lastStopTimestamp` ≥ **12h** (preserves same-day `start_stopped_vm` resume; after delete, status `NOT_FOUND` → clear Firestore → client re-provisions + DB upload) - RUNNING older than **2d** still reaped as abandoned - Checked-in CronJob default `DRY_RUN=true` so bare apply is log-only **Not in this PR:** public NAT removal / firewall cutover (phase-1 health-auth PR / #9261 lane). No network changes. ## Live evidence (2026-07-23, project `based-hardware`) | Metric | Value | |--------|-------| | Fleet | ~183 TERMINATED + ~104 RUNNING `omi-agent-*` | | Disk | 50 GB `pd-balanced` each | | Idle disk burn | ~183 × $5 ≈ **~$915/mo** | | Prod CronJob | **missing** (`kubectl -n prod-omi-backend get cronjob` — no reaper) | | GSA `agent-vm-reaper@…` | **NOT_FOUND** | | Node default SA | `roles/compute.viewer` only — dedicated WI SA required | Dry-run of this PR's script (`python3 backend/scripts/agent_vm_reaper.py --dry-run`): - **137** reapable now (85 TERMINATED ≥12h + 52 RUNNING ≥2d) - Immediate idle-disk savings from those TERMINATED ≈ **~$425/mo** - Remaining TERMINATED age into the 12h window → full idle-disk fleet bounded toward ~$0 beyond grace; steady-state savings ≈ **~$800–915/mo** once LIVE, plus abandoned RUNNING compute ## Manual steps after merge (required — no CD for this chart) ```bash # 1) Install IAM + CronJob in dry-run (log-only) AGENT_VM_REAPER_APPLY=1 bash backend/scripts/apply-agent-vm-reaper.sh # 2) Manual job + inspect logs kubectl -n prod-omi-backend create job --from=cronjob/prod-agent-vm-reaper agent-vm-reaper-manual-$(date +%s) kubectl -n prod-omi-backend logs job/<job-name> # 3) Enable deletes AGENT_VM_REAPER_APPLY=1 AGENT_VM_REAPER_LIVE=1 bash backend/scripts/apply-agent-vm-reaper.sh ``` Local inventory only (no mutation): `python3 backend/scripts/agent_vm_reaper.py --dry-run` ## Test plan - [x] `python3 -m pytest backend/tests/unit/test_agent_vm_reaper.py -v` → 9 passed (selection, dry-run, refuse gates, manifest defaults) - [x] `bash backend/scripts/apply-agent-vm-reaper.sh` without gate → REFUSED exit 1 - [x] Live dry-run against GCP inventory → 137 targets logged, zero deletes - [ ] After merge: apply dry-run CronJob, review logs, then LIVE=1 - [ ] Confirm TERMINATED count drops over ~24h; disks deleted with instances ## Relationship - **#7326** — progresses **cost** half only (partial). Full close still needs private networking / remove public NAT (deferred; depends on proxy routing + peer/move VMs). - **Health-auth / superseding #9261** — separate PR; this change does not touch agent-proxy, NAT, or firewall. Failure-Class: new <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/BasedHardware/omi/pull/10390?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="Review in cubic" src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a> <!-- End of auto-generated description by cubic. -->
… cutover) (#10391) ## Summary Phase-1, low-blast-radius harden for agent VM public `:8080` exposure (#7326) — **without** removing public NAT or applying a public DENY firewall (those break prod today). **Why not private-only yet:** agent VMs are on VPC `default`; `agent-proxy` is on GKE `omi-prod-vpc-1` with **no peering**. Desktop still calls `http://{vmIP}:8080` for upload/sync. Removing NAT or denying `0.0.0.0/0` would break chat + DB sync. ### This PR (safe to merge) - Keep `ONE_TO_ONE_NAT` / public IP provisioning - Keep / contract-test `omi-agent-vm` network tag - Auth-gate VM `/health` (was publicly readable `databaseReady`); update desktop + agent-proxy callers - Land deferred phase-3 firewall IaC with **apply refuse-by-default** (`AGENT_VM_FIREWALL_APPLY_PHASE3` gate) - Deferred cutover docs live in `backend/charts/agent-vm-firewall/firewall-rule.yaml` + apply script (refuse-by-default) ### Explicitly deferred (do not apply yet) | Step | Follow-up | |------|-----------| | Route desktop upload/sync through agent-proxy | **PR10c** (required before firewall cutover) | | Allowlist reserved Cloud NAT egress for proxy (or peer/move VMs) | infra | | Apply public DENY / remove NAT | phase 3 after the above are proven | | Terminated-disk / storage cost leak | later slice of #7326 | **Partial progress on #7326** (auth harden + prepare surface; not full network isolation or cost fix). **Supersedes #9261** (stale/CONFLICTING since Jul 12). ## Product invariants affected - INV-AUTH-1 (path-matched via `AgentSyncService.swift`; this PR only adds Bearer/`?token=` on VM `/health` probes — no Firebase session-death policy change) ## Failure-Class Failure-Class: new Registers `FC-agent-vm-public-health-unauth`: public agent VM `/health` must not expose readiness metadata without the VM auth token. Evidence: #9261 / #7326. ## Manual steps (post-merge; current Python runtime) This is a **phase-1 health-auth rollout only**. Keep public `ONE_TO_ONE_NAT` / public IP provisioning. Do not remove NAT, apply a public DENY firewall, or run the deferred phase-3 firewall script. PR #10686 retired the Node `agent.mjs` and Rust agent runtime in favor of the Python Agent VM image. Do **not** publish `agent.mjs` or update `version.txt` as the rollout mechanism. Use the current versioned image/startup workflow on merged `main`. **Safe order (callers before gate):** 1. **Deploy `agent-proxy` from merged `main` first.** Dispatch `.github/workflows/gcp_backend_agent_proxy.yml` with `environment=prod`. The workflow checks out `main`, builds/pushes `agent-proxy`, deploys it to `prod-omi-gke`, and waits for the GKE rollout to complete. 2. **Ship a desktop build with the Swift health-auth callers.** Use a beta/candidate containing the `AgentSyncService.swift` and `AgentVMService.swift` changes from this PR. Do not let VMs enforce the new health gate before this caller is available; otherwise desktop health checks receive `401` and may false-trigger DB re-upload paths. 3. **Choose the VM-image publication path deliberately.** The current `.github/workflows/desktop_backend_prod.yml` is a **combined desktop-backend production release**: in addition to building/publishing `gcr.io/based-hardware/agent-vm:<first-12-of-release-sha>` and `gs://based-hardware-agent/startup.sh`, it deploys and probes a desktop-backend candidate, then routes 100% of production traffic and can roll back. **Do not dispatch it solely to publish the VM image.** Use it only after separately approving that combined desktop-backend release, with the exact merged `release_sha`, normal release-eligibility proof, `confirm=deploy-desktop-backend-prod`, and a non-empty operator `reason`. There is no dedicated VM-only publisher currently; create and approve that path before a VM-only rollout. 4. **Verify before declaring the rollout complete:** - `curl -sS -i http://<vm-public-ip>:8080/health` returns `401` and no readiness metadata. - `curl -sS -i -H "Authorization: Bearer <vmToken>" http://<vm-public-ip>:8080/health` returns `200` with the expected `databaseReady` field. - Confirm the `agent-proxy` GKE rollout, the VM runtime/image identity, and desktop provision → upload/sync plus chat via `wss://agent.omi.me`. 5. **Stop and roll back** if unauthenticated health returns readiness data, an authenticated caller receives `401`, or upload/sync/chat regresses. Do not change firewall or NAT state while investigating. **Do not run** `backend/scripts/apply-agent-vm-firewall.sh`, remove public NAT, or use `--live` reachability against production until PR10c plus private reachability and the reserved Cloud NAT allowlist are proven. ## Test plan - [x] `cd backend && python3 -m pytest tests/unit/test_agent_vm_firewall_contract.py tests/unit/test_agent_vm_health_auth_contract.py tests/unit/test_agent_vm_protocol.py -v` → PR-specific backend contract tests pass - [x] `bash backend/scripts/apply-agent-vm-firewall.sh` → exit 1 `REFUSED` - [x] `bash backend/scripts/agent-vm-reachability-check.sh` → passed (hermetic; no production `--live` check) - [x] Swift recovery test asserts `/health` sends Bearer + `?token=` (`AgentSyncBatchQueryTests`) Merge with a **regular merge** (no squash). Do not auto-merge — coordinate the caller-before-gate deployment order above. <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/BasedHardware/omi/pull/10391?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="Review in cubic" src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a> <!-- End of auto-generated description by cubic. -->
…edHardware#10390) ## Summary Fixes the **cost half** of BasedHardware#7326: stopped `omi-agent-*` VMs keep billing ~50 GB `pd-balanced` boot disks because `autoDelete: true` only fires on instance **delete**, not stop. **Approach:** enable/fix the existing `backend/charts/agent-vm-reaper` CronJob (it was written but never deployed — no GSA, no CronJob in `prod-omi-backend`). Prefer reusing that machinery over new systems. - Extract selection/delete into `backend/scripts/agent_vm_reaper.py` (dry-run default; live gated) - Add refuse-by-default `backend/scripts/apply-agent-vm-reaper.sh` (creates GSA + WI + ConfigMap + CronJob) - TERMINATED grace: `lastStopTimestamp` ≥ **12h** (preserves same-day `start_stopped_vm` resume; after delete, status `NOT_FOUND` → clear Firestore → client re-provisions + DB upload) - RUNNING older than **2d** still reaped as abandoned - Checked-in CronJob default `DRY_RUN=true` so bare apply is log-only **Not in this PR:** public NAT removal / firewall cutover (phase-1 health-auth PR / BasedHardware#9261 lane). No network changes. ## Live evidence (2026-07-23, project `based-hardware`) | Metric | Value | |--------|-------| | Fleet | ~183 TERMINATED + ~104 RUNNING `omi-agent-*` | | Disk | 50 GB `pd-balanced` each | | Idle disk burn | ~183 × $5 ≈ **~$915/mo** | | Prod CronJob | **missing** (`kubectl -n prod-omi-backend get cronjob` — no reaper) | | GSA `agent-vm-reaper@…` | **NOT_FOUND** | | Node default SA | `roles/compute.viewer` only — dedicated WI SA required | Dry-run of this PR's script (`python3 backend/scripts/agent_vm_reaper.py --dry-run`): - **137** reapable now (85 TERMINATED ≥12h + 52 RUNNING ≥2d) - Immediate idle-disk savings from those TERMINATED ≈ **~$425/mo** - Remaining TERMINATED age into the 12h window → full idle-disk fleet bounded toward ~$0 beyond grace; steady-state savings ≈ **~$800–915/mo** once LIVE, plus abandoned RUNNING compute ## Manual steps after merge (required — no CD for this chart) ```bash # 1) Install IAM + CronJob in dry-run (log-only) AGENT_VM_REAPER_APPLY=1 bash backend/scripts/apply-agent-vm-reaper.sh # 2) Manual job + inspect logs kubectl -n prod-omi-backend create job --from=cronjob/prod-agent-vm-reaper agent-vm-reaper-manual-$(date +%s) kubectl -n prod-omi-backend logs job/<job-name> # 3) Enable deletes AGENT_VM_REAPER_APPLY=1 AGENT_VM_REAPER_LIVE=1 bash backend/scripts/apply-agent-vm-reaper.sh ``` Local inventory only (no mutation): `python3 backend/scripts/agent_vm_reaper.py --dry-run` ## Test plan - [x] `python3 -m pytest backend/tests/unit/test_agent_vm_reaper.py -v` → 9 passed (selection, dry-run, refuse gates, manifest defaults) - [x] `bash backend/scripts/apply-agent-vm-reaper.sh` without gate → REFUSED exit 1 - [x] Live dry-run against GCP inventory → 137 targets logged, zero deletes - [ ] After merge: apply dry-run CronJob, review logs, then LIVE=1 - [ ] Confirm TERMINATED count drops over ~24h; disks deleted with instances ## Relationship - **BasedHardware#7326** — progresses **cost** half only (partial). Full close still needs private networking / remove public NAT (deferred; depends on proxy routing + peer/move VMs). - **Health-auth / superseding BasedHardware#9261** — separate PR; this change does not touch agent-proxy, NAT, or firewall. Failure-Class: new <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/BasedHardware/omi/pull/10390?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="Review in cubic" src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a> <!-- End of auto-generated description by cubic. -->
Summary
Phase-1, low-blast-radius harden for agent VM public
:8080exposure (#7326) — without removing public NAT or applying a public DENY firewall (those break prod today).Why not private-only yet: agent VMs are on VPC
default;agent-proxyis on GKEomi-prod-vpc-1with no peering. Desktop still callshttp://{vmIP}:8080for upload/sync. Removing NAT or denying0.0.0.0/0would break chat + DB sync.This PR (safe to merge)
ONE_TO_ONE_NAT/ public IP provisioningomi-agent-vmnetwork tag/health(was publicly readabledatabaseReady); update desktop + agent-proxy callersAGENT_VM_FIREWALL_APPLY_PHASE3gate)AGENTS.mddescribing the deferred cutoverExplicitly deferred (do not apply yet)
Related: #6611
Closes: partial progress on #7326 (auth harden + prepare surface; not full network isolation)
Test plan
After merge / deploy (auth path):
desktop/macos/agent-cloud/agent.mjsto the agent GCS artifact bucket (VMs hot-reload from GCS).agent-proxy+ desktop-backend as needed for caller header changes.GET http://<vm-public-ip>:8080/health→401.?token=) →200withdatabaseReady.wss://agent.omi.mestill works.Do not run
apply-agent-vm-firewall.shor--livereachability against prod until PR10c + private reachability land.Merge with a regular merge (no squash).
Made with Cursor