-
Notifications
You must be signed in to change notification settings - Fork 37
feat(cni-plugin): add iptables binary fallback logic #587
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a92ec96
add iptables binary fallback logic
adleong eba2d97
Add log rotation
adleong 13138e5
update detection logic
adleong a85e19d
lints
adleong 451c21f
Revert "lints"
adleong 7205a44
Revert "update detection logic"
adleong 5c06f70
add test
adleong 7a3d187
Merge remote-tracking branch 'origin/main' into alex/detect-iptables
raykroeker 60e9515
feat(cni-plugin): ignore dir mode lint+ print err
raykroeker a603208
feat(cni-plugin): 'plain' ip-tables mode test
raykroeker 93db412
lumberjack dependency should be direct
alpeb 0a1c69f
Merge remote-tracking branch 'origin/main' into alex/detect-iptables
raykroeker 3b7582c
feat(cni-plugin): drop logging to file.
raykroeker a030d19
feat(cni-plugin): fix go-comment.
raykroeker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| package iptables | ||
|
|
||
| import ( | ||
| "errors" | ||
| "testing" | ||
| ) | ||
|
|
||
| // fakeLookPath returns a LookPath-like function backed by a set of available names. | ||
| func fakeLookPath(available []string) func(string) (string, error) { | ||
| return func(name string) (string, error) { | ||
| for _, a := range available { | ||
| if a == name { | ||
| return "/fake/" + name, nil | ||
| } | ||
| } | ||
| return "", errors.New("not found") | ||
| } | ||
| } | ||
|
|
||
| func TestResolveBinFallback_KeepWhenPresent(t *testing.T) { | ||
| fc := &FirewallConfiguration{BinPath: "iptables-nft", SaveBinPath: "iptables-nft-save"} | ||
| lp := fakeLookPath([]string{ | ||
| "iptables-nft", | ||
| "iptables-nft-save", | ||
| }) | ||
|
|
||
| resolveBinFallback(fc, lp) | ||
|
|
||
| if fc.BinPath != "iptables-nft" || fc.SaveBinPath != "iptables-nft-save" { | ||
| t.Fatalf("expected to keep configured binaries, got bin=%q save=%q", fc.BinPath, fc.SaveBinPath) | ||
| } | ||
| } | ||
|
|
||
| func TestResolveBinFallback_FallbackToNFT_IPv4(t *testing.T) { | ||
| fc := &FirewallConfiguration{BinPath: "iptables-notreal", SaveBinPath: "iptables-notreal-save"} | ||
| lp := fakeLookPath([]string{ | ||
| // Only nft pair is available | ||
| "iptables-nft", | ||
| "iptables-nft-save", | ||
| }) | ||
|
|
||
| resolveBinFallback(fc, lp) | ||
|
|
||
| if fc.BinPath != "iptables-nft" || fc.SaveBinPath != "iptables-nft-save" { | ||
| t.Fatalf("expected fallback to iptables-nft, got bin=%q save=%q", fc.BinPath, fc.SaveBinPath) | ||
| } | ||
| } | ||
|
|
||
| func TestResolveBinFallback_FallbackOrder_Plain(t *testing.T) { | ||
| fc := &FirewallConfiguration{BinPath: "iptables-missing", SaveBinPath: "iptables-missing-save"} | ||
| lp := fakeLookPath([]string{ | ||
| // Only plain iptables present | ||
| "iptables", | ||
| "iptables-save", | ||
| }) | ||
|
|
||
| resolveBinFallback(fc, lp) | ||
|
|
||
| if fc.BinPath != "iptables" || fc.SaveBinPath != "iptables-save" { | ||
| t.Fatalf("expected fallback to iptables/iptable-save, got bin=%q save=%q", fc.BinPath, fc.SaveBinPath) | ||
| } | ||
| } | ||
|
|
||
| func TestResolveBinFallback_IPv6_FallbackLegacy(t *testing.T) { | ||
| fc := &FirewallConfiguration{BinPath: "ip6tables-missing", SaveBinPath: "ip6tables-missing-save"} | ||
| lp := fakeLookPath([]string{ | ||
| // Only legacy pair present for IPv6 | ||
| "ip6tables-legacy", | ||
| "ip6tables-legacy-save", | ||
| }) | ||
|
|
||
| resolveBinFallback(fc, lp) | ||
|
|
||
| if fc.BinPath != "ip6tables-legacy" || fc.SaveBinPath != "ip6tables-legacy-save" { | ||
| t.Fatalf("expected fallback to ip6tables-legacy, got bin=%q save=%q", fc.BinPath, fc.SaveBinPath) | ||
| } | ||
| } | ||
|
|
||
| func TestResolveBinFallback_NoCandidates(t *testing.T) { | ||
| origBin, origSave := "iptables-missing", "iptables-missing-save" | ||
| fc := &FirewallConfiguration{BinPath: origBin, SaveBinPath: origSave} | ||
| lp := fakeLookPath([]string{}) | ||
|
|
||
| resolveBinFallback(fc, lp) | ||
|
|
||
| if fc.BinPath != origBin || fc.SaveBinPath != origSave { | ||
| t.Fatalf("expected no change when no candidates found, got bin=%q save=%q", fc.BinPath, fc.SaveBinPath) | ||
| } | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a
getCommandsfunction incmd/root.gowhere the binaries to use is determined. I think that's a better place to place this logic, where we the ipv6 case is also considered without resorting to string comparison.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alpeb My only concern with moving this to the
cmd/package is that it in effect limits the implementation to the proxy-init command only. If we leave it iniptables/all calls toConfigure|Cleanupwill benefit from the resolution. Thoughts?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes you're right, I missed the initialization is a bit different for cni vs proxy-init. Should be good as-is then 👍