Skip to content

fix(security): phase-1 agent VM /health auth (keep NAT, defer private cutover) - #10391

Merged
Git-on-my-level merged 8 commits into
mainfrom
fix/agent-vm-health-auth-phase1
Aug 4, 2026
Merged

Git-on-my-level merged 8 commits into
mainfrom
fix/agent-vm-health-auth-phase1

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Jul 23, 2026 •

Copy link
Copy Markdown
Member

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

  • 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
  • bash backend/scripts/apply-agent-vm-firewall.sh → exit 1 REFUSED
  • bash backend/scripts/agent-vm-reachability-check.sh → passed (hermetic; no production --live check)
  • 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.

Review in cubic

@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: ed8fdf0a9f

ℹ️ 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".

@Git-on-my-level
Git-on-my-level force-pushed the fix/agent-vm-health-auth-phase1 branch 2 times, most recently from 809cedd to 9d9379f Compare July 23, 2026 09:15
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Monitor run — firewall update idempotency fix

  • Fixed the Codex review (PRRT_kwDOLkKqys6TJ8pP): split GCLOUD_ARGS into mutable UPDATE_ARGS + create-only flags (--action, --direction, --network). gcloud compute firewall-rules update rejects these immutable flags, so the previous single-array approach would fail on idempotent re-apply during phase-3 cutover instead of refreshing an existing rule.
  • Added test_apply_script_update_path_omits_immutable_flags static contract test asserting the update path omits immutable flags while create still carries them.
  • Resolved the review thread.

Pre-existing backend unit failure (not addressed here): test_desktop_release_scripts.py::test_codemagic_produces_canonical_app_and_strictly_verifiable_dmg fails because upstream main refactored smoke-signed-desktop-artifact.sh to use dmg_app="$DMG_MOUNTPOINT/$dmg_app_name" instead of the hardcoded dmg_app="$DMG_MOUNTPOINT/Omi.app" the test still asserts. This PR does not touch desktop release scripts.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

agent VM /health auth — approved; touches auth so not auto-merged, flagged for Nik

@Git-on-my-level
Git-on-my-level force-pushed the fix/agent-vm-health-auth-phase1 branch from 9d9379f to 92ef6d7 Compare July 24, 2026 15:14
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Monitor run — rebased onto current main

Rebased this branch onto the latest origin/main (9067aff). The previous CI run was on a stale base where test_desktop_release_scripts::test_codemagic_produces_canonical_app_and_strictly_verifiable_dmg failed — that failure is gone from main and no longer reproduces.

After rebase, Desktop Swift Static Contracts now passes (was failing before on the stale base).

The remaining CI failures (Backend unit suite, Public Developer API contract) are pre-existing main breakage, not caused by this PR:

  • OpenAPI contract: docs/api-reference/app-client-openapi.json is stale on main (same failure on every backend-touching PR and on main pushes).
  • Backend unit suite: 9 pre-existing main failures (stale generated Swift/TS types, langchain_core import error, canonical_memory_vectors access-denied assertion, rate-limit count mismatch).

The PR's own tests (test_agent_vm_health_auth_contract.py 3 tests + test_agent_vm_firewall_contract.py 5 tests) pass locally against the rebased branch.

@Git-on-my-level
Git-on-my-level force-pushed the fix/agent-vm-health-auth-phase1 branch from 92ef6d7 to 93d9786 Compare July 24, 2026 19:14
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Monitor run — rebased onto latest main (09ce8a7)

Rebased this branch onto the latest origin/main (09ce8a7, 14 commits ahead of the previous base) and force-pushed. All 7 PR commits preserved with identical diff; desktop changelog and failure-class entries intact.

Verification before push:

  • 8 PR-specific backend contract tests pass (test_agent_vm_firewall_contract.py + test_agent_vm_health_auth_contract.py)
  • Firewall update path correctly omits immutable create-only flags (Codex P2 already addressed)
  • Desktop changelog entry present

Check status after rebase:
The 4 failing checks are all pre-existing on main, not introduced by this PR:

Check Status Root cause
Backend unit suite fail Pre-existing on main (3 recent main runs fail identically). Failing test files (canonical_memory_vectors, lock_bypass_fixes, memories_create, rate_limiting, etc.) have zero overlap with this PR's changed files.
Public Developer API contract fail Pre-existing on main. Stale OpenAPI spec unrelated to agent-proxy/desktop changes.
Desktop Swift Test Suites fail SwiftPM lock-contention flake (PushToTalkStateMachineTests / QueryTracerTests timeout: "Another instance of SwiftPM is already running"). Same failure on main runs 9c295ff and bd272c1; passes intermittently.
Desktop Swift Build & Tests fail Gate job mirroring the Test Suites flake above.

Review threads: The single Codex P2 thread (firewall create-only flags) remains resolved. No new review comments on the rebased head.

Git-on-my-level and others added 7 commits July 25, 2026 06:11
Unauthenticated GET /health leaked databaseReady on public :8080.
Require the existing VM token (Bearer or ?token=) and update
agent-proxy + desktop health callers so readiness probes keep working.

Verification: python3 -m pytest backend/tests/unit/test_agent_vm_health_auth_contract.py -v

Related #7326
Failure-Class: new

Co-authored-by: Cursor <[email protected]>
Extract insert-body/IP helpers and lock ONE_TO_ONE_NAT + omi-agent-vm
tag so phase-1 hardening cannot accidentally drop public reachability.

Verification: cd desktop/macos/Backend-Rust && cargo test agent::contract

Related #7326
Failure-Class: none

Co-authored-by: Cursor <[email protected]>
Prepare private-allow + public-deny rules for tag omi-agent-vm, but
refuse apply by default (AGENT_VM_FIREWALL_APPLY_PHASE3 gate). Do not
apply to prod until desktop upload/sync is proxied and cross-VPC
reachability exists.

Verification: python3 -m pytest backend/tests/unit/test_agent_vm_firewall_contract.py -v
              bash backend/scripts/apply-agent-vm-firewall.sh  # exits 1 REFUSED

Related #7326
Failure-Class: none

Co-authored-by: Cursor <[email protected]>
Related #7326
Failure-Class: none

Co-authored-by: Cursor <[email protected]>
desktop/macos/AGENTS.md already exceeds its byte budget on main; any
AGENTS.md touch selects agents-md-lean and fails. Deferred firewall
docs remain in backend/charts/agent-vm-firewall/firewall-rule.yaml and
apply-agent-vm-firewall.sh.

Related #7326
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]>
gcloud compute firewall-rules update rejects --action, --direction,
and --network (immutable after creation). The apply script reused a
single GCLOUD_ARGS array for both create and update, so updating an
existing rule during phase-3 cutover would fail instead of refreshing.

Split into UPDATE_ARGS (mutable attributes) + create-only flags
appended only to the create path. Added a static contract test that
asserts the update line omits immutable flags while the create block
still carries them.

Addresses Codex review PRRT_kwDOLkKqys6TJ8pP.
@Git-on-my-level
Git-on-my-level force-pushed the fix/agent-vm-health-auth-phase1 branch from 93d9786 to dd7a8ec Compare July 24, 2026 23:13
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Rebased onto latest main to resolve stale-branch CI failures (langchain_core.messages import error). Resolved a Swift test merge conflict: upstream main refactored AgentSyncBatchQueryTests with a new AgentSyncReplacementCallbackGate and restructured AgentSyncRecoveryProbe, while this PR adds auth-header tracking on /health probes. Merged both — kept upstream's gate/probe refactor and layered the PR's lastHealthAuthorization/lastHealthTokenQuery capture + accessor + auth assertions into the refactored probe.

Backend agent-vm health auth and firewall contract tests pass; Swift file parses clean.

All checks green.

@undivisible

Copy link
Copy Markdown
Collaborator

#10686 supersedes the agent.mjs publication step with a versioned Python VM image and GCS startup artifact. Keep this PR’s health-auth rollout order when resolving overlap.

@Git-on-my-level

Copy link
Copy Markdown
Member Author

@cursor address merge conflicts

@cursor

cursor Bot commented Aug 4, 2026 •

Copy link
Copy Markdown

Merge conflicts are resolved and pushed to fix/agent-vm-health-auth-phase1.

What conflicted: main removed the retired Node (agent.mjs) and Rust (Backend-Rust/src/routes/agent.rs) agent surfaces in favor of the Python cutover (backend/agent_vm/, backend/routers/desktop_agent_vm.py), while this branch still had health-auth edits on the old files.

Resolution:

  • Accepted main's deletions — removed both conflicted files
  • Ported /health auth gating to backend/agent_vm/main.py (runtime.require_auth(request))
  • Updated contract tests to target the new Python surfaces:
    • test_agent_vm_health_auth_contract.py → backend/agent_vm/main.py
    • test_agent_vm_firewall_contract.py → backend/routers/desktop_agent_vm.py
    • test_agent_vm_protocol.py → health now requires token (401 without, 200 with Bearer/?token=)
  • Updated FC-agent-vm-public-health-unauth.json scope hints for the Python agent VM

Unchanged (already merged cleanly): Swift callers (AgentSyncService, AgentVMService), agent-proxy Bearer headers, firewall IaC, and Swift auth assertions in AgentSyncBatchQueryTests.

Verification: All 9 PR-specific backend contract tests pass.

Rollout note: The PR's manual step to publish agent.mjs to GCS is obsolete — #10686 superseded that with a versioned Python VM image. The caller-before-gate order still applies: deploy agent-proxy and ship desktop with auth headers before VMs enforce /health auth.

Open in Web Open in Cursor 

Main retired agent.mjs and Backend-Rust agent.rs in favor of
backend/agent_vm and routers/desktop_agent_vm.py. Port /health auth
gating and contract tests to the Python surfaces; drop the deleted
Node/Rust files instead of keeping stale edits.

Verification: pytest test_agent_vm_health_auth_contract.py
test_agent_vm_firewall_contract.py test_agent_vm_protocol (health auth)

Co-authored-by: David Zhang <[email protected]>
@Git-on-my-level
Git-on-my-level merged commit 5c7eb50 into main Aug 4, 2026
47 of 48 checks passed
@Git-on-my-level
Git-on-my-level deleted the fix/agent-vm-health-auth-phase1 branch August 4, 2026 22:13
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.

4 participants