fix: reconcile egress drop rules to the desired set#5
Merged
Conversation
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.
dda913c to
eef6fcb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
cocoon-netv0.1.6 added--drop-internal-access/--drop-cidregress DROP rules, butsetupIPTablesonly adds them. Changing the drop set (e.g. removing a--drop-cidr, or moving the subnet) or clearing it left the oldcocoon-net-drop-tagged FORWARD rules in place until an explicitcocoon-net teardown— stale isolation rules that can over-block.Change
setupIPTablesnow reconciles to the desired drop set on every run: insert the desired rules first (idempotent viaiptInsert'sExistscheck), thenreconcileDropRulesprunes any tagged FORWARD drop rule whose-ddestination is no longer wanted.ClearDropRulesis now a thin wrapper overreconcileDropRules(ctx, ipt, nil)(empty set ⇒ remove all) — one source of truth for the list/match/delete logic.ruleDest(fields)extracts the-d <cidr>from aniptables -Sline, with a table-driven test.Verification
make lint0 issues (GOOS=linux+darwin);make testgreen.TestRuleDestcross-compiled and run on a real linux host — all cases pass.🤖 Generated with Claude Code