Merge pull request #8779 from kinvolk/rata/userns-fixes
Fix net.ipv4.ping_group_range with userns
This commit is contained in:
commit
3c250cb508
@ -146,6 +146,9 @@ func (c *Controller) sandboxContainerSpec(id string, config *runtime.PodSandboxC
|
||||
if c.config.EnableUnprivilegedPorts && !ipUnprivilegedPortStart {
|
||||
sysctls["net.ipv4.ip_unprivileged_port_start"] = "0"
|
||||
}
|
||||
// TODO (rata): We need to set this only if the pod will
|
||||
// **not** use user namespaces either.
|
||||
// This will be done when user namespaces is ported to sbserver.
|
||||
if c.config.EnableUnprivilegedICMP && !pingGroupRange && !userns.RunningInUserNS() {
|
||||
sysctls["net.ipv4.ping_group_range"] = "0 2147483647"
|
||||
}
|
||||
|
@ -95,6 +95,7 @@ func (c *criService) sandboxContainerSpec(id string, config *runtime.PodSandboxC
|
||||
|
||||
usernsOpts := nsOptions.GetUsernsOptions()
|
||||
uids, gids, err := parseUsernsIDs(usernsOpts)
|
||||
var usernsEnabled bool
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("user namespace configuration: %w", err)
|
||||
}
|
||||
@ -105,6 +106,7 @@ func (c *criService) sandboxContainerSpec(id string, config *runtime.PodSandboxC
|
||||
specOpts = append(specOpts, customopts.WithoutNamespace(runtimespec.UserNamespace))
|
||||
case runtime.NamespaceMode_POD:
|
||||
specOpts = append(specOpts, oci.WithUserNamespace(uids, gids))
|
||||
usernsEnabled = true
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported user namespace mode: %q", mode)
|
||||
}
|
||||
@ -164,7 +166,7 @@ func (c *criService) sandboxContainerSpec(id string, config *runtime.PodSandboxC
|
||||
if c.config.EnableUnprivilegedPorts && !ipUnprivilegedPortStart {
|
||||
sysctls["net.ipv4.ip_unprivileged_port_start"] = "0"
|
||||
}
|
||||
if c.config.EnableUnprivilegedICMP && !pingGroupRange && !userns.RunningInUserNS() {
|
||||
if c.config.EnableUnprivilegedICMP && !pingGroupRange && !userns.RunningInUserNS() && !usernsEnabled {
|
||||
sysctls["net.ipv4.ping_group_range"] = "0 2147483647"
|
||||
}
|
||||
}
|
||||
|
@ -148,6 +148,27 @@ func TestLinuxSandboxContainerSpec(t *testing.T) {
|
||||
})
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "spec shouldn't have ping_group_range if userns are in use",
|
||||
configChange: func(c *runtime.PodSandboxConfig) {
|
||||
c.Linux.SecurityContext = &runtime.LinuxSandboxSecurityContext{
|
||||
NamespaceOptions: &runtime.NamespaceOption{
|
||||
UsernsOptions: &runtime.UserNamespace{
|
||||
Mode: runtime.NamespaceMode_POD,
|
||||
Uids: []*runtime.IDMapping{&idMap},
|
||||
Gids: []*runtime.IDMapping{&idMap},
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
specCheck: func(t *testing.T, spec *runtimespec.Spec) {
|
||||
require.NotNil(t, spec.Linux)
|
||||
assert.Contains(t, spec.Linux.Namespaces, runtimespec.LinuxNamespace{
|
||||
Type: runtimespec.UserNamespace,
|
||||
})
|
||||
assert.NotContains(t, spec.Linux.Sysctl["net.ipv4.ping_group_range"], "0 2147483647")
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "host namespace",
|
||||
configChange: func(c *runtime.PodSandboxConfig) {
|
||||
|
Loading…
Reference in New Issue
Block a user