rancher / rancher

Complete container management platform
http://rancher.com
Apache License 2.0
23.2k stars 2.94k forks source link

[BUG] UI defaults to broken combination of privileged=true and allowPrivilegeEscalation=false #42893

Open kravciak opened 11 months ago

kravciak commented 11 months ago

Rancher Server Setup

Describe the bug

When I select privileged: true on pod securityContext then allowPrivilegeEscalation option hides in UI but is still present in YAML as false. This combination is not valid. When privileged: true then allowPrivilegeEscalation has to be also true.

To Reproduce

This combination is wrong as described in kubernetes doc:

"allowPrivilegeEscalation is always true when the container is run as privileged."

To see error message in UI install kubewarden 1.7.0 with recommended policies in monitor mode.

Result

Problem is obvious when I enable kubewarden, it prevents pod creation (in both monitor / protect modes) with following error:

Pod "rrr" is invalid: spec.containers[0].securityContext: Invalid value: core.SecurityContext{Capabilities:(*core.Capabilities)(0xc037249020), Privileged:(*bool)(0xc02dfb504c), SELinuxOptions:(*core.SELinuxOptions)(nil), WindowsOptions:(*core.WindowsSecurityContextOptions)(nil), RunAsUser:(*int64)(nil), RunAsGroup:(*int64)(nil), RunAsNonRoot:(*bool)(0xc02dfb504e), ReadOnlyRootFilesystem:(*bool)(0xc02dfb504d), AllowPrivilegeEscalation:(*bool)(0xc02dfb504b), ProcMount:(*core.ProcMountType)(nil), SeccompProfile:(*core.SeccompProfile)(nil)}: cannot set `allowPrivilegeEscalation` to false and `privileged` to true

After I switch back to privileged: No then Privilege Escalation is switched to Yes (both UI and YAML).

Expected Result

When I select Privileged: Yes then Privilege Escalation is:

Screenshots Screenshot from 2023-09-21 12-37-33

baptisterajaut commented 4 months ago

This is still prevalent in rancher 2.8.2. Just enabling priviledged as true is not enough and require manual yaml editing. Rancher v2.8.2 Dashboard v2.8.0 Helm v2.16.8-rancher2 Machine v0.15.0-rancher106 Cluster RKE2 : v1.27.12+rke2r1