Skip to content

Commit

Permalink
pkg/securitycontextconstraints/sccadmission: simplify retrieving SCCs
Browse files Browse the repository at this point in the history
  • Loading branch information
s-urbaniak committed May 8, 2023
1 parent d9b2bf6 commit 806f568
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions pkg/securitycontextconstraints/sccadmission/admission.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,20 +206,14 @@ func (c *constraint) computeSecurityContext(ctx context.Context, a admission.Att
return nil, "", nil, admission.NewForbidden(a, fmt.Errorf("securitycontextconstraints.security.openshift.io required check failed oddly"))
}

constraints, err := sccmatching.NewDefaultSCCMatcher(c.sccLister, nil).FindApplicableSCCs(ctx, a.GetNamespace())
constraints, err := c.sccLister.List(labels.Everything())
if err != nil {
return nil, "", nil, admission.NewForbidden(a, err)
}
if len(constraints) == 0 {
sccs, err := c.sccLister.List(labels.Everything())
if err != nil {
return nil, "", nil, admission.NewForbidden(a, err)
}
if len(sccs) == 0 {
return nil, "", nil, admission.NewForbidden(a, fmt.Errorf("no SecurityContextConstraints found in cluster"))
}
return nil, "", nil, admission.NewForbidden(a, fmt.Errorf("no SecurityContextConstraints found in namespace %s", a.GetNamespace()))
return nil, "", nil, admission.NewForbidden(a, fmt.Errorf("no SecurityContextConstraints found in cluster"))
}
sort.Sort(sccsort.ByPriority(constraints))

// If mutation is not allowed and validatedSCCHint is provided, check the validated policy first.
// Keep the order the same for everything else
Expand Down

0 comments on commit 806f568

Please sign in to comment.