mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-06 03:33:26 +00:00
simplify the if logic
This commit is contained in:
@@ -49,7 +49,7 @@ func NewSecurityContextDeny() *Plugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate will deny any pod that defines SELinuxOptions or RunAsUser.
|
// Validate will deny any pod that defines SupplementalGroups, SELinuxOptions, RunAsUser or FSGroup
|
||||||
func (p *Plugin) Validate(a admission.Attributes) (err error) {
|
func (p *Plugin) Validate(a admission.Attributes) (err error) {
|
||||||
if a.GetSubresource() != "" || a.GetResource().GroupResource() != api.Resource("pods") {
|
if a.GetSubresource() != "" || a.GetResource().GroupResource() != api.Resource("pods") {
|
||||||
return nil
|
return nil
|
||||||
@@ -60,20 +60,19 @@ func (p *Plugin) Validate(a admission.Attributes) (err error) {
|
|||||||
return apierrors.NewBadRequest("Resource was marked with kind Pod but was unable to be converted")
|
return apierrors.NewBadRequest("Resource was marked with kind Pod but was unable to be converted")
|
||||||
}
|
}
|
||||||
|
|
||||||
if pod.Spec.SecurityContext != nil && pod.Spec.SecurityContext.SupplementalGroups != nil {
|
|
||||||
return apierrors.NewForbidden(a.GetResource().GroupResource(), pod.Name, fmt.Errorf("SecurityContext.SupplementalGroups is forbidden"))
|
|
||||||
}
|
|
||||||
if pod.Spec.SecurityContext != nil {
|
if pod.Spec.SecurityContext != nil {
|
||||||
|
if pod.Spec.SecurityContext.SupplementalGroups != nil {
|
||||||
|
return apierrors.NewForbidden(a.GetResource().GroupResource(), pod.Name, fmt.Errorf("pod.Spec.SecurityContext.SupplementalGroups is forbidden"))
|
||||||
|
}
|
||||||
if pod.Spec.SecurityContext.SELinuxOptions != nil {
|
if pod.Spec.SecurityContext.SELinuxOptions != nil {
|
||||||
return apierrors.NewForbidden(a.GetResource().GroupResource(), pod.Name, fmt.Errorf("pod.Spec.SecurityContext.SELinuxOptions is forbidden"))
|
return apierrors.NewForbidden(a.GetResource().GroupResource(), pod.Name, fmt.Errorf("pod.Spec.SecurityContext.SELinuxOptions is forbidden"))
|
||||||
}
|
}
|
||||||
if pod.Spec.SecurityContext.RunAsUser != nil {
|
if pod.Spec.SecurityContext.RunAsUser != nil {
|
||||||
return apierrors.NewForbidden(a.GetResource().GroupResource(), pod.Name, fmt.Errorf("pod.Spec.SecurityContext.RunAsUser is forbidden"))
|
return apierrors.NewForbidden(a.GetResource().GroupResource(), pod.Name, fmt.Errorf("pod.Spec.SecurityContext.RunAsUser is forbidden"))
|
||||||
}
|
}
|
||||||
}
|
if pod.Spec.SecurityContext.FSGroup != nil {
|
||||||
|
return apierrors.NewForbidden(a.GetResource().GroupResource(), pod.Name, fmt.Errorf("pod.Spec.SecurityContext.FSGroup is forbidden"))
|
||||||
if pod.Spec.SecurityContext != nil && pod.Spec.SecurityContext.FSGroup != nil {
|
}
|
||||||
return apierrors.NewForbidden(a.GetResource().GroupResource(), pod.Name, fmt.Errorf("SecurityContext.FSGroup is forbidden"))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, v := range pod.Spec.InitContainers {
|
for _, v := range pod.Spec.InitContainers {
|
||||||
|
Reference in New Issue
Block a user