-
Notifications
You must be signed in to change notification settings - Fork 667
feat: add support for com.docker.network.bridge.enable_icc network option #4311
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ import ( | |
"gotest.tools/v3/assert" | ||
|
||
"github.com/containerd/nerdctl/mod/tigron/expect" | ||
"github.com/containerd/nerdctl/mod/tigron/require" | ||
"github.com/containerd/nerdctl/mod/tigron/test" | ||
|
||
"github.com/containerd/nerdctl/v2/pkg/testutil" | ||
|
@@ -110,3 +111,100 @@ func TestNetworkCreate(t *testing.T) { | |
|
||
testCase.Run(t) | ||
} | ||
|
||
func TestNetworkCreateICC(t *testing.T) { | ||
testCase := nerdtest.Setup() | ||
|
||
testCase.Require = require.All( | ||
require.Linux, | ||
nerdtest.Rootful, | ||
) | ||
|
||
testCase.SubTests = []*test.Case{ | ||
{ | ||
Description: "with enable_icc=false", | ||
Require: nerdtest.CNIFirewallVersion("1.7.1"), | ||
NoParallel: true, | ||
Setup: func(data test.Data, helpers test.Helpers) { | ||
// Create a network with ICC disabled | ||
helpers.Ensure("network", "create", data.Identifier(), "--driver", "bridge", | ||
"--opt", "com.docker.network.bridge.enable_icc=false") | ||
|
||
// Run a container in that network | ||
data.Labels().Set("container1", helpers.Capture("run", "-d", "--net", data.Identifier(), | ||
"--name", data.Identifier("c1"), testutil.CommonImage, "sleep", "infinity")) | ||
|
||
// Wait for container to be running | ||
nerdtest.EnsureContainerStarted(helpers, data.Identifier("c1")) | ||
}, | ||
Cleanup: func(data test.Data, helpers test.Helpers) { | ||
helpers.Anyhow("container", "rm", "-f", data.Identifier("c1")) | ||
helpers.Anyhow("network", "rm", data.Identifier()) | ||
}, | ||
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { | ||
// DEBUG | ||
iptablesSave := "iptables-save | grep CNI-ISOLATION || true" | ||
helpers.Custom("sh", "-ec", iptablesSave).Run(&test.Expected{}) | ||
// Try to ping the other container in the same network | ||
// This should fail when ICC is disabled | ||
return helpers.Command("run", "--rm", "--net", data.Identifier(), | ||
testutil.CommonImage, "ping", "-c", "1", "-W", "1", data.Identifier("c1")) | ||
}, | ||
Expected: test.Expects(expect.ExitCodeGenericFail, nil, nil), // Expect ping to fail with exit code 1 | ||
}, | ||
{ | ||
Description: "with enable_icc=true", | ||
Require: nerdtest.CNIFirewallVersion("1.7.1"), | ||
NoParallel: true, | ||
Setup: func(data test.Data, helpers test.Helpers) { | ||
// Create a network with ICC enabled (default) | ||
helpers.Ensure("network", "create", data.Identifier(), "--driver", "bridge", | ||
"--opt", "com.docker.network.bridge.enable_icc=true") | ||
|
||
// Run a container in that network | ||
data.Labels().Set("container1", helpers.Capture("run", "-d", "--net", data.Identifier(), | ||
"--name", data.Identifier("c1"), testutil.CommonImage, "sleep", "infinity")) | ||
// Wait for container to be running | ||
nerdtest.EnsureContainerStarted(helpers, data.Identifier("c1")) | ||
}, | ||
Cleanup: func(data test.Data, helpers test.Helpers) { | ||
helpers.Anyhow("container", "rm", "-f", data.Identifier("c1")) | ||
helpers.Anyhow("network", "rm", data.Identifier()) | ||
}, | ||
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { | ||
// Try to ping the other container in the same network | ||
// This should succeed when ICC is enabled | ||
return helpers.Command("run", "--rm", "--net", data.Identifier(), | ||
testutil.CommonImage, "ping", "-c", "1", "-W", "1", data.Identifier("c1")) | ||
}, | ||
Expected: test.Expects(0, nil, nil), // Expect ping to succeed with exit code 0 | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add a third case where enable_icc is not specified, to verify the default behavior? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, will add |
||
{ | ||
Description: "with no enable_icc option set", | ||
NoParallel: true, | ||
Setup: func(data test.Data, helpers test.Helpers) { | ||
// Create a network with ICC enabled (default) | ||
helpers.Ensure("network", "create", data.Identifier(), "--driver", "bridge") | ||
|
||
// Run a container in that network | ||
data.Labels().Set("container1", helpers.Capture("run", "-d", "--net", data.Identifier(), | ||
"--name", data.Identifier("c1"), testutil.CommonImage, "sleep", "infinity")) | ||
// Wait for container to be running | ||
nerdtest.EnsureContainerStarted(helpers, data.Identifier("c1")) | ||
}, | ||
Cleanup: func(data test.Data, helpers test.Helpers) { | ||
helpers.Anyhow("container", "rm", "-f", data.Identifier("c1")) | ||
helpers.Anyhow("network", "rm", data.Identifier()) | ||
}, | ||
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand { | ||
// Try to ping the other container in the same network | ||
// This should succeed when no ICC is set | ||
return helpers.Command("run", "--rm", "--net", data.Identifier(), | ||
testutil.CommonImage, "ping", "-c", "1", "-W", "1", data.Identifier("c1")) | ||
}, | ||
Expected: test.Expects(0, nil, nil), // Expect ping to succeed with exit code 0 | ||
}, | ||
} | ||
|
||
testCase.Run(t) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,6 +99,7 @@ func (e *CNIEnv) generateCNIPlugins(driver string, name string, ipam map[string] | |
case "bridge": | ||
mtu := 0 | ||
iPMasq := true | ||
icc := true | ||
for opt, v := range opts { | ||
switch opt { | ||
case "mtu", "com.docker.network.driver.mtu": | ||
|
@@ -111,6 +112,11 @@ func (e *CNIEnv) generateCNIPlugins(driver string, name string, ipam map[string] | |
if err != nil { | ||
return nil, err | ||
} | ||
case "icc", "com.docker.network.bridge.enable_icc": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs documentation |
||
icc, err = strconv.ParseBool(v) | ||
if err != nil { | ||
return nil, err | ||
} | ||
default: | ||
return nil, fmt.Errorf("unsupported %q network option %q", driver, opt) | ||
} | ||
|
@@ -129,10 +135,25 @@ func (e *CNIEnv) generateCNIPlugins(driver string, name string, ipam map[string] | |
if ipv6 { | ||
bridge.Capabilities["ips"] = true | ||
} | ||
plugins = []CNIPlugin{bridge, newPortMapPlugin(), newFirewallPlugin(), newTuningPlugin()} | ||
|
||
// Determine the appropriate firewall ingress policy based on icc setting | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This only matter for non-default network, right? Maybe the entire section should be moved inside the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, currently network options are only applied to non default network, which makes sense since the default network is created by nerdctl. That being said, there isn't a hard rule that these network options can never be applied to the default network. Docker actually allows you to configure the default network with these options on daemon startup. I think we can keep this as is, and let the callers decide how they want to invoke this. |
||
ingressPolicy := "same-bridge" // Default policy | ||
firewallPath := filepath.Join(e.Path, "firewall") | ||
if !icc { | ||
// Check if firewall plugin supports the "isolated" policy (v1.7.1+) | ||
ok, err := FirewallPluginGEQVersion(firewallPath, "v1.7.1") | ||
if err != nil { | ||
log.L.WithError(err).Warnf("Failed to detect whether %q is newer than v1.7.1", firewallPath) | ||
} else if ok { | ||
ingressPolicy = "isolated" | ||
} else { | ||
log.L.Warnf("To use 'isolated' ingress policy, CNI plugin \"firewall\" (>= 1.7.1) needs to be installed in CNI_PATH (%q), see https://www.cni.dev/plugins/current/meta/firewall/", e.Path) | ||
} | ||
} | ||
|
||
plugins = []CNIPlugin{bridge, newPortMapPlugin(), newFirewallPlugin(ingressPolicy), newTuningPlugin()} | ||
if name != DefaultNetworkName { | ||
firewallPath := filepath.Join(e.Path, "firewall") | ||
ok, err := firewallPluginGEQ110(firewallPath) | ||
ok, err := FirewallPluginGEQVersion(firewallPath, "v1.1.0") | ||
if err != nil { | ||
log.L.WithError(err).Warnf("Failed to detect whether %q is newer than v1.1.0", firewallPath) | ||
} | ||
|
@@ -281,7 +302,8 @@ func (e *CNIEnv) parseIPAMRanges(subnets []string, gateway, ipRange string, ipv6 | |
return ranges, findIPv4, nil | ||
} | ||
|
||
func firewallPluginGEQ110(firewallPath string) (bool, error) { | ||
// FirewallPluginGEQVersion checks if the firewall plugin is greater than or equal to the specified version | ||
func FirewallPluginGEQVersion(firewallPath string, versionStr string) (bool, error) { | ||
// TODO: guess true by default in 2023 | ||
guessed := false | ||
|
||
|
@@ -310,8 +332,8 @@ func firewallPluginGEQ110(firewallPath string) (bool, error) { | |
if err != nil { | ||
return guessed, fmt.Errorf("failed to guess the version of %q: %w", firewallPath, err) | ||
} | ||
ver110 := semver.MustParse("v1.1.0") | ||
return ver.GreaterThan(ver110) || ver.Equal(ver110), nil | ||
targetVer := semver.MustParse(versionStr) | ||
return ver.GreaterThan(targetVer) || ver.Equal(targetVer), nil | ||
} | ||
|
||
// guessFirewallPluginVersion guess the version of the CNI firewall plugin (not the version of the implemented CNI spec). | ||
|
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.
Why?