99 "k8s.io/klog"
1010
1111 apiequality "k8s.io/apimachinery/pkg/api/equality"
12+ "k8s.io/apimachinery/pkg/labels"
1213 "k8s.io/apimachinery/pkg/util/validation/field"
1314 "k8s.io/apiserver/pkg/admission"
1415 "k8s.io/apiserver/pkg/admission/initializer"
@@ -133,6 +134,16 @@ func (c *constraint) computeSecurityContext(a admission.Attributes, pod *coreapi
133134 if err != nil {
134135 return nil , "" , nil , admission .NewForbidden (a , err )
135136 }
137+ if len (constraints ) == 0 {
138+ sccs , err := c .sccLister .List (labels .Everything ())
139+ if err != nil {
140+ return nil , "" , nil , admission .NewForbidden (a , err )
141+ }
142+ if len (sccs ) == 0 {
143+ return nil , "" , nil , admission .NewForbidden (a , fmt .Errorf ("no SecurityContextConstraints found in cluster" ))
144+ }
145+ return nil , "" , nil , admission .NewForbidden (a , fmt .Errorf ("no SecurityContextConstraints found in namespace %s" , a .GetNamespace ()))
146+ }
136147
137148 // If mutation is not allowed and validatedSCCHint is provided, check the validated policy first.
138149 // Keep the other the same for everything else
@@ -152,7 +163,7 @@ func (c *constraint) computeSecurityContext(a admission.Attributes, pod *coreapi
152163 logProviders (pod , providers , errs )
153164
154165 if len (providers ) == 0 {
155- return nil , "" , nil , admission .NewForbidden (a , fmt .Errorf ("no providers available to validate pod request" ))
166+ return nil , "" , nil , admission .NewForbidden (a , fmt .Errorf ("no SecurityContextConstraintsProvider available to validate pod request" ))
156167 }
157168
158169 // all containers in a single pod must validate under a single provider or we will reject the request
0 commit comments