@@ -31,24 +31,6 @@ var defaultSCCs = sets.NewString(
31
31
"restricted-v2" ,
32
32
)
33
33
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
-
52
34
type requiredSCCAnnotationChecker struct {
53
35
kubeClient kubernetes.Interface
54
36
}
@@ -86,59 +68,20 @@ func (w *requiredSCCAnnotationChecker) CollectData(ctx context.Context, storageD
86
68
continue
87
69
}
88
70
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
-
94
71
pods , err := w .kubeClient .CoreV1 ().Pods (ns .Name ).List (ctx , metav1.ListOptions {})
95
72
if err != nil {
96
73
return nil , nil , err
97
74
}
98
75
99
76
failures := make ([]string , 0 )
100
77
for _ , pod := range pods .Items {
101
- validatedSCC := pod .Annotations [securityv1 .ValidatedSCCAnnotation ]
102
- allowedNamespaces , isNonStandard := nonStandardSCCNamespaces [validatedSCC ]
103
-
104
78
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
- }
110
79
continue
111
80
}
112
81
82
+ suggestedSCC := suggestSCC (& pod )
113
83
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 ))
142
85
}
143
86
144
87
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
148
91
}
149
92
150
93
failureMsg := strings .Join (failures , "\n " )
151
-
152
94
junits = append (junits ,
153
95
& junitapi.JUnitTestCase {
154
96
Name : testName ,
155
97
SystemOut : failureMsg ,
156
98
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
+ )
166
106
}
167
107
168
108
return nil , junits , nil
@@ -184,6 +124,20 @@ func (w *requiredSCCAnnotationChecker) Cleanup(ctx context.Context) error {
184
124
return nil
185
125
}
186
126
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
+
187
141
func ownerReferences (pod * v1.Pod ) string {
188
142
ownerRefs := make ([]string , len (pod .OwnerReferences ))
189
143
for i , or := range pod .OwnerReferences {
0 commit comments