Skip to content

Commit 8f7d502

Browse files
Merge pull request openshift#29321 from neisw/revert-29135-OCPBUGS-42435
NO-JIRA: Revert "Enforce the required-scc monitor test and validate usage of non-standard OCP SCCs
2 parents 19cf936 + 0536dfd commit 8f7d502

File tree

1 file changed

+23
-69
lines changed

1 file changed

+23
-69
lines changed

pkg/monitortests/authentication/requiredsccmonitortests/monitortest.go

Lines changed: 23 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,6 @@ var defaultSCCs = sets.NewString(
3131
"restricted-v2",
3232
)
3333

34-
var nonStandardSCCNamespaces = map[string]sets.Set[string]{
35-
"node-exporter": sets.New("openshift-monitoring"),
36-
"machine-api-termination-handler": sets.New("openshift-machine-api"),
37-
}
38-
39-
var namespacesWithPendingSCCPinning = sets.NewString(
40-
"openshift-cluster-csi-drivers",
41-
"openshift-cluster-version",
42-
"openshift-image-registry",
43-
"openshift-ingress",
44-
"openshift-ingress-canary",
45-
"openshift-ingress-operator",
46-
"openshift-insights",
47-
"openshift-machine-api",
48-
"openshift-marketplace",
49-
"openshift-monitoring",
50-
)
51-
5234
type requiredSCCAnnotationChecker struct {
5335
kubeClient kubernetes.Interface
5436
}
@@ -86,59 +68,20 @@ func (w *requiredSCCAnnotationChecker) CollectData(ctx context.Context, storageD
8668
continue
8769
}
8870

89-
// check if the namespace should be treated as flaking when failed
90-
flakeWhenFailed := ns.Labels["openshift.io/run-level"] == "0" ||
91-
ns.Labels["openshift.io/run-level"] == "1" ||
92-
namespacesWithPendingSCCPinning.Has(ns.Name)
93-
9471
pods, err := w.kubeClient.CoreV1().Pods(ns.Name).List(ctx, metav1.ListOptions{})
9572
if err != nil {
9673
return nil, nil, err
9774
}
9875

9976
failures := make([]string, 0)
10077
for _, pod := range pods.Items {
101-
validatedSCC := pod.Annotations[securityv1.ValidatedSCCAnnotation]
102-
allowedNamespaces, isNonStandard := nonStandardSCCNamespaces[validatedSCC]
103-
10478
if _, exists := pod.Annotations[securityv1.RequiredSCCAnnotation]; exists {
105-
if isNonStandard && !allowedNamespaces.Has(ns.Name) {
106-
failures = append(failures, fmt.Sprintf(
107-
"pod '%s' has a non-standard SCC '%s' not allowed in namespace '%s'; allowed namespaces are: %s",
108-
pod.Name, validatedSCC, ns.Name, strings.Join(allowedNamespaces.UnsortedList(), ", ")))
109-
}
11079
continue
11180
}
11281

82+
suggestedSCC := suggestSCC(&pod)
11383
owners := ownerReferences(&pod)
114-
115-
switch {
116-
case len(validatedSCC) == 0:
117-
failures = append(failures, fmt.Sprintf(
118-
"annotation missing from pod '%s'%s; cannot suggest required-scc, no validated SCC on pod",
119-
pod.Name, owners))
120-
121-
case defaultSCCs.Has(validatedSCC):
122-
failures = append(failures, fmt.Sprintf(
123-
"annotation missing from pod '%s'%s; suggested required-scc: '%s'",
124-
pod.Name, owners, validatedSCC))
125-
126-
case isNonStandard:
127-
if allowedNamespaces.Has(ns.Name) {
128-
failures = append(failures, fmt.Sprintf(
129-
"annotation missing from pod '%s'%s; suggested required-scc: '%s', this is a non-standard SCC",
130-
pod.Name, owners, validatedSCC))
131-
} else {
132-
failures = append(failures, fmt.Sprintf(
133-
"annotation missing from pod '%s'%s; pod is using non-standard SCC '%s' not allowed in namespace '%s'; allowed namespaces are: %s",
134-
pod.Name, owners, validatedSCC, ns.Name, strings.Join(allowedNamespaces.UnsortedList(), ", ")))
135-
}
136-
137-
default:
138-
failures = append(failures, fmt.Sprintf(
139-
"annotation missing from pod '%s'%s; cannot suggest required-scc, validated SCC '%s' is a custom SCC",
140-
pod.Name, owners, validatedSCC))
141-
}
84+
failures = append(failures, fmt.Sprintf("annotation missing from pod '%s'%s; %s", pod.Name, owners, suggestedSCC))
14285
}
14386

14487
testName := fmt.Sprintf("[sig-auth] all workloads in ns/%s must set the '%s' annotation", ns.Name, securityv1.RequiredSCCAnnotation)
@@ -148,21 +91,18 @@ func (w *requiredSCCAnnotationChecker) CollectData(ctx context.Context, storageD
14891
}
14992

15093
failureMsg := strings.Join(failures, "\n")
151-
15294
junits = append(junits,
15395
&junitapi.JUnitTestCase{
15496
Name: testName,
15597
SystemOut: failureMsg,
15698
FailureOutput: &junitapi.FailureOutput{Output: failureMsg},
157-
})
158-
159-
// add a successful test with the same name to cause a flake
160-
if flakeWhenFailed {
161-
junits = append(junits,
162-
&junitapi.JUnitTestCase{
163-
Name: testName,
164-
})
165-
}
99+
},
100+
101+
// add a successful test with the same name to cause a flake
102+
&junitapi.JUnitTestCase{
103+
Name: testName,
104+
},
105+
)
166106
}
167107

168108
return nil, junits, nil
@@ -184,6 +124,20 @@ func (w *requiredSCCAnnotationChecker) Cleanup(ctx context.Context) error {
184124
return nil
185125
}
186126

127+
// suggestSCC suggests the assigned SCC only if it belongs to the default set of SCCs
128+
// pods in runlevel 0/1 namespaces won't have any assigned SCC as SCC admission is disabled
129+
func suggestSCC(pod *v1.Pod) string {
130+
if len(pod.Annotations[securityv1.ValidatedSCCAnnotation]) == 0 {
131+
return "cannot suggest required-scc, no validated SCC on pod"
132+
}
133+
134+
if defaultSCCs.Has(pod.Annotations[securityv1.ValidatedSCCAnnotation]) {
135+
return fmt.Sprintf("suggested required-scc: '%s'", pod.Annotations[securityv1.ValidatedSCCAnnotation])
136+
}
137+
138+
return "cannot suggest required-scc, validated SCC is custom"
139+
}
140+
187141
func ownerReferences(pod *v1.Pod) string {
188142
ownerRefs := make([]string, len(pod.OwnerReferences))
189143
for i, or := range pod.OwnerReferences {

0 commit comments

Comments
 (0)