Skip to content
This repository was archived by the owner on Oct 14, 2020. It is now read-only.

Commit ff6b1fd

Browse files
committed
Add Findings Stats to scheduled Scans which reflect the stats of the most recent scan
1 parent 4fd5021 commit ff6b1fd

File tree

5 files changed

+75
-1
lines changed

5 files changed

+75
-1
lines changed

operator/apis/execution/v1/scheduledscan_types.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,17 @@ type ScheduledScanStatus struct {
4545
// Important: Run "make" to regenerate code after modifying this file
4646

4747
LastScheduleTime *metav1.Time `json:"lastScheduleTime,omitempty"`
48+
49+
// Findings Contains the findings stats of the most recent completed scan
50+
Findings FindingStats `json:"findings,omitempty"`
4851
}
4952

5053
// +kubebuilder:object:root=true
5154
// +kubebuilder:subresource:status
55+
// +kubebuilder:printcolumn:name="UID",type=string,JSONPath=`.metadata.uid`,description="K8s Resource UID",priority=1
56+
// +kubebuilder:printcolumn:name="Type",type=string,JSONPath=`.spec.scanSpec.scanType`,description="Scan Type"
57+
// +kubebuilder:printcolumn:name="Findings",type=string,JSONPath=`.status.findings.count`,description="Total Finding Count"
58+
// +kubebuilder:printcolumn:name="Parameters",type=string,JSONPath=`.spec.scanSpec.parameters`,description="Arguments passed to the Scanner",priority=1
5259

5360
// ScheduledScan is the Schema for the scheduledscans API
5461
type ScheduledScan struct {

operator/apis/execution/v1/zz_generated.deepcopy.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

operator/config/crd/bases/execution.experimental.securecodebox.io_scheduledscans.yaml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,25 @@ metadata:
88
creationTimestamp: null
99
name: scheduledscans.execution.experimental.securecodebox.io
1010
spec:
11+
additionalPrinterColumns:
12+
- JSONPath: .metadata.uid
13+
description: K8s Resource UID
14+
name: UID
15+
priority: 1
16+
type: string
17+
- JSONPath: .spec.scanSpec.scanType
18+
description: Scan Type
19+
name: Type
20+
type: string
21+
- JSONPath: .status.findings.count
22+
description: Total Finding Count
23+
name: Findings
24+
type: string
25+
- JSONPath: .spec.scanSpec.parameters
26+
description: Arguments passed to the Scanner
27+
name: Parameters
28+
priority: 1
29+
type: string
1130
group: execution.experimental.securecodebox.io
1231
names:
1332
kind: ScheduledScan
@@ -65,6 +84,40 @@ spec:
6584
status:
6685
description: ScheduledScanStatus defines the observed state of ScheduledScan
6786
properties:
87+
findings:
88+
description: Findings Contains the findings stats of the most recent
89+
completed scan
90+
properties:
91+
categories:
92+
additionalProperties:
93+
format: int64
94+
type: integer
95+
description: FindingCategories indicates the count of finding broken
96+
down by their categories
97+
type: object
98+
count:
99+
description: Count indicates how many findings were identified in
100+
total
101+
format: int64
102+
type: integer
103+
severities:
104+
description: FindingSeverities indicates the count of finding with
105+
the respective severity
106+
properties:
107+
high:
108+
format: int64
109+
type: integer
110+
informational:
111+
format: int64
112+
type: integer
113+
low:
114+
format: int64
115+
type: integer
116+
medium:
117+
format: int64
118+
type: integer
119+
type: object
120+
type: object
68121
lastScheduleTime:
69122
format: date-time
70123
type: string

operator/config/samples/execution_v1_scheduledscan.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ spec:
99
scanType: "nmap"
1010
parameters:
1111
- "-Pn"
12-
- localhost
12+
- "192.168.178.24"

operator/controllers/execution/scheduledscan_controller.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package controllers
1919
import (
2020
"context"
2121
"fmt"
22+
"reflect"
2223
"sort"
2324
"time"
2425

@@ -78,6 +79,18 @@ func (r *ScheduledScanReconciler) Reconcile(req ctrl.Request) (ctrl.Result, erro
7879
return completedScans[i].Status.StartTime.Before(completedScans[j].Status.StartTime)
7980
})
8081

82+
if len(completedScans) >= 1 {
83+
lastFindings := completedScans[len(completedScans)-1].Status.Findings
84+
if !reflect.DeepEqual(lastFindings, scheduledScan.Status.Findings) {
85+
log.V(2).Info("Updating ScheduledScans Findings as they appear to have changed")
86+
scheduledScan.Status.Findings = *lastFindings.DeepCopy()
87+
if err := r.Status().Update(ctx, &scheduledScan); err != nil {
88+
log.Error(err, "unable to update ScheduledScan status")
89+
return ctrl.Result{}, err
90+
}
91+
}
92+
}
93+
8194
for i, scan := range completedScans {
8295
if int64(i) >= int64(len(completedScans))-scheduledScan.Spec.HistoryLimit {
8396
break

0 commit comments

Comments
 (0)