mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2025-11-01 02:38:12 +00:00
Add SELinuxChangePolicy validation
This commit is contained in:
@@ -393,6 +393,8 @@ func GetValidationOptionsFromPodSpecAndMeta(podSpec, oldPodSpec *api.PodSpec, po
|
||||
opts.AllowRelaxedEnvironmentVariableValidation = useRelaxedEnvironmentVariableValidation(podSpec, oldPodSpec)
|
||||
opts.AllowRelaxedDNSSearchValidation = useRelaxedDNSSearchValidation(oldPodSpec)
|
||||
|
||||
opts.AllowOnlyRecursiveSELinuxChangePolicy = useOnlyRecursiveSELinuxChangePolicy(oldPodSpec)
|
||||
|
||||
if oldPodSpec != nil {
|
||||
// if old spec has status.hostIPs downwardAPI set, we must allow it
|
||||
opts.AllowHostIPsField = opts.AllowHostIPsField || hasUsedDownwardAPIFieldPathWithPodSpec(oldPodSpec, "status.hostIPs")
|
||||
@@ -723,6 +725,7 @@ func dropDisabledFields(
|
||||
|
||||
dropPodLifecycleSleepAction(podSpec, oldPodSpec)
|
||||
dropImageVolumes(podSpec, oldPodSpec)
|
||||
dropSELinuxChangePolicy(podSpec, oldPodSpec)
|
||||
}
|
||||
|
||||
func dropPodLifecycleSleepAction(podSpec, oldPodSpec *api.PodSpec) {
|
||||
@@ -1361,3 +1364,34 @@ func imageVolumesInUse(podSpec *api.PodSpec) bool {
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func dropSELinuxChangePolicy(podSpec, oldPodSpec *api.PodSpec) {
|
||||
if utilfeature.DefaultFeatureGate.Enabled(features.SELinuxChangePolicy) || seLinuxChangePolicyInUse(oldPodSpec) {
|
||||
return
|
||||
}
|
||||
if podSpec == nil || podSpec.SecurityContext == nil {
|
||||
return
|
||||
}
|
||||
podSpec.SecurityContext.SELinuxChangePolicy = nil
|
||||
}
|
||||
|
||||
func seLinuxChangePolicyInUse(podSpec *api.PodSpec) bool {
|
||||
if podSpec == nil || podSpec.SecurityContext == nil {
|
||||
return false
|
||||
}
|
||||
return podSpec.SecurityContext.SELinuxChangePolicy != nil
|
||||
}
|
||||
|
||||
func useOnlyRecursiveSELinuxChangePolicy(oldPodSpec *api.PodSpec) bool {
|
||||
if utilfeature.DefaultFeatureGate.Enabled(features.SELinuxMount) {
|
||||
// All policies are allowed
|
||||
return false
|
||||
}
|
||||
|
||||
if seLinuxChangePolicyInUse(oldPodSpec) {
|
||||
// The old pod spec has *any* policy: we need to keep that object update-able.
|
||||
return false
|
||||
}
|
||||
// No feature gate + no value in the old object -> only Recursive is allowed
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user