mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Enhance the prompt information of verifyRunAsNonRoot, add pod, container information
This commit is contained in:
parent
66ea0f568c
commit
be1c85d915
@ -22,6 +22,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"k8s.io/api/core/v1"
|
"k8s.io/api/core/v1"
|
||||||
|
"k8s.io/kubernetes/pkg/kubelet/util/format"
|
||||||
"k8s.io/kubernetes/pkg/securitycontext"
|
"k8s.io/kubernetes/pkg/securitycontext"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -35,16 +36,16 @@ func verifyRunAsNonRoot(pod *v1.Pod, container *v1.Container, uid *int64, userna
|
|||||||
|
|
||||||
if effectiveSc.RunAsUser != nil {
|
if effectiveSc.RunAsUser != nil {
|
||||||
if *effectiveSc.RunAsUser == 0 {
|
if *effectiveSc.RunAsUser == 0 {
|
||||||
return fmt.Errorf("container's runAsUser breaks non-root policy")
|
return fmt.Errorf("container's runAsUser breaks non-root policy (pod: %q, container: %s)", format.Pod(pod), container.Name)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case uid != nil && *uid == 0:
|
case uid != nil && *uid == 0:
|
||||||
return fmt.Errorf("container has runAsNonRoot and image will run as root")
|
return fmt.Errorf("container has runAsNonRoot and image will run as root (pod: %q, container: %s)", format.Pod(pod), container.Name)
|
||||||
case uid == nil && len(username) > 0:
|
case uid == nil && len(username) > 0:
|
||||||
return fmt.Errorf("container has runAsNonRoot and image has non-numeric user (%s), cannot verify user is non-root", username)
|
return fmt.Errorf("container has runAsNonRoot and image has non-numeric user (%s), cannot verify user is non-root (pod: %q, container: %s)", username, format.Pod(pod), container.Name)
|
||||||
default:
|
default:
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"k8s.io/api/core/v1"
|
"k8s.io/api/core/v1"
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
|
"k8s.io/kubernetes/pkg/kubelet/util/format"
|
||||||
"k8s.io/kubernetes/pkg/securitycontext"
|
"k8s.io/kubernetes/pkg/securitycontext"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -42,24 +43,24 @@ func verifyRunAsNonRoot(pod *v1.Pod, container *v1.Container, uid *int64, userna
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if effectiveSc.RunAsUser != nil {
|
if effectiveSc.RunAsUser != nil {
|
||||||
klog.Warningf("Windows container does not support SecurityContext.RunAsUser, please use SecurityContext.WindowsOptions")
|
klog.Warningf("Windows container does not support SecurityContext.RunAsUser, please use SecurityContext.WindowsOptions (pod: %q, container: %s)", format.Pod(pod), container.Name)
|
||||||
}
|
}
|
||||||
if effectiveSc.SELinuxOptions != nil {
|
if effectiveSc.SELinuxOptions != nil {
|
||||||
klog.Warningf("Windows container does not support SecurityContext.SELinuxOptions, please use SecurityContext.WindowsOptions")
|
klog.Warningf("Windows container does not support SecurityContext.SELinuxOptions, please use SecurityContext.WindowsOptions (pod: %q, container: %s)", format.Pod(pod), container.Name)
|
||||||
}
|
}
|
||||||
if effectiveSc.RunAsGroup != nil {
|
if effectiveSc.RunAsGroup != nil {
|
||||||
klog.Warningf("Windows container does not support SecurityContext.RunAsGroup")
|
klog.Warningf("Windows container does not support SecurityContext.RunAsGroup (pod: %q, container: %s)", format.Pod(pod), container.Name)
|
||||||
}
|
}
|
||||||
if effectiveSc.WindowsOptions != nil {
|
if effectiveSc.WindowsOptions != nil {
|
||||||
if effectiveSc.WindowsOptions.RunAsUserName != nil {
|
if effectiveSc.WindowsOptions.RunAsUserName != nil {
|
||||||
if *effectiveSc.WindowsOptions.RunAsUserName == windowsRootUserName {
|
if *effectiveSc.WindowsOptions.RunAsUserName == windowsRootUserName {
|
||||||
return fmt.Errorf("container's runAsUser (%s) which will be regarded as root identity and will break non-root policy", username)
|
return fmt.Errorf("container's runAsUser (%s) which will be regarded as root identity and will break non-root policy (pod: %q, container: %s)", username, format.Pod(pod), container.Name)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(username) > 0 && username == windowsRootUserName {
|
if len(username) > 0 && username == windowsRootUserName {
|
||||||
return fmt.Errorf("container's runAsUser (%s) which will be regarded as root identity and will break non-root policy", username)
|
return fmt.Errorf("container's runAsUser (%s) which will be regarded as root identity and will break non-root policy (pod: %q, container: %s)", username, format.Pod(pod), container.Name)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user