mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Validation on RunAsGroup - Update DropDisabled[Alpha]Fields behaviour
This commit is contained in:
parent
13e59ab9ad
commit
d4c85e977f
@ -279,7 +279,7 @@ func DropDisabledFields(podSpec, oldPodSpec *api.PodSpec) {
|
||||
// dropDisabledRunAsGroupField removes disabled fields from PodSpec related
|
||||
// to RunAsGroup
|
||||
func dropDisabledRunAsGroupField(podSpec, oldPodSpec *api.PodSpec) {
|
||||
if !utilfeature.DefaultFeatureGate.Enabled(features.RunAsGroup) {
|
||||
if !utilfeature.DefaultFeatureGate.Enabled(features.RunAsGroup) && !runAsGroupInUse(oldPodSpec) {
|
||||
if podSpec.SecurityContext != nil {
|
||||
podSpec.SecurityContext.RunAsGroup = nil
|
||||
}
|
||||
@ -293,22 +293,6 @@ func dropDisabledRunAsGroupField(podSpec, oldPodSpec *api.PodSpec) {
|
||||
podSpec.InitContainers[i].SecurityContext.RunAsGroup = nil
|
||||
}
|
||||
}
|
||||
|
||||
if oldPodSpec != nil {
|
||||
if oldPodSpec.SecurityContext != nil {
|
||||
oldPodSpec.SecurityContext.RunAsGroup = nil
|
||||
}
|
||||
for i := range oldPodSpec.Containers {
|
||||
if oldPodSpec.Containers[i].SecurityContext != nil {
|
||||
oldPodSpec.Containers[i].SecurityContext.RunAsGroup = nil
|
||||
}
|
||||
}
|
||||
for i := range oldPodSpec.InitContainers {
|
||||
if oldPodSpec.InitContainers[i].SecurityContext != nil {
|
||||
oldPodSpec.InitContainers[i].SecurityContext.RunAsGroup = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -445,3 +429,25 @@ func volumeDevicesInUse(podSpec *api.PodSpec) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// runAsGroupInUse returns true if the pod spec is non-nil and has a SecurityContext's RunAsGroup field set
|
||||
func runAsGroupInUse(podSpec *api.PodSpec) bool {
|
||||
if podSpec == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
if podSpec.SecurityContext != nil && podSpec.SecurityContext.RunAsGroup != nil {
|
||||
return true
|
||||
}
|
||||
for i := range podSpec.Containers {
|
||||
if podSpec.Containers[i].SecurityContext != nil && podSpec.Containers[i].SecurityContext.RunAsGroup != nil {
|
||||
return true
|
||||
}
|
||||
}
|
||||
for i := range podSpec.InitContainers {
|
||||
if podSpec.InitContainers[i].SecurityContext != nil && podSpec.InitContainers[i].SecurityContext.RunAsGroup != nil {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
@ -28,11 +28,8 @@ func DropDisabledFields(pspSpec, oldPSPSpec *policy.PodSecurityPolicySpec) {
|
||||
if !utilfeature.DefaultFeatureGate.Enabled(features.ProcMountType) && !allowedProcMountTypesInUse(oldPSPSpec) {
|
||||
pspSpec.AllowedProcMountTypes = nil
|
||||
}
|
||||
if !utilfeature.DefaultFeatureGate.Enabled(features.RunAsGroup) {
|
||||
if !utilfeature.DefaultFeatureGate.Enabled(features.RunAsGroup) && (oldPSPSpec == nil || oldPSPSpec.RunAsGroup == nil) {
|
||||
pspSpec.RunAsGroup = nil
|
||||
if oldPSPSpec != nil {
|
||||
oldPSPSpec.RunAsGroup = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user