mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-10-07 11:04:44 +00:00
AllowPrivilegeEscalation: add validations for caps and privileged
Signed-off-by: Jess Frazelle <acidburn@microsoft.com>
This commit is contained in:
@@ -4704,6 +4704,38 @@ func TestValidatePodSpec(t *testing.T) {
|
||||
DNSPolicy: api.DNSClusterFirst,
|
||||
PriorityClassName: "InvalidName",
|
||||
},
|
||||
"with privileged and allowPrivilegeEscalation false": {
|
||||
Containers: []api.Container{
|
||||
{
|
||||
Name: "ctr",
|
||||
Image: "image",
|
||||
ImagePullPolicy: "IfNotPresent",
|
||||
Ports: []api.ContainerPort{
|
||||
{HostPort: 8080, ContainerPort: 2600, Protocol: "TCP"}},
|
||||
SecurityContext: &api.SecurityContext{
|
||||
Privileged: boolPtr(true),
|
||||
AllowPrivilegeEscalation: boolPtr(false),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"with CAP_SYS_ADMIN and allowPrivilegeEscalation false": {
|
||||
Containers: []api.Container{
|
||||
{
|
||||
Name: "ctr",
|
||||
Image: "image",
|
||||
ImagePullPolicy: "IfNotPresent",
|
||||
Ports: []api.ContainerPort{
|
||||
{HostPort: 8080, ContainerPort: 2600, Protocol: "TCP"}},
|
||||
SecurityContext: &api.SecurityContext{
|
||||
Capabilities: &api.Capabilities{
|
||||
Add: []api.Capability{"CAP_SYS_ADMIN"},
|
||||
},
|
||||
AllowPrivilegeEscalation: boolPtr(false),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
for k, v := range failureCases {
|
||||
if errs := ValidatePodSpec(&v, field.NewPath("field")); len(errs) == 0 {
|
||||
@@ -11082,3 +11114,7 @@ func TestValidateOrSetClientIPAffinityConfig(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func boolPtr(b bool) *bool {
|
||||
return &b
|
||||
}
|
||||
|
Reference in New Issue
Block a user