@@ -258,8 +258,8 @@ func (a *analyzer) initialize() error {
258
258
return nil
259
259
}
260
260
261
- func (a * analyzer ) shouldExclude (subject map [string ]interface {}, exclusions []* exclusion ) (bool , error ) {
262
- for _ , exclusion := range exclusions {
261
+ func (a * analyzer ) shouldExclude (subject map [string ]interface {}, exclusions []* exclusion ) (bool , int , error ) {
262
+ for i , exclusion := range exclusions {
263
263
if exclusion .exclusion .Disabled {
264
264
klog .V (7 ).Infof ("Exclusion '%v' is disabled - skipping" , exclusion .exclusion .Comment )
265
265
continue
@@ -275,20 +275,20 @@ func (a *analyzer) shouldExclude(subject map[string]interface{}, exclusions []*e
275
275
})
276
276
277
277
if err != nil {
278
- return false , err
278
+ return false , i , err
279
279
}
280
280
281
281
exclude , ok := recommendationOutput .Value ().(bool )
282
282
if ! ok {
283
- return false , fmt .Errorf ("Failed to cast exclusion result '%v'" , exclusion .exclusion .Comment )
283
+ return false , i , fmt .Errorf ("Failed to cast exclusion result '%v'" , exclusion .exclusion .Comment )
284
284
}
285
285
286
286
if exclude {
287
- return true , nil
287
+ return true , i , nil
288
288
}
289
289
}
290
290
291
- return false , nil
291
+ return false , 0 , nil
292
292
}
293
293
294
294
func (a * analyzer ) Analyze () (* AnalysisReport , error ) {
@@ -301,8 +301,9 @@ func (a *analyzer) Analyze() (*AnalysisReport, error) {
301
301
Description : a .config .Description ,
302
302
Uuid : a .config .Uuid ,
303
303
},
304
- CreatedOn : time .Now ().Format (time .RFC3339 ),
305
- Findings : []AnalysisReportFinding {},
304
+ CreatedOn : time .Now ().Format (time .RFC3339 ),
305
+ Findings : []AnalysisReportFinding {},
306
+ ExclusionsInfo : []ExclusionInfo {},
306
307
}
307
308
308
309
errs := []error {}
@@ -339,20 +340,39 @@ func (a *analyzer) Analyze() (*AnalysisReport, error) {
339
340
for _ , subject := range subjects {
340
341
sub := subject .(map [string ]interface {})
341
342
342
- exclude , err := a .shouldExclude (sub , rule .exclusions )
343
+ s := v1.Subject {}
344
+ if kind , exist := sub ["kind" ]; exist {
345
+ s .Kind = kind .(string )
346
+ }
347
+ if apiGroup , exist := sub ["apiGroup" ]; exist {
348
+ s .APIGroup = apiGroup .(string )
349
+ }
350
+ if name , exist := sub ["name" ]; exist {
351
+ s .Name = name .(string )
352
+ }
353
+ if namespace , exist := sub ["namespace" ]; exist {
354
+ s .Namespace = namespace .(string )
355
+ }
356
+
357
+ exclude , index , err := a .shouldExclude (sub , rule .exclusions )
343
358
if err != nil {
344
- klog .Errorf ("Failed to check exclusion for rule '%v' and subject %v - %v" , rule .rule .Name , sub , err )
359
+ klog .Errorf ("Failed to check exclusion for rule '%v' and subject %v - %v (exclusion #%v) " , rule .rule .Name , sub , err , index + 1 )
345
360
errs = append (errs , err )
346
361
//Continue on error - assume malformed exception expression
347
362
}
348
363
349
364
if exclude {
350
365
analysisStats .ExclusionCount ++
351
- klog .V (5 ).Infof ("Skipping subject '%v' from rule exclusion - %v" , sub , rule .rule .Name )
366
+ klog .V (5 ).Infof ("Skipping subject '%v' from rule exclusion - %v (exclusion #%v)" , sub , rule .rule .Name , index + 1 )
367
+ ei := ExclusionInfo {
368
+ Subject : & s ,
369
+ Message : fmt .Sprintf ("For rule: \" %v\" , subject excluded by the rule-level (#%v) - \" %v\" " , rule .rule .Name , index + 1 , rule .rule .Exclusions [index ].Comment ),
370
+ }
371
+ report .ExclusionsInfo = append (report .ExclusionsInfo , ei )
352
372
continue
353
373
}
354
374
355
- exclude , err = a .shouldExclude (sub , a .globalExclusions )
375
+ exclude , index , err = a .shouldExclude (sub , a .globalExclusions )
356
376
if err != nil {
357
377
klog .Errorf ("Failed to check global exclusion for rule '%v' and subject %v - %v" , rule .rule .Name , sub , err )
358
378
errs = append (errs , err )
@@ -361,7 +381,12 @@ func (a *analyzer) Analyze() (*AnalysisReport, error) {
361
381
362
382
if exclude {
363
383
analysisStats .ExclusionCount ++
364
- klog .V (5 ).Infof ("Skipping subject '%v' from rule exclusion - %v" , sub , rule .rule .Name )
384
+ klog .V (5 ).Infof ("Skipping subject '%v' from global exclusion - %v" , s , index + 1 )
385
+ ei := ExclusionInfo {
386
+ Subject : & s ,
387
+ Message : fmt .Sprintf ("For rule: \" %v\" , subject excluded by a global exclusion (#%v) - \" %v\" " , rule .rule .Name , index + 1 , a .globalExclusions [index ].exclusion .Comment ),
388
+ }
389
+ report .ExclusionsInfo = append (report .ExclusionsInfo , ei )
365
390
continue
366
391
}
367
392
@@ -389,20 +414,6 @@ func (a *analyzer) Analyze() (*AnalysisReport, error) {
389
414
References : rule .rule .References ,
390
415
}
391
416
392
- s := v1.Subject {}
393
- if kind , exist := sub ["kind" ]; exist {
394
- s .Kind = kind .(string )
395
- }
396
- if apiGroup , exist := sub ["apiGroup" ]; exist {
397
- s .APIGroup = apiGroup .(string )
398
- }
399
- if name , exist := sub ["name" ]; exist {
400
- s .Name = name .(string )
401
- }
402
- if namespace , exist := sub ["namespace" ]; exist {
403
- s .Namespace = namespace .(string )
404
- }
405
-
406
417
finding := AnalysisReportFinding {
407
418
Subject : & s ,
408
419
Finding : info ,
0 commit comments