Refactor iptables/ip6tables chain teardown into shared helper#3359
Conversation
There was a problem hiding this comment.
Pull request overview
Centralizes the duplicated iptables/ip6tables chain teardown (DOCKER-USER reference removal + reverse-order delete + flush + drop chain) into a single cleanupChain helper, and refactors the IPv4 cleanup, IPv6 cleanup, and setup pre-cleanup paths to use it.
Changes:
- Add
cleanupChaintohost-iptables-shared.tswith optional DOCKER-USER reference removal and a customizable match predicate. - Replace duplicated teardown code in
host-iptables-cleanup.ts(IPv4 with bridge-aware predicate, IPv6 with default matching) and inhost-iptables-rules.tssetup pre-cleanup. - Add
host-iptables-shared.test.tscovering reverse-order deletion and the skip-DOCKER-USER option.
Show a summary per file
| File | Description |
|---|---|
| src/host-iptables-shared.ts | New shared cleanupChain helper |
| src/host-iptables-cleanup.ts | IPv4/IPv6 cleanup paths now delegate to cleanupChain |
| src/host-iptables-rules.ts | Setup pre-cleanup uses cleanupChain |
| src/host-iptables-shared.test.ts | Unit tests for the new helper |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 4/4 changed files
- Comments generated: 0
Smoke Test Results✅ GitHub API - Confirmed 2 PR entries in recent-prs.json Overall: PASS
|
🔥 Smoke Test: Copilot BYOK (Offline) Mode
Running in BYOK offline mode ( PR by Overall: PARTIAL — BYOK inference and MCP connectivity confirmed ✅; pre-step smoke data was not expanded by the workflow runner.
|
🔬 Smoke Test Results
PR: "Refactor iptables/ip6tables chain teardown into shared helper" by Overall: PASS
|
Codex Smoke Test✅ chore: recompile all workflow lock files 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.
|
Smoke Test Results
Overall status: FAIL Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "localhost"See Network Configuration for more information.
|
🏗️ Build Test Suite Results
Overall: 8/8 ecosystems passed — ✅ PASS
|
Chroot Version Comparison Results
Result: ❌ Not all versions match. Python and Node.js versions differ between host and chroot environments.
|
Smoke Test Results
Overall: FAIL —
|
|
@copilot address review feedback |
I checked all review threads/comments on this PR and there aren’t any actionable review findings to apply (the reviewer reported 0 comments). If you have specific feedback you want addressed, please share the comment link or details and I’ll apply it. |
This PR addresses duplicated, security-sensitive chain teardown logic split across IPv4/IPv6 cleanup paths and setup pre-cleanup. The same list→match→delete (reverse order)→flush→delete sequence is now centralized to keep IPv4/IPv6 behavior in lockstep.
Shared teardown primitive
cleanupChaininsrc/host-iptables-shared.tsto encapsulate:-F/-Xchain teardownCleanup path deduplication
src/host-iptables-cleanup.tsto callcleanupChainfor:iptables,FW_WRAPPER) with bridge-aware match predicate (-i/-o <bridge>+ chain)ip6tables,FW_WRAPPER_V6) using default chain-name matchingSetup path deduplication
src/host-iptables-rules.tspre-setup cleanup to reusecleanupChain('iptables', CHAIN_NAME)when an existing chain is detected, removing the duplicated teardown block.Focused helper coverage
src/host-iptables-shared.test.tswith targeted coverage for: