Refactor host iptables into focused modules with a stable public facade#3030
Conversation
✅ Coverage Check PassedOverall Coverage
📁 Per-file Coverage Changes (2 files)
✨ New Files (4 files)
Coverage comparison generated by |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Pull request overview
This PR refactors the security-critical host iptables implementation into smaller, concern-focused modules while preserving the existing public import surface via a thin src/host-iptables.ts facade.
Changes:
- Replaced the monolithic
src/host-iptables.tsimplementation with a stable facade that re-exports the existing public API. - Extracted shared constants/state and helper functions (bridge/gateway lookup, IPv6/sysctl state) into a shared module.
- Split network lifecycle and iptables cleanup into dedicated modules to reduce responsibility overlap.
Show a summary per file
| File | Description |
|---|---|
| src/host-iptables.ts | Converts the original module into a stable public facade re-exporting the same API and preserving __testing._resetIpv6State. |
| src/host-iptables-shared.ts | Introduces shared constants and helper functions (bridge name lookup, gateway lookup, IPv6 availability + sysctl toggling/state). |
| src/host-iptables-rules.ts | Contains the extracted setupHostIptables, isValidPortSpec, and related rule construction logic and types. |
| src/host-iptables-network.ts | Contains the extracted Docker network creation/removal logic for the firewall network. |
| src/host-iptables-cleanup.ts | Contains the extracted iptables/ip6tables cleanup logic plus IPv6 sysctl re-enable behavior. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 5/5 changed files
- Comments generated: 1
| /** | ||
| * Creates the dedicated firewall network if it doesn't exist | ||
| * Returns the Squid and agent IPs | ||
| */ | ||
| export async function ensureFirewallNetwork(): Promise<{ | ||
| subnet: string; | ||
| squidIp: string; | ||
| agentIp: string; | ||
| proxyIp: string; | ||
| }> { |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@copilot address the review feedback |
Smoke Test: Copilot BYOK (Offline) Mode
Running in BYOK offline mode ( Overall: FAIL — pre-step outputs were not interpolated into the prompt; GitHub MCP returned 401.
|
Smoke Test Results✅ Playwright: GitHub page title verified Status: FAIL (3/4 tests passed)
|
🧪 Smoke Test Results
Overall: PARTIAL PASS (infra checks pass; MCP auth unavailable)
|
|
Smoke test Codex: FAIL Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "registry.npmjs.org"See Network Configuration for more information.
|
🏗️ Build Test Suite Results
Overall: 8/8 ecosystems passed — ✅ PASS
|
Smoke Test Results — Services Connectivity
Overall: FAIL —
|
Chroot Smoke Test Results
Overall: ❌ FAILED — Python and Node.js versions differ between host and chroot environment.
|
✨ Enhancement
src/host-iptables.tshad grown into a 700+ line mixed-responsibility module, with a 379-linesetupHostIptablespath handling multiple security-critical rule categories. This PR decomposes the file by concern to make firewall behavior easier to audit and evolve without changing call sites.What does this improve?
./host-iptablesunchanged.Why is this valuable?
Implementation approach:
src/host-iptables-network.ts:ensureFirewallNetwork,cleanupFirewallNetworksrc/host-iptables-rules.ts:setupHostIptables,isValidPortSpec, host-access and proxy rule sectionssrc/host-iptables-cleanup.ts:cleanupHostIptablessrc/host-iptables-shared.ts: shared constants + IPv6/bridge helper state/functionssrc/host-iptables.tsnow re-exports the public API and types (HostAccessConfig,CliProxyHostConfig) and keeps__testing._resetIpv6Stateavailable.