-
Notifications
You must be signed in to change notification settings - Fork 8
/
securityrisks.go
285 lines (223 loc) · 9.08 KB
/
securityrisks.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
package armotypes
import (
"encoding/json"
"errors"
)
type SecurityIssueStatus string
type RiskType string
type SecurityIssueSeverity string
type ResolvedReason string
const (
SecurityIssueStatusDetected SecurityIssueStatus = "Detected"
SecurityIssueStatusResolved SecurityIssueStatus = "Resolved"
RiskTypeControl RiskType = "Control"
RiskTypeControlWithNetworkPolicy RiskType = "ControlWithNetworkPolicy"
RiskTypeAttackPath RiskType = "AttackPath"
SecurityIssueSeverityCritical SecurityIssueSeverity = "Critical"
SecurityIssueSeverityHigh SecurityIssueSeverity = "High"
SecurityIssueSeverityMedium SecurityIssueSeverity = "Medium"
SecurityIssueSeverityLow SecurityIssueSeverity = "Low"
SecurityRiskExceptionPolicyType PolicyType = "securityRiskExceptionPolicy"
ResolvedReasonResourceDeleted ResolvedReason = "ResourceDeleted"
ResolvedReasonClusterDeleted ResolvedReason = "ClusterDeleted"
ResolvedReasonRiskResolved ResolvedReason = "RiskResolved"
)
// Risk represents an individual risk with an ID and type
type Risk struct {
ID string `json:"ID"`
Type RiskType `json:"type"`
// field to be enriched by the backend, relevant only to type Control
FixByNetworkPolicy bool `json:"fixByNetworkPolicy"`
}
// UnmarshalJSON is a custom unmarshaler for RiskType that validates its value
func (rt *RiskType) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
return err
}
switch s {
case string(RiskTypeControl), string(RiskTypeAttackPath):
*rt = RiskType(s)
return nil
default:
return errors.New("invalid RiskType value")
}
}
// SecurityRisk represents the main object with various fields and an array of Risks
type SecurityRisk struct {
ID string `json:"ID"`
Name string `json:"name"`
Description string `json:"description"`
WhatIs string `json:"whatIs"`
Severity string `json:"severity"`
Category string `json:"category"`
Remediation string `json:"remediation"`
Risks []Risk `json:"risks"`
SecurityIssues []ISecurityIssue `json:"securityIssues,omitempty"`
SmartRemediation bool `json:"smartRemediation"`
}
func (sr *SecurityRisk) GetRisks() []Risk {
return sr.Risks
}
func (sr *SecurityRisk) GetRisksIDsByType(riskType RiskType) []string {
var risksIDs []string
for _, risk := range sr.Risks {
if risk.Type == riskType {
risksIDs = append(risksIDs, risk.ID)
}
}
return risksIDs
}
func (sr *SecurityRisk) GetRiskTypes() []RiskType {
riskTypes := make(map[RiskType]interface{})
for _, risk := range sr.Risks {
riskTypes[risk.Type] = nil
}
keys := make([]RiskType, 0, len(riskTypes))
for key := range riskTypes {
keys = append(keys, key)
}
return keys
}
type SecurityIssuesSummary struct {
SecurityRiskID string `json:"securityRiskID"`
SecurityRiskName string `json:"securityRiskName"`
Category string `json:"category"`
Severity string `json:"severity"`
LastUpdated string `json:"lastUpdated"`
AffectedClustersCount int `json:"affectedClustersCount"`
AffectedNamespacesCount int `json:"affectedNamespacesCount"`
AffectedResourcesCount int `json:"affectedResourcesCount"`
ResourcesDetectedLastUpdateCount int `json:"resourcesDetectedLastUpdateCount"`
ResourcesResolvedLastUpdateCount int `json:"resourcesResolvedLastUpdateCount"`
ResourcesDetectedLastChangeCount int `json:"resourcesDetectedLastChangeCount"`
ResourcesDetectedLastChange []Resource `json:"resourcesDetectedLastChange"`
// resources that are resolved excluding deleted
ResourcesResolvedLastChangeCount int `json:"resourcesResolvedLastChangeCount"`
ResourcesResolvedLastChange []Resource `json:"resourcesResolvedLastChange"`
// resources that are resolved because of a kubernetes resource deletion or cluster deletion
ResourcesDeletedLastChangeCount int `json:"resourcesDeletedLastChangeCount"`
ResourcesDeletedLastChange []Resource `json:"resourcesDeletedLastChange"`
AffectedResourcesChange int `json:"affectedResourcesChange"`
// if True, control supports smart remediation
// swagger:ignore
SupportsSmartRemediation bool `json:"supportsSmartRemediation"` // DEPRECATED
SmartRemediation bool `json:"smartRemediation"`
}
type SecurityIssuesCategories struct {
CategoryResourceCounters map[string]int `json:"categoryResourceCounter"`
TotalResources int `json:"totalResources"`
}
func (sic *SecurityIssuesCategories) SetCategoryTotal(category string, total int) {
sic.CategoryResourceCounters[category] = total
}
type SecurityIssuesSeverities struct {
SeverityResourceCounters map[SecurityIssueSeverity]int `json:"severityResourceCounter"`
TotalResources int `json:"totalResources"`
}
func NewSecurityIssuesCategories() SecurityIssuesCategories {
return SecurityIssuesCategories{
CategoryResourceCounters: map[string]int{},
TotalResources: 0,
}
}
func (sis *SecurityIssuesSeverities) SetSeverityTotal(severity SecurityIssueSeverity, total int) {
sis.SeverityResourceCounters[severity] = total
}
func NewSecurityIssuesSeverities() SecurityIssuesSeverities {
return SecurityIssuesSeverities{
SeverityResourceCounters: map[SecurityIssueSeverity]int{
SecurityIssueSeverityCritical: 0,
SecurityIssueSeverityHigh: 0,
SecurityIssueSeverityMedium: 0,
SecurityIssueSeverityLow: 0,
},
TotalResources: 0,
}
}
type ISecurityIssue interface {
GetClusterName() string
GetShortClusterName() string
SetClusterName(string)
SetShortClusterName(string)
}
type SecurityIssue struct {
ISecurityIssue `json:",inline,omitempty"`
Cluster string `json:"cluster"`
ClusterShortName string `json:"clusterShortName"`
Namespace string `json:"namespace"`
ResourceName string `json:"resourceName"`
Kind string `json:"kind"`
ResourceID string `json:"resourceID"`
K8sResourceHash string `json:"k8sResourceHash"`
RiskID string `json:"riskID"` // controlID/attackTrackID
RiskType RiskType `json:"riskType,omitempty"`
SecurityRiskID string `json:"securityRiskID"`
Status SecurityIssueStatus `json:"status"`
IsNew bool `json:"isNew"`
LastTimeDetected string `json:"lastTimeDetected,omitempty"`
LastTimeResolved string `json:"lastTimeResolved,omitempty"`
ExceptionApplied bool `json:"exceptionApplied"`
ExceptionPolicyGUID string `json:"exceptionPolicyGUID"`
}
func (si *SecurityIssue) GetClusterName() string {
return si.Cluster
}
func (si *SecurityIssue) GetShortClusterName() string {
return si.ClusterShortName
}
func (si *SecurityIssue) SetClusterName(clusterName string) {
si.Cluster = clusterName
}
func (si *SecurityIssue) SetShortClusterName(clusterShortName string) {
si.ClusterShortName = clusterShortName
}
type SecurityIssueControl struct {
SecurityIssue `json:",inline"`
ControlID string `json:"controlID"`
ReportGUID string `json:"reportGUID"`
FrameworkName string `json:"frameworkName"`
// relevant for controls with network policy fix
NetworkPolicyStatus NetworkPolicyStatus `json:"networkPolicyStatus,omitempty"`
MissingRuntimeInfoReason MissingRuntimeInfoReason `json:"missingRuntimeInfoReason,omitempty"`
}
type SecurityIssueAttackPath struct {
SecurityIssue `json:",inline"`
AttackChainID string `json:"attackChainID"`
FirstSeen string `json:"firstSeen"`
}
type SecurityRiskExceptionPolicy struct {
BaseExceptionPolicy `json:",inline"`
Name string `json:"name"`
Category string `json:"category"`
Severity string `json:"severity"`
SecurityRiskID string `json:"securityRiskID"`
Risks []Risk `json:"risks"`
}
type SecurityIssuesTrends struct {
// date in format yyyy-mm-dd
Date string `json:"date"`
// new detected issues within the day
NewDetected int `json:"newDetected"`
// new resolved issues within the day
NewResolved int `json:"newResolved"`
TotalNewDetectedUpToDate int `json:"totalNewDetectedUpToDate"`
TotalNewResolvedUpToDate int `json:"totalNewResolvedUpToDate"`
// new detected issues at the end of the day
NewDetectedEndOfDay int `json:"newDetectedEndOfDay"`
// new resolved issues at the end of the day
NewResolvedEndOfDay int `json:"newResolvedEndOfDay"`
// total detected from the beginning of the period until current date
TotalDetectedUpToDate int `json:"totalDetectedUpToDate"`
}
type SecurityIssuesTrendsSummary struct {
SecurityIssuesTrends []SecurityIssuesTrends `json:"securityIssuesTrends"`
// total issues detected for the period
TotalDetectedForPeriod int `json:"totalDetectedForPeriod"`
// total issues resolved for the period
TotalResolvedForPeriod int `json:"totalResolvedForPeriod"`
// current detected issues
CurrentDetected int `json:"currentDetected"`
// CurrentDetected - TotalDetectedUpToDate of first date of period.
ChangeFromBeginningOfPeriod int `json:"changeFromBeginningOfPeriod"`
}