Skip to content

fix(e2e): allow host mocks through UFW - #8708

Merged
senthilr-nv merged 5 commits into
mainfrom
codex/fix-e2e-host-mock-ufw
Aug 10, 2026
Merged

fix(e2e): allow host mocks through UFW#8708
senthilr-nv merged 5 commits into
mainfrom
codex/fix-e2e-host-mock-ufw

Conversation

@senthilr-nv

@senthilr-nv senthilr-nv commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Summary

Live E2E host mocks now add one temporary UFW rule after the OpenShell Docker bridge appears. The fixture limits the rule to the detected bridge interface, subnet, gateway, and mock port, then restores the original UFW rule set during cleanup.

Related Issue

Fixes #8696

Changes

  • Add a host-mock firewall fixture that waits for the historical installer to create the OpenShell bridge, validates its IPv4 bridge interface and address, and applies one exact TCP rule. An inline rule before installation cannot derive a network that does not exist yet. The openshell-gateway-upgrade live E2E test is the current consumer, and host-mock-firewall.test.ts protects the contract.
  • Register cleanup before the UFW write. Cleanup inspects UFW state after an ambiguous apply result, removes only a fixture-owned rule, and requires the complete pre-change UFW snapshot after deletion.
  • Report the detected bridge, subnet, gateway, port, and manual UFW command when automatic remediation is not authorized or cannot complete.
  • Add regression tests for applied, inactive, pre-existing, denied, invalid, interrupted, timed-out, cleanup-before-mutation, cleanup-failure, and concurrent setup outcomes. Existing host-only readiness coverage did not model an active default-deny UFW boundary.

Type of Change

  • Code change (feature, bug fix, or refactor)
  • Code change with doc updates
  • Doc only (prose changes, no code sample modifications)
  • Doc only (includes code sample changes)

Quality Gates

  • Tests added or updated for changed behavior
  • Existing tests cover changed behavior — justification:
  • Tests not applicable — justification:
  • Docs updated for user-facing behavior changes
  • Docs not applicable — justification: This changes live E2E fixture execution only. It does not change a supported command, configuration, workflow, or documented product behavior.
  • Sensitive paths changed (security, policy, credentials, preflight, onboarding, inference, runner, sandbox, or messaging)
  • Sensitive-path review completed or maintainer-approved waiver recorded — reviewer/approval link/justification: Codex Desktop reviewed input validation, live-E2E authorization, exact UFW scope, partial-write recovery, interruption cleanup, and baseline restoration. The maintainer approved issue scope in the implementation task.
  • Non-success, skipped, or missing CI check accepted by maintainer — check name, approval link, and follow-up issue:

Documentation Writer Review

  • Documentation writer subagent reviewed the completed changes
  • Result: no-docs-needed
  • Evidence: The change affects only live E2E fixtures, helpers, and regression tests. It does not change a supported command, configuration, workflow, or documented product behavior.
  • Agent: Codex Desktop

DGX Station Hardware Evidence

  • Tested on DGX Station
  • Tested commit: Not applicable
  • Station profile/scenario: Not applicable
  • Result: Not applicable
  • Supporting evidence: Not applicable

Verification

  • PR description includes a Signed-off-by: line and every commit appears as Verified in GitHub
  • Normal pre-commit, commit-msg, and pre-push hooks passed, or npm run validate:pr passed after refreshing origin/main when hooks were skipped or unavailable
  • Targeted behavior tests pass for the current change set, or tests are marked not applicable above — command/result or justification: Focused E2E support coverage passed 19 tests in 2 files. npm run test:changed passed 10 tests in 1 file for the review repair. npm run test:e2e-phases:check validated 125 tests across 81 files. npm run test-conditionals:scan -- --top 25 passed.
  • Applicable broad gate passed — npm test for broad runtime/test-harness changes; npm run check for repo-wide validation/coverage changes — command/result:
  • Quality Gates section completed with required justifications or waivers
  • No secrets, API keys, or credentials committed
  • npm run docs builds without warnings (doc changes only)
  • Doc pages follow the style guide (doc changes only)
  • New doc pages include SPDX header and frontmatter (new pages only)

Signed-off-by: Senthil Ravichandran senthilr@nvidia.com

Summary by CodeRabbit

  • New Features

    • Added automatic firewall setup for Linux-based host mock environments during gateway upgrades.
    • Detects the required network bridge and configures access when authorized.
    • Provides setup results and manual remediation guidance when automatic configuration is unavailable.
  • Bug Fixes

    • Safely cleans up firewall changes without overwriting unexpected external changes.
    • Reports individual or combined gateway upgrade setup failures clearly.
  • Tests

    • Added comprehensive coverage for firewall detection, rule management, interruptions, timeouts, and cleanup failures.

@senthilr-nv senthilr-nv self-assigned this Aug 10, 2026
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a host firewall fixture for live E2E mocks. It discovers Docker bridge topology, applies and cleans up an exact UFW rule, reports remediation details, and integrates concurrent setup failure handling with the gateway upgrade test.

Changes

Host mock firewall

Layer / File(s) Summary
Topology contracts and validation
test/e2e/fixtures/host-mock-firewall.ts
Adds the firewall API, Docker network validation, bounded network polling, and bridge address verification.
UFW rule lifecycle
test/e2e/fixtures/host-mock-firewall.ts
Handles platform and UFW states, authorization, exact rule application, post-application verification, and safe cleanup.
Gateway upgrade integration and failure handling
test/e2e/live/openshell-gateway-upgrade.test.ts, test/e2e/live/openshell-gateway-upgrade-helpers.ts, test/e2e/support/openshell-gateway-upgrade-workflow-boundary.test.ts
Runs firewall setup with legacy installation and propagates one or multiple setup failures.
Firewall behavior validation
test/e2e/support/host-mock-firewall.test.ts
Covers successful setup, pre-existing rules, unsupported states, interruptions, timeouts, verification failures, and cleanup failures.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant UpgradeTest
  participant FakeOpenAIServer
  participant HostMockFirewall
  participant Docker
  participant UFW
  participant CleanupRegistry

  UpgradeTest->>FakeOpenAIServer: start fake endpoint
  UpgradeTest->>HostMockFirewall: register endpoint port
  HostMockFirewall->>Docker: inspect bridge network
  Docker-->>HostMockFirewall: return subnet and gateway
  HostMockFirewall->>UFW: apply exact rule
  UFW-->>HostMockFirewall: return mutation result
  UpgradeTest->>UpgradeTest: run installation and firewall setup concurrently
  UpgradeTest->>FakeOpenAIServer: close server on registration failure
  CleanupRegistry->>UFW: restore baseline rule state
Loading

Suggested labels: bug-fix

Suggested reviewers: cv

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The fixture, live-test integration, cleanup handling, diagnostics, and regression tests satisfy the firewall remediation objectives in [#8696].
Out of Scope Changes check ✅ Passed All changes support UFW access for live E2E host mocks, setup failure handling, cleanup, or regression coverage.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: allowing E2E host mocks through UFW.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-e2e-host-mock-ufw

Comment @coderabbitai help to get the list of available commands.

@github-code-quality

github-code-quality Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Code Coverage Overview

Languages: TypeScript

TypeScript / code-coverage/plugin

The overall coverage in commit 6044319 in the codex/fix-e2e-host-m... branch remains at 96%, unchanged from commit 07d57ed in the main branch.

TypeScript / code-coverage/cli

The overall coverage in commit 6044319 in the codex/fix-e2e-host-m... branch remains at 82%, unchanged from commit fa2b577 in the main branch.

Show a code coverage summary of the most impacted files.
File main fa2b577 codex/fix-e2e-host-m... 6044319 +/-
src/lib/messagi...annel-config.ts 99% 95% -4%
src/lib/agent/g...tart-scripts.ts 100% 97% -3%
src/lib/policy/index.ts 67% 67% 0%
src/lib/inferen...ter-topology.ts 89% 89% 0%
src/lib/inferen...ter-registry.ts 95% 96% +1%
src/lib/inferen...-ssh-binding.ts 87% 89% +2%
src/lib/inferen...talog-loader.ts 80% 84% +4%
src/lib/inferen...er-lifecycle.ts 70% 77% +7%
src/lib/inferen...del-registry.ts 93% 100% +7%
src/lib/inferen...time-context.ts 84% 93% +9%

Updated August 10, 2026 07:44 UTC

@senthilr-nv senthilr-nv added chore Build, CI, dependency, or tooling maintenance area: e2e End-to-end tests, nightly failures, or validation infrastructure area: networking DNS, proxy, TLS, ports, host aliases, or connectivity security v0.0.106 labels Aug 10, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
test/e2e/fixtures/host-mock-firewall.ts (1)

263-467: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy lift

Split the firewall lifecycle into smaller phases.

registerOpenShellHostMockFirewall combines validation, topology discovery, UFW inspection, mutation, and cleanup coordination. The shared state flags make lifecycle ownership difficult to verify. Extract focused phases and isolate the cleanup state coordinator.

As per coding guidelines, keep function complexity low.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/e2e/fixtures/host-mock-firewall.ts` around lines 263 - 467, The
registerOpenShellHostMockFirewall function is too complex and mixes validation,
topology discovery, UFW inspection, mutation, and cleanup state. Split these
responsibilities into focused helper functions, including a dedicated
cleanup-state coordinator that owns applyInFlight, baselineRules,
mutationStarted, closed, topology, and rule access; keep
registerOpenShellHostMockFirewall as orchestration and preserve all existing
results, errors, authorization checks, and cleanup behavior.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@test/e2e/fixtures/host-mock-firewall.ts`:
- Around line 416-425: In the setup flow around mutationStarted and
applyInFlight, check closed immediately before invoking options.host.command to
apply the UFW rule; if cleanup has started, abort without setting
mutationStarted or issuing the mutation. Preserve the existing post-apply closed
check for interruptions that occur during the command.

In `@test/e2e/live/openshell-gateway-upgrade.test.ts`:
- Around line 1191-1201: Update the firewall setup handling around
registerOpenShellHostMockFirewall to await its returned promise inside the
existing try/catch, so asynchronous topology, authorization, and UFW failures
reach the catch. Ensure fake.close() runs before rethrowing any rejected
firewall setup, including the corresponding setup block noted by the review.

In `@test/e2e/support/host-mock-firewall.test.ts`:
- Around line 91-95: Update the test helper method containing this
call-recording and response-shifting logic to remove the if statement. Replace
the exhausted-queue check with a nullish fallback that throws the same
unexpected-command error, while preserving function-response invocation and
direct response returns.

---

Nitpick comments:
In `@test/e2e/fixtures/host-mock-firewall.ts`:
- Around line 263-467: The registerOpenShellHostMockFirewall function is too
complex and mixes validation, topology discovery, UFW inspection, mutation, and
cleanup state. Split these responsibilities into focused helper functions,
including a dedicated cleanup-state coordinator that owns applyInFlight,
baselineRules, mutationStarted, closed, topology, and rule access; keep
registerOpenShellHostMockFirewall as orchestration and preserve all existing
results, errors, authorization checks, and cleanup behavior.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 8192ea87-b18b-4e0e-bd1c-ef5aa36d2dc4

📥 Commits

Reviewing files that changed from the base of the PR and between 04e28aa and 62d7480.

📒 Files selected for processing (3)
  • test/e2e/fixtures/host-mock-firewall.ts
  • test/e2e/live/openshell-gateway-upgrade.test.ts
  • test/e2e/support/host-mock-firewall.test.ts

Comment thread test/e2e/fixtures/host-mock-firewall.ts
Comment thread test/e2e/live/openshell-gateway-upgrade.test.ts
Comment thread test/e2e/support/host-mock-firewall.test.ts
@senthilr-nv
senthilr-nv requested a review from cv August 10, 2026 07:12
@github-actions

github-actions Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

PR Review Advisor — No blocking findings reported

Advisor assessment: No blocking advisor findings reported
Next action: Review the warnings below.
Findings: 0 blockers · 1 warning · 0 suggestions

Model lanes

  • GPT-5.6 Terra (primary): Completed · high confidence · 0 blockers · 1 warning · 0 suggestions
  • Nemotron 3 Ultra (second opinion): Completed · high confidence · 0 blockers · 0 warnings · 0 suggestions
  • Model comparison: normalized findings differ; normalized terminology decisions differ; normalized E2E selections match; Nemotron reported the same number of blockers, 1 fewer warning, the same number of suggestions.
8 terminology differences from the second opinion

Advisory only. These are normalized differences from the primary terminology receipt.

  • UFW at test/e2e/fixtures/host-mock-firewall.ts:47: selected only by the second-opinion lane as established.
  • manual command at test/e2e/support/host-mock-firewall.test.ts:250: selected only by the second-opinion lane as established.
  • mutation at test/e2e/fixtures/host-mock-firewall.ts:284: selected only by the second-opinion lane as established.
  • gateway at test/e2e/fixtures/host-mock-firewall.ts:29: selected only by the second-opinion lane as established.
  • remediation at test/e2e/fixtures/host-mock-firewall.ts:155: selected only by the second-opinion lane as established.
  • host mock at test/e2e/fixtures/host-mock-firewall.ts:158: selected only by the second-opinion lane as define.
  • host mock firewall at test/e2e/fixtures/host-mock-firewall.ts:210: selected only by the second-opinion lane as define.
  • bridge interface at test/e2e/fixtures/host-mock-firewall.ts:102: selected only by the second-opinion lane as define.

Second-opinion terminology and E2E selections are advisory. Live E2E does not run automatically for pull requests.

2 semantic terminology decisions

Terminology decisions are advisory. They affect the assessment only when a separate finding identifies concrete semantic impact.

  • justified — host mock firewall at test/e2e/support/host-mock-firewall.test.ts:121: Keep `host mock firewall` for this host-side UFW fixture and its results.
  • justified — exact UFW rule at test/e2e/support/host-mock-firewall.test.ts:201: Keep `exact UFW rule` where rule identity determines whether cleanup may delete it.

E2E guidance

Advisory only. A maintainer can dispatch the default E2E suite against this exact revision.

Recommended E2E: cloud-inference, cloud-onboard, security-posture, openshell-gateway-upgrade

1 warning · 0 suggestions

Warnings

Warnings do not block.

PRA-1 Warning — Test cleanup after an external UFW rule change

  • Location: test/e2e/support/host-mock-firewall.test.ts:379
  • Category: tests
  • Problem: The fixture test suite does not cover cleanup when another process adds a UFW rule after the fixture applies its rule.
  • Impact: A change to the snapshot comparison or deletion arguments could remove an external rule or conceal that host UFW state was not restored.
  • Recommendation: Add one FakeHost test that adds a distinct UFW rule after setup, returns a successful fixture-rule deletion, and asserts that cleanup leaves the external rule present and reports the baseline mismatch.
  • Verification: Inspect the cleanup command calls and cleanup result in the new FakeHost test; the delete command must contain only the fixture rule and cleanup must report the final snapshot mismatch.
  • Test coverage: Add a focused fixture test for an external UFW rule added after setup that proves cleanup deletes only the fixture-owned rule and rejects the non-baseline final snapshot.
  • Evidence: test/e2e/fixtures/host-mock-firewall.ts:306-332 conditionally deletes the exact fixture rule and compares the final snapshot with baselineRules. test/e2e/support/host-mock-firewall.test.ts:379-417 tests rejected deletion but does not model a retained external UFW rule after successful deletion.

Workflow run details

This automated review informs maintainers. Warnings and suggestions do not require a response. A maintainer decides whether to merge.

@cv cv 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.

Blocking security finding on commit a578b188d9:

test/e2e/fixtures/host-mock-firewall.ts:416-424 can apply the UFW rule after cleanup has completed. If cleanup starts while the baseline ufw show added command is pending, cleanup sets closed, sees mutationStarted === false, and returns. Setup then resumes without checking closed, starts the UFW mutation, and throws only after the rule was applied. No cleanup remains to delete that rule. This violates #8696's interruption requirement and can leave the host firewall more permissive after the test exits.

Check closed immediately before setting mutationStarted and invoking ufw allow. Add a regression test that pauses the baseline-rule snapshot, starts cleanup, resolves the snapshot, and proves that no UFW apply command runs.

Security review result: FAIL for error recovery, security testing, and whole-operation state safety until this race is fixed. I found no credential, input-injection, authorization, dependency, cryptography, or unrelated configuration blocker.

@senthilr-nv

Copy link
Copy Markdown
Collaborator Author

@cv The blocking cleanup-race finding from your CHANGES_REQUESTED review is addressed in commit 76b735289. Setup now checks closed immediately before mutationStarted and ufw allow; the regression starts cleanup during the pending baseline snapshot and proves no apply command runs. Focused E2E support coverage passes 19/19, and CodeRabbit has confirmed and resolved the thread. Please review the fix when ready.

@senthilr-nv
senthilr-nv enabled auto-merge (squash) August 10, 2026 07:42
@senthilr-nv
senthilr-nv merged commit 69f67a2 into main Aug 10, 2026
51 checks passed
@senthilr-nv
senthilr-nv deleted the codex/fix-e2e-host-mock-ufw branch August 10, 2026 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: e2e End-to-end tests, nightly failures, or validation infrastructure area: networking DNS, proxy, TLS, ports, host aliases, or connectivity chore Build, CI, dependency, or tooling maintenance security

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Live E2E host mocks are unreachable through the OpenShell bridge on UFW-enabled Brev hosts

2 participants