Skip to content

Refactor iptables/ip6tables chain teardown into shared helper#3359

Merged
lpcox merged 2 commits into
mainfrom
copilot/fix-duplicate-code-iptables
May 18, 2026
Merged

Refactor iptables/ip6tables chain teardown into shared helper#3359
lpcox merged 2 commits into
mainfrom
copilot/fix-duplicate-code-iptables

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 18, 2026

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

    • Added cleanupChain in src/host-iptables-shared.ts to encapsulate:
      • optional DOCKER-USER reference removal
      • rule matching via default chain-name match or custom predicate
      • reverse-order deletion of DOCKER-USER rule numbers
      • final -F / -X chain teardown
  • Cleanup path deduplication

    • Updated src/host-iptables-cleanup.ts to call cleanupChain for:
      • IPv4 (iptables, FW_WRAPPER) with bridge-aware match predicate (-i/-o <bridge> + chain)
      • IPv6 (ip6tables, FW_WRAPPER_V6) using default chain-name matching
    • Preserved conditional behavior when bridge name is unavailable.
  • Setup path deduplication

    • Updated src/host-iptables-rules.ts pre-setup cleanup to reuse cleanupChain('iptables', CHAIN_NAME) when an existing chain is detected, removing the duplicated teardown block.
  • Focused helper coverage

    • Added src/host-iptables-shared.test.ts with targeted coverage for:
      • reverse-order DOCKER-USER deletion
      • optional skip of DOCKER-USER reference removal
await cleanupChain('iptables', CHAIN_NAME, {
  removeDockerUserReferences: Boolean(bridgeName),
  matchPredicate: bridgeName
    ? (line) =>
        (line.includes(`-i ${bridgeName}`) || line.includes(`-o ${bridgeName}`)) &&
        line.includes(CHAIN_NAME)
    : undefined,
});

Copilot AI changed the title [WIP] Fix duplicate code in iptables chain management Refactor iptables/ip6tables chain teardown into shared helper May 18, 2026
Copilot AI requested a review from lpcox May 18, 2026 22:31
Copilot finished work on behalf of lpcox May 18, 2026 22:31
@lpcox lpcox marked this pull request as ready for review May 18, 2026 22:48
Copilot AI review requested due to automatic review settings May 18, 2026 22:48
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 cleanupChain to host-iptables-shared.ts with 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 in host-iptables-rules.ts setup pre-cleanup.
  • Add host-iptables-shared.test.ts covering 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

@github-actions
Copy link
Copy Markdown
Contributor

Smoke Test Results

GitHub API - Confirmed 2 PR entries in recent-prs.json
Playwright - GitHub.com page title contains "GitHub"
File verify - smoke-test-claude-26064180274.txt exists

Overall: PASS

💥 [THE END] — Illustrated by Smoke Claude

@github-actions
Copy link
Copy Markdown
Contributor

🔥 Smoke Test: Copilot BYOK (Offline) Mode

Test Result
GitHub MCP connectivity (list PRs)
GitHub.com HTTP connectivity ⚠️ pre-step data unavailable (template not expanded)
File write/read ⚠️ pre-step data unavailable (template not expanded)
BYOK inference (agent → api-proxy → api.githubcopilot.com)

Running in BYOK offline mode (COPILOT_OFFLINE=true) via api-proxy → api.githubcopilot.com.

PR by @Copilot, assignees: @lpcox @Copilot.

Overall: PARTIAL — BYOK inference and MCP connectivity confirmed ✅; pre-step smoke data was not expanded by the workflow runner.

🔑 BYOK report filed by Smoke Copilot BYOK

@github-actions
Copy link
Copy Markdown
Contributor

🔬 Smoke Test Results

Test Status
GitHub MCP connectivity
GitHub.com HTTP connectivity
File write/read

PR: "Refactor iptables/ip6tables chain teardown into shared helper" by @Copilot
Assignees: @lpcox, @Copilot

Overall: PASS

📰 BREAKING: Report filed by Smoke Copilot

@github-actions
Copy link
Copy Markdown
Contributor

Codex Smoke Test

✅ chore: recompile all workflow lock files
✅ refactor: split token-tracker.js into four focused modules
❌ safeinputs-gh unavailable; ❌ Tavily search unavailable; ⏭️ discussion skipped
✅ Playwright title; ✅ file/bash; ✅ npm build
Overall status: FAIL

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • registry.npmjs.org

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "registry.npmjs.org"

See Network Configuration for more information.

🔮 The oracle has spoken through Smoke Codex

@github-actions
Copy link
Copy Markdown
Contributor

Smoke Test Results

  • GitHub MCP Testing: ❌ (Tools missing)
  • GitHub.com Connectivity: ❌ (Status 000)
  • File Writing Testing: ✅
  • Bash Tool Testing: ✅

Overall status: FAIL

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • localhost

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "localhost"

See Network Configuration for more information.

💎 Faceted by Smoke Gemini

@github-actions
Copy link
Copy Markdown
Contributor

🏗️ Build Test Suite Results

Ecosystem Project Build/Install Tests Status
Bun elysia 1/1 passed ✅ PASS
Bun hono 1/1 passed ✅ PASS
C++ fmt N/A ✅ PASS
C++ json N/A ✅ PASS
Deno oak N/A 1/1 passed ✅ PASS
Deno std N/A 1/1 passed ✅ PASS
.NET hello-world N/A ✅ PASS
.NET json-parse N/A ✅ PASS
Go color 1/1 passed ✅ PASS
Go env 1/1 passed ✅ PASS
Go uuid 1/1 passed ✅ PASS
Java gson 1/1 passed ✅ PASS
Java caffeine 1/1 passed ✅ PASS
Node.js clsx passed ✅ PASS
Node.js execa passed ✅ PASS
Node.js p-limit passed ✅ PASS
Rust fd 1/1 passed ✅ PASS
Rust zoxide 1/1 passed ✅ PASS

Overall: 8/8 ecosystems passed — ✅ PASS

Generated by Build Test Suite for issue #3359 · ● 8.1M ·

@github-actions
Copy link
Copy Markdown
Contributor

Chroot Version Comparison Results

Runtime Host Version Chroot Version Match?
Python Python 3.12.13 Python 3.12.3
Node.js v24.15.0 v20.20.2
Go go1.22.12 go1.22.12

Result: ❌ Not all versions match. Python and Node.js versions differ between host and chroot environments.

Tested by Smoke Chroot

@github-actions
Copy link
Copy Markdown
Contributor

Smoke Test Results

  • Redis PING: ❌ (connection timed out)
  • PostgreSQL pg_isready: ❌ (no response)
  • PostgreSQL SELECT 1: ❌ (skipped — host unreachable)

Overall: FAILhost.docker.internal services are not reachable from this runner.

🔌 Service connectivity validated by Smoke Services

@lpcox
Copy link
Copy Markdown
Collaborator

lpcox commented May 18, 2026

@copilot address review feedback

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 18, 2026

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

Copilot finished work on behalf of lpcox May 18, 2026 22:56
@lpcox lpcox merged commit 8e70100 into main May 18, 2026
66 of 73 checks passed
@lpcox lpcox deleted the copilot/fix-duplicate-code-iptables branch May 18, 2026 23:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Duplicate Code] IPv4/IPv6 parallel iptables chain management duplicated in host-iptables-cleanup.ts and host-iptables-rules.ts

3 participants