-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathslack_notifications_for_critical_container_vulnerabilities.yaml
273 lines (257 loc) · 11.5 KB
/
slack_notifications_for_critical_container_vulnerabilities.yaml
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
metadata:
version: "1"
dependencies:
apps:
- id: dynatrace.automations
version: ^1.700.0
- id: dynatrace.slack
version: ^1.3.12
inputs:
- type: connection
schema: app:dynatrace.slack:connection
targets:
- tasks.alert_in_slack.connection
workflow:
title: "[Sample] Slack notification for critical container vulnerabilities"
tasks:
alert_in_slack:
name: alert_in_slack
description: "Send a Slack notification for the vulnerability findings. "
action: dynatrace.slack:slack-send-message
active: true
input:
channel: ""
message: >-
{
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "{{ (_.finding.vulnerability_finding_events|first).get("dt.security.risk.level") }} vulnerability was detected!",
"emoji": true
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "{{ (_.finding.vulnerability_finding_events|first).get("dt.security.risk.level") }} vulnerability `{{ _.finding.get("vulnerability.id") }}` was detected in `{{ (_.finding.vulnerability_finding_events|first).get("container_image.repository") }}`"
},
"accessory": {
"type": "image",
"image_url": "https://dt-cdn.net/images/appsec-logo-with-bg-and-rounded-corners-200-8253a2bc6e.png",
"alt_text": "Dynatrace Application Security"
}
},
{
"type": "divider"
},
{
"type": "rich_text",
"elements": [
{
"type": "rich_text_section",
"elements": [
{
"type": "text",
"text": "Details:\n"
}
]
},
{
"type": "rich_text_list",
"style": "bullet",
"elements": [
{
"type": "rich_text_section",
"elements": [
{
"type": "text",
"text": "Finding source: "
},
{
"type": "text",
"text": "{{ (_.finding.vulnerability_finding_events|first).get("event.provider") }}"
}
]
},
{
"type": "rich_text_section",
"elements": [
{
"type": "text",
"text": "Registry ID: "
},
{
"type": "text",
"text": "{{ (_.finding.vulnerability_finding_events|first).get("container_image.registry") }}"
}
]
},
{
"type": "rich_text_section",
"elements": [
{
"type": "text",
"text": "Repository name: "
},
{
"type": "text",
"text": "{{ (_.finding.vulnerability_finding_events|first).get("container_image.repository") }}"
}
]
},
{
"type": "rich_text_section",
"elements": [
{
"type": "text",
"text": "Number of affected images: "
},
{
"type": "text",
"text": "{{_.finding.affected_images_count}}"
}
]
},
{
"type": "rich_text_section",
"elements": [
{
"type": "text",
"text": "Vulnerable component (version): "
},
{
"type": "text",
"text": "{{ (_.finding.vulnerability_finding_events|first).get("component.name") }} ({{ (_.finding.vulnerability_finding_events|first).get("component.version") }})"
}
]
}
]
}
]
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Click to view all vulnerabilities findings in a notebook."
},
"accessory": {
"type": "button",
"text": {
"type": "plain_text",
"text": "View all findings",
"emoji": true
},
"url": "{{ environment().url }}/ui/intent/dynatrace.notebooks/view-query#%7B%22dt.query%22%3A%22fetch%20events%5Cn%2F%2F%20data%20access%5Cn%7C%20filter%20dt.system.bucket%20%3D%3D%20%5C%22default_security_custom_events%5C%22%5Cn%20%20%20%20%20AND%20event.type%20%3D%3D%20%5C%22VULNERABILITY_FINDING%5C%22%5Cn%20%20%20%20%20AND%20object.type%3D%3D%5C%22CONTAINER_IMAGE%5C%22%5Cn%20%20%20%20%20AND%20isNotNull(component.name)%5Cn%7C%20dedup%20%7Bobject.id%2C%20vulnerability.id%2C%20component.name%2C%5Cn%20%20%20%20%20%20%20%20%20container_image.registry%2C%20container_image.repository%2C%20container_image.tags%7D%2C%20sort%3A%20%7Btimestamp%20desc%7D%5Cn%2F%2F%20aggregation%20and%20custom%20filtering%5Cn%7C%20sort%20timestamp%20desc%22%2C%22dt.timeframe%22%3A%7B%22from%22%3A%22now()-7d%22%2C%22to%22%3A%22now()%22%7D%2C%22hideInput%22%3Afalse%2C%22sourceApplication%22%3A%22dynatrace.notebooks%22%2C%22title%22%3A%22List%20recent%20container%20vulnerability%20findings%22%2C%22visualization%22%3A%22recordView%22%2C%22visualizationSettings%22%3A%7B%22thresholds%22%3A%5B%5D%2C%22chartSettings%22%3A%7B%22gapPolicy%22%3A%22connect%22%2C%22circleChartSettings%22%3A%7B%22groupingThresholdType%22%3A%22relative%22%2C%22groupingThresholdValue%22%3A0%2C%22valueType%22%3A%22relative%22%7D%2C%22categoryOverrides%22%3A%7B%7D%2C%22categoricalBarChartSettings%22%3A%7B%22categoryAxis%22%3A%22object.id%22%2C%22categoryAxisLabel%22%3A%22object.id%22%2C%22valueAxis%22%3A%22dt.security.risk.score%22%2C%22valueAxisLabel%22%3A%22dt.security.risk.score%22%7D%2C%22hiddenLegendFields%22%3A%5B%5D%2C%22fieldMapping%22%3A%7B%22timestamp%22%3A%22timestamp%22%2C%22leftAxisValues%22%3A%5B%22dt.security.risk.score%22%5D%2C%22leftAxisDimensions%22%3A%5B%22ResponseMetadata%22%5D%7D%7D%2C%22singleValue%22%3A%7B%22showLabel%22%3Atrue%2C%22label%22%3A%22%22%2C%22prefixIcon%22%3A%22%22%2C%22recordField%22%3A%22timestamp%22%2C%22autoscale%22%3Atrue%2C%22alignment%22%3A%22center%22%2C%22colorThresholdTarget%22%3A%22value%22%7D%2C%22table%22%3A%7B%22rowDensity%22%3A%22condensed%22%2C%22enableSparklines%22%3Afalse%2C%22hiddenColumns%22%3A%5B%5D%2C%22lineWrapIds%22%3A%5B%5D%2C%22firstVisibleRowIndex%22%3A0%2C%22columnWidths%22%3A%7B%7D%7D%2C%22honeycomb%22%3A%7B%22shape%22%3A%22hexagon%22%2C%22legend%22%3A%22auto%22%2C%22dataMappings%22%3A%7B%22category%22%3A%22ResponseMetadata%22%2C%22value%22%3A%22timestamp%22%7D%7D%2C%22histogram%22%3A%7B%22dataMappings%22%3A%5B%7B%22valueAxis%22%3A%22dt.security.risk.score%22%2C%22rangeAxis%22%3A%22%22%7D%5D%7D%7D%7D",
"action_id": "button-action"
}
}
]
}
reaction: []
connection: ""
workflowID: "{{ execution().workflow.id }}"
channelType: id
executionID: "{{ execution().id }}"
executionDate: "{{ execution().started_at }}"
appendToThread: false
selectedRequestType: 0
attachmentToggleValue: none
position:
x: 0
y: 2
predecessors:
- get_vulnerabilites
conditions:
states:
get_vulnerabilites: SUCCESS
custom: '{{result("get_vulnerabilites").records|length > 0}}'
concurrency: 1
withItems: finding in {{ result("get_vulnerabilites").records }}
get_vulnerabilites:
name: get_vulnerabilites
description: Query for new vulnerability findings in the last 24 hours.
action: dynatrace.automations:execute-dql-query
active: true
input:
query: >-
// The query has a rolling window of 7 days and the last 24hrs.
// Vulnerability finding events which have already been reported
// before the current 24hr window will not be reported again.
fetch events, from: now() - 7d
| filter dt.system.bucket == "default_security_custom_events"
AND event.kind == "SECURITY_EVENT"
AND object.type == "CONTAINER_IMAGE"
AND event.type == "VULNERABILITY_FINDING"
AND dt.security.risk.level == "CRITICAL"
// Aggregate vulnerability findings per vulnerability, repository,
// component and component version.
| summarize {
affected_images_count = count(),
vulnerability_finding_events = collectArray(
record(
object.id = object.id,
event.provider = event.provider,
container_image.registry = container_image.registry,
container_image.repository = container_image.repository,
component.version = component.version,
component.name = component.name,
dt.security.risk.level = dt.security.risk.level,
ingest_time = timestamp
)
)
}, by:{ vulnerability.id, vulnerability.title, event.provider, container_image.registry, container_image.repository, component.name, component.version }
// Filter out, if this vulnerability for the repository and the
component
// and version was already reported before the last 24 hours.
// For example, if the same vulnerability was reported multiple times
// during the last 7 days, don't report it again.
| filterOut iAny(vulnerability_finding_events[][ingest_time] < now() -
24h)
// Expand and deduplicate for repetitive findings if they
// were reported more than once in the last 24 hours.
| expand vulnerability_finding_events
| dedup { vulnerability.id, vulnerability.title,
vulnerability_finding_events[object.id],
vulnerability_finding_events[component.name],
vulnerability_finding_events[component.version] }
// Aggregate again to count the unique affected images within each
repository.
| summarize {
affected_images_count = count(),
vulnerability_finding_events = collectArray(
vulnerability_finding_events
)
}, by:{ vulnerability.id, vulnerability.title, event.provider, container_image.registry, container_image.repository, component.name, component.version }
| sort vulnerability_finding_events[][ingest_time] desc
customSampleResult: {}
position:
x: 0
y: 1
predecessors: []
conditions:
states: {}
custom: ""
description: ""
trigger:
schedule:
rule: null
trigger:
type: time
time: 08:00
timezone: Europe/Vienna
isActive: false
isFaulty: false
filterParameters:
earliestStart: 2024-04-10
inputs: {}
schemaVersion: 3