Skip to content

fix: reconcile egress drop rules to the desired set#5

Merged
CMGS merged 1 commit into
mainfrom
fix/egress-drop-reconcile
Jun 30, 2026
Merged

fix: reconcile egress drop rules to the desired set#5
CMGS merged 1 commit into
mainfrom
fix/egress-drop-reconcile

Conversation

@CMGS

@CMGS CMGS commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Problem

cocoon-net v0.1.6 added --drop-internal-access / --drop-cidr egress DROP rules, but setupIPTables only adds them. Changing the drop set (e.g. removing a --drop-cidr, or moving the subnet) or clearing it left the old cocoon-net-drop-tagged FORWARD rules in place until an explicit cocoon-net teardown — stale isolation rules that can over-block.

Change

  • setupIPTables now reconciles to the desired drop set on every run: insert the desired rules first (idempotent via iptInsert's Exists check), then reconcileDropRules prunes any tagged FORWARD drop rule whose -d destination is no longer wanted.
  • Insert-then-prune keeps the reconcile gapless — no window where VM-to-VM isolation is off on daemon restart. (The old code never removed on restart, so this preserves the no-gap property while adding convergence on config change.)
  • ClearDropRules is now a thin wrapper over reconcileDropRules(ctx, ipt, nil) (empty set ⇒ remove all) — one source of truth for the list/match/delete logic.
  • New pure helper ruleDest(fields) extracts the -d <cidr> from an iptables -S line, with a table-driven test.

Verification

  • make lint 0 issues (GOOS=linux + darwin); make test green.
  • TestRuleDest cross-compiled and run on a real linux host — all cases pass.

🤖 Generated with Claude Code

setupIPTables only added --drop-internal-access/--drop-cidr DROP rules, so
changing or clearing the drop config left stale rules in FORWARD until an
explicit teardown. Insert the desired rules first, then prune tagged FORWARD
drop rules whose destination is no longer wanted -- a gapless reconcile, no
isolation gap on daemon restart. ClearDropRules reuses the same prune with an
empty set.
@CMGS CMGS force-pushed the fix/egress-drop-reconcile branch from dda913c to eef6fcb Compare June 30, 2026 10:46
@CMGS CMGS merged commit 2a659f2 into main Jun 30, 2026
2 checks passed
@CMGS CMGS deleted the fix/egress-drop-reconcile branch June 30, 2026 10:59
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.

1 participant