mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 14:37:00 +00:00
Merge pull request #68803 from dims/avoid-setting-masked-read-only-when-pod-is-privilged
Avoid setting Masked/ReadOnly paths when pod is privileged
This commit is contained in:
commit
76518f154b
@ -137,8 +137,10 @@ func modifyHostConfig(sc *runtimeapi.LinuxContainerSecurityContext, hostConfig *
|
|||||||
hostConfig.SecurityOpt = append(hostConfig.SecurityOpt, "no-new-privileges")
|
hostConfig.SecurityOpt = append(hostConfig.SecurityOpt, "no-new-privileges")
|
||||||
}
|
}
|
||||||
|
|
||||||
hostConfig.MaskedPaths = sc.MaskedPaths
|
if !hostConfig.Privileged {
|
||||||
hostConfig.ReadonlyPaths = sc.ReadonlyPaths
|
hostConfig.MaskedPaths = sc.MaskedPaths
|
||||||
|
hostConfig.ReadonlyPaths = sc.ReadonlyPaths
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -110,11 +110,27 @@ func TestModifyContainerConfig(t *testing.T) {
|
|||||||
|
|
||||||
func TestModifyHostConfig(t *testing.T) {
|
func TestModifyHostConfig(t *testing.T) {
|
||||||
setNetworkHC := &dockercontainer.HostConfig{}
|
setNetworkHC := &dockercontainer.HostConfig{}
|
||||||
|
|
||||||
|
// When we have Privileged pods, we do not need to use the
|
||||||
|
// Masked / Readonly paths.
|
||||||
setPrivSC := &runtimeapi.LinuxContainerSecurityContext{}
|
setPrivSC := &runtimeapi.LinuxContainerSecurityContext{}
|
||||||
setPrivSC.Privileged = true
|
setPrivSC.Privileged = true
|
||||||
|
setPrivSC.MaskedPaths = []string{"/hello/world/masked"}
|
||||||
|
setPrivSC.ReadonlyPaths = []string{"/hello/world/readonly"}
|
||||||
setPrivHC := &dockercontainer.HostConfig{
|
setPrivHC := &dockercontainer.HostConfig{
|
||||||
Privileged: true,
|
Privileged: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsetPrivSC := &runtimeapi.LinuxContainerSecurityContext{}
|
||||||
|
unsetPrivSC.Privileged = false
|
||||||
|
unsetPrivSC.MaskedPaths = []string{"/hello/world/masked"}
|
||||||
|
unsetPrivSC.ReadonlyPaths = []string{"/hello/world/readonly"}
|
||||||
|
unsetPrivHC := &dockercontainer.HostConfig{
|
||||||
|
Privileged: false,
|
||||||
|
MaskedPaths: []string{"/hello/world/masked"},
|
||||||
|
ReadonlyPaths: []string{"/hello/world/readonly"},
|
||||||
|
}
|
||||||
|
|
||||||
setCapsHC := &dockercontainer.HostConfig{
|
setCapsHC := &dockercontainer.HostConfig{
|
||||||
CapAdd: []string{"addCapA", "addCapB"},
|
CapAdd: []string{"addCapA", "addCapB"},
|
||||||
CapDrop: []string{"dropCapA", "dropCapB"},
|
CapDrop: []string{"dropCapA", "dropCapB"},
|
||||||
@ -148,6 +164,11 @@ func TestModifyHostConfig(t *testing.T) {
|
|||||||
sc: setPrivSC,
|
sc: setPrivSC,
|
||||||
expected: setPrivHC,
|
expected: setPrivHC,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "container.SecurityContext.NoPrivileges",
|
||||||
|
sc: unsetPrivSC,
|
||||||
|
expected: unsetPrivHC,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "container.SecurityContext.Capabilities",
|
name: "container.SecurityContext.Capabilities",
|
||||||
sc: &runtimeapi.LinuxContainerSecurityContext{
|
sc: &runtimeapi.LinuxContainerSecurityContext{
|
||||||
|
Loading…
Reference in New Issue
Block a user