-
Notifications
You must be signed in to change notification settings - Fork 179
Expand file tree
/
Copy path.helm-docs.gotmpl
More file actions
452 lines (362 loc) · 18.1 KB
/
.helm-docs.gotmpl
File metadata and controls
452 lines (362 loc) · 18.1 KB
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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
{{- /*
SPDX-FileCopyrightText: the secureCodeBox authors
SPDX-License-Identifier: Apache-2.0
*/ -}}
{{- define "extra.docsSection" -}}
---
title: "Notification WebHook"
category: "hook"
type: "integration"
state: "released"
usecase: "Publishes Scan Summary to MS Teams, Slack and others."
---
{{- end }}
{{- define "extra.dockerDeploymentSection" -}}
## Supported Tags
- `latest` (represents the latest stable release build)
- tagged releases, e.g. `3.0.0`, `2.9.0`, `2.8.0`, `2.7.0`
{{- end }}
{{- define "extra.chartAboutSection" -}}
## What is "Notification" Hook about?
Installing the Notification WebHook hook will add a ReadOnly Hook to your namespace which is capable of sending scan results containing `findings` as messages to different tools like messangers or even email.
You can customise the message templates on your behalf or use the already provided one.
{{- end }}
{{- define "extra.scannerConfigurationSection" -}}{{- end }}
{{- define "extra.chartConfigurationSection" -}}
## Additional Chart Configurations
Installing the Notification hook will add a ReadOnly Hook to your namespace.
```bash
helm upgrade --install notification ./hooks/notification/ --values /path/to/your/values"
```
The `values.yaml` you need depends on the notification type you want to use.
Please take a look at the documentation for each type (e.g. for slack see [Configuration of a Slack Notification](#configuration-of-a-slack-notification-webhook))
### Available Notifier
- [Slack](#configuration-of-a-slack-notification-webhook)
- [Slack App](#configuration-of-a-slack-app-notification)
- [Email](#configuration-of-an-email-notification)
- [MS Teams](#configuration-of-a-ms-teams-notification)
- [Trello](#configuration-of-a-trello-notification)
### Configuration of a Notification
The general configuration of a notification looks something like this
```yaml
notificationChannels:
- name: slack
type: slack
template: slack-messageCard
skipNotificationOnZeroFinding: true
rules:
- matches:
anyOf:
- category: "Open Port"
endPoint: "SOME_ENV"
env:
- name: SOME_ENV
valueFrom:
secretKeyRef:
name: some-secret
key: some-key
```
The Notification Hook enables you to define multiple so called `notificationChannels`. A `notificationChannel` defines the Notification to a specific platform (e.g. Slack or Teams).
The `name` is used to for debugging failing notifications.
it can be a _string_ of you choice.
The `type` specifies the type of the notification (in this example slack).
See [Available Notifier](#available-notifier).
The `template` field defines the name of a Nunjucks template to send to your notification channel.
These templates are usually tied to their notification channel (slack templates will not work for teams).
The template `slack-messageCard` is provided by default.
Notice that for the name of the template we chose to omit the file type.
The template `slack-messageCard` will point to `slack-messageCard.njk` in the filesystem of the hook.
The `skipNotificationOnZeroFindings` if set to true will cause the notifier when there were no findings.
This can happen when the scan did not identify any or if all findings were filtered out using [rules](#rule-configuration).
Defaults to `false` if not set.
You can use `skipNotificationOnZeroFindings` to only send out notification for non duplicate findings, e.g. by combining the DefectDojo hook with this one and filtering out the `duplicate` attribute in the rules.
The `endPoint` specifies where the notification has to go to.
To protect the actual endPoint (e.g. a webhook url) this should point to an env name defined under `env`
For slack this would be your webhook URL to slack.
To define conditions when a notification should be created you can use `rules`.
If no rules are specified, this hook will assume that you always want to be notified.
Under `env` you have to define additional information needed for your templates such as the actual endpoint.
`env` will be mapped to the `env` implementation of Kubernetes.
This means that you can define key-value pairs as well as providing envs via secrets (See [Define Environment Variables for a Container | Kubernetes](https://kubernetes.io/docs/tasks/inject-data-application/define-environment-variable-container/)).
#### Rule Configuration
The rules can be defined in the values of the Chart.
The syntax and semantic for these rules are quite similar to CascadingRules (See: [secureCodeBox | CascadingRules](https://www.securecodebox.io/docs/api/crds/cascading-rule))
To define Rules you will have to provide the `rules` field with one or more `matches` elements.
Each `matches` defines one Rule.
For example:
```yaml
rules:
- matches:
anyOf:
- category: "Open Port"
attributes:
port: 23
state: open
```
This Rule will match all Findings with an open port on 23.
##### matches
Within the `matches` you will have to provide `anyOf`
`anyOf` contains one or more conditions to be met by the finding to match the rule.
Notice that only one of these elements needs to match the finding for the rule to match.
#### Configuration of a Slack Notification (WebHook)
To configure a Slack notification set the `type` to `slack` and the `endPoint` to point to your env containing your Webhook URL to slack.
You can use one of the following default templates:
- `slack-messageCard`: Sends a message with a summary listing the number of findings per category and severity.
- `slack-individual-findings-with-defectdojo`: Sends a message with a list of all findings with a link to the finding in DefectDojo. Will only work correctly if the DefectDojo hook is installed in the same namespace.
##### Example Config
The below example shows how to create a helm values chart and load secrets for access.
You must have `endPoint` point to a [defined environment variable](https://github.com/secureCodeBox/secureCodeBox/blob/main/hooks/notification/hook/hook.ts#L20), not a string.
```
# cat myvalues.yaml
notificationChannels:
- name: nmapopenports
type: slack
template: slack-messageCard
skipNotificationOnZeroFinding: true
rules:
- matches:
anyOf:
- category: "Open Port"
endPoint: POINTER_TO_ENV
env:
- name: POINTER_TO_ENV
valueFrom:
secretKeyRef:
name: myslacksecret
key: SLACK_WEB_HOOK
# cat values_slack_secrets.yaml
apiVersion: v1
kind: Secret
metadata:
name: myslacksecret
type: Opaque
data:
SLACK_WEB_HOOK: NOIDONTHINKSOBASE64STUFF
kubectl apply -f values_slack_secrets.yaml
helm upgrade --install nwh oci://ghcr.io/securecodebox/helm/notification-hook --values myvalues.yaml
```
#### Configuration of a Slack App Notification
The `slack-app` notifier is an _alternate_ way to send notifications to slack using the slack api directly rather then using webhooks.
Use `slack-app` over the normal `slack` if you want to send notifications into different slack channels on a per scan basis.
##### Slack App Configuration
To set it up, you'll need to create a new slack app at [https://api.slack.com/apps/](https://api.slack.com/apps/) and add the `chat:write` "Bot Token Scope" to it on the "OAuth & Permissions" tab. Then add the bot to your workspace, this will give you the access token (should begin with a `xoxb-`).
To configure a Slack notification set the `type` to `slack-app` and reference the secret via the `SLACK_APP_TOKEN` env var.
##### Example Config
```yaml
notificationChannels:
- name: slack
type: slack-app
template: slack-messageCard
rules: []
env:
# you can create the secret via: kubectl create secret generic slack-app-token --from-literal="token=xoxb-..."
- name: SLACK_APP_TOKEN
valueFrom:
secretKeyRef:
name: slack-app-token
key: token
# configures which channel the messages are send to if the scan doesn't specify a channel
- name: SLACK_DEFAULT_CHANNEL
value: "#example-channel"
```
##### Supported Notification Channels
The `slack-app` notifier supports the same message templates as the `slack` notifier.
See [slack](#configuration-of-a-slack-notification-webhook) for the supported message types.
##### Scan / Channel Config
You can configure to which channel the message is sent to by setting the `notification.securecodebox.io/slack-channel` to the channel the message should be sent to, the following example will send its notifications to the `#juice-shop-dev` channel in the slack workspace of the configured token.
> Note: The channel needs to have the app you've create invited to it. Otherwise the app will not be permitted to write to it.
```yaml
apiVersion: "execution.securecodebox.io/v1"
kind: Scan
metadata:
name: "nmap-juice-shop"
annotations:
notification.securecodebox.io/slack-channel: "#juice-shop-dev"
spec:
scanType: "nmap"
parameters:
- juice-shop.default.svc
```
#### Configuration Of An Email Notification
To configure an email notification set the `type` to `email` and the `endPoint` to point to your env containing your target email address.
You can use one of the following default templates:
- `email`: Sends a email with a summary listing the number of findings per category and severity.
Additional to this configuration you will have to provide a special smtp configuration URL.
This config reflects the transporter configuration of nodemailer (See [nodemailer | SMTP Transport](https://nodemailer.com/smtp/)).
This configuration needs to be specified under `env` in the values yaml.
The identifier for this config has to be `SMTP_CONFIG`.
A basic configuration could look like this:
```yaml
notificationChannels:
- name: email
type: email
template: email
rules: []
endPoint: "someone@example.com"
env:
- name: SMTP_CONFIG
# you can create the secret via: kubectl create secret generic email-credentials --from-literal="smtp-config=smtp://user:pass@smtp.domain.tld/"
valueFrom:
secretKeyRef:
name: email-credentials
key: smtp-config
```
To provide a custom `from` field for your email you can specify `EMAIL_FROM` under env.
For example:
```
env:
- name: SMTP_CONFIG
valueFrom:
secretKeyRef:
name: email-credentials
key: smtp-config
- name: EMAIL_FROM
value: secureCodeBox
```
You can overwrite the default email recipient of the notification mail for every scan by setting a `notification.securecodebox.io/email-recipient` annotation on the scan to another email address:
```yaml
apiVersion: "execution.securecodebox.io/v1"
kind: Scan
metadata:
name: "nmap-juice-shop"
annotations:
notification.securecodebox.io/email-recipient: "foo@example.com"
spec:
scanType: "nmap"
parameters:
- juice-shop.default.svc
```
#### Configuration Of A MS Teams Notification
To configure a MS Teams notification you need to set the type to `ms-teams`.
In `endPoint` you need to specify the MS Teams webhook.
To use the template provided by the secureCodeBox set template to `msteams-messageCard`.
The default template allows you to specify an additional set of information.
If you use an external web based vulnerability management system with some kind of dashboard, you can set the variable `VULNMANAG_ENABLED` to true and point the `VULNMANAG_DASHBOARD_URL` to the URL of your vulnerability management.
This will add a button in the notification that links directly to your dashboard.
You can also add a button that opens your findings directly in your dashboard.
To do this you need to specify `dashboardFingingsUrl`.
You will have to replace the id of the scan in this url with `{{ `{{ uid }}` }}` so that nunjucks can parse these urls.
A basic configuration could look like this:
```yaml
notificationChannels:
- name: ms-teams
type: ms-teams
template: msteams-messageCard
rules: []
endPoint: "https://example/sadf12"
env:
- name: VULNMANAG_ENABLED
value: true
- name: VULNMANAG_DASHBOARD_URL
value: "somedashboard.url"
- name: VULNMANAG_DASHBOARD_FINDINGS_URL
value: "somedashboard.url/findings/{{ `{{ uid }}` }}"
```
#### Configuration of a Trello Notification
A Trello notification is used to create Trello cards for each finding that matches the defined rules. This allows integrating SecureCodeBox into your development workflow. Each finding will be created as a card with the following information:
```
Card Name: <severity>: <name>
Card Body: <location> <category> <description> <attributes>
```
##### Requirements
- Please read the [Trello API documentation](https://developer.atlassian.com/cloud/trello/guides/rest-api/api-introduction/) for a description on how to setup your Trello key and token.
- Identify your target card list where the new cards will be created and get the list ID. To find the card list and label ids use the Trello JSON hack as described here https://stackoverflow.com/questions/26552278/trello-api-getting-boards-lists-cards-information
- Read the [Trello Cards API](https://developer.atlassian.com/cloud/trello/rest/api-group-cards) for more information on the card creation options.
##### Configuration
To configure a Trello notification set the `type` to `trello` and the `endPoint` to point to your env containing the Trello cards API endpoint. You also need to define the following env vars (if an env var is not defined it will take the default value, if required and not set the notification won't be sent):
- TRELLO_CARDS_ENDPOINT: The Trello cards API endpoint. Default: https://api.trello.com/1/cards.
- TRELLO_KEY: Your Trello API key. Read the requirements above. Required.
- TRELLO_TOKEN: Your Trello API token. Read the requirements above. Required.
- TRELLO_LIST: Trello unique Id of the list where the cards will be placed. Required.
- TRELLO_LABELS: Comma separated list of Trello label IDs to apply to the card. If empty no labels will be applied. Default: ""
- TRELLO_POS: The position of the card in the list as defined by the Trello cards API. Options: top, bottom, or a positive float. Default: top.
- TRELLO_TITLE_PREFIX: An optional arbitrary text to add to the title of the card. Default "".
##### Example Config
The below example shows how to create a helm values chart and load secrets for access.
You must have `endPoint` point to a [defined environment variable](https://github.com/secureCodeBox/secureCodeBox/blob/main/hooks/notification/hook/hook.ts#L20), not a string.
```yaml
# cat trello_values.yaml
notificationChannels:
- name: nmapopenports
type: trello
skipNotificationOnZeroFinding: true
rules:
- matches:
anyOf:
- category: "Open Port"
endPoint: TRELLO_CARDS_ENDPOINT
env:
- name: TRELLO_CARDS_ENDPOINT
value: https://api.trello.com/1/cards
- name: TRELLO_KEY
valueFrom:
secretKeyRef:
name: trello
key: key
- name: TRELLO_TOKEN
valueFrom:
secretKeyRef:
name: trello
key: token
- name: TRELLO_LIST
value: 123a456b789c013d
- name: TRELLO_LABELS
value: "111a111b222c333f,555a666b777c888d"
- name: TRELLO_POS
value: top
- name: TRELLO_TITLE_PREFIX
value: "Alert! "
---
# cat trello_secrets.yaml
apiVersion: v1
kind: Secret
metadata:
name: trello
type: Opaque
stringData:
key: YOURSECRETTRELLOAPIKEY
token: YOURSECRETTRELLOAPITOKEN
kubectl apply -f trello_secrets.yaml
helm upgrade --install nwh oci://ghcr.io/securecodebox/helm/notification-hook --values trello_values.yaml
```
#### Configuration Of A rocket.chat Notification
To configure a [rocket.chat](https://rocket.chat/) notification you need to set the type to `rocket-chat`.
In `endPoint` you need to specify url to your rocket.chat instances `post.message` endpoint. E.g. `https://rocketchat.example.com/api/v1/chat.postMessage`
To use the template provided by the secureCodeBox set template to `rocket-chat`.
The rocket.chat notifier requires a rocket chat api token to work correctly, see example below on how this is configured.
You can configure the channel the hook sends the message to by setting the `notification.securecodebox.io/rocket-chat-channel=#my-channel` on the scan.
If the channel is not set the hook wil send the notification to the default channel configured, see config example below.
A basic configuration could look like this:
```yaml
notificationChannels:
- name: rocket-chat
type: rocket-chat
template: rocket-chat
rules: []
endPoint: "https://rocketchat.example.com/api/v1/chat.postMessage"
env:
- name: ROCKET_CHAT_AUTH_TOKEN
# you can create the secret via: kubectl create secret generic rocket-chat --from-literal="token=token-goes-here"
valueFrom:
secretKeyRef:
name: rocket-chat
key: token
- name: ROCKET_CHAT_USER_ID
value: "XcNTAqEhyBD14aqcZ"
- name: ROCKET_CHAT_DEFAULT_CHANNEL
# channel used to send in notifications if no channel is set for the individual scan.
value: "#securecodebox"
```
### Custom Message Templates
CAUTION: Nunjucks templates allow code to be injected! Use templates from trusted sources only!
The Notification Hook enables you to write your own message templates if the templates provided by default are not sufficient.
Templates for this hook are written using the [Nunjucks](https://mozilla.github.io/nunjucks/) templating engine.
To fill your template with data we provide the following objects.
| object | Details |
| -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| findings | An array of the findings matching your rules (See [Finding secureCodeBox API Specification](https://www.securecodebox.io/docs/api/finding) |
| scan | An Object containing information about the scan that triggered the notification (See [Scan secureCodeBox API Specification](https://www.securecodebox.io/docs/api/crds/scan) |
| args | contains `process.env` (See: [process.env nodejs](https://nodejs.org/api/process.html#process_process_env)) you can use this to access data defined in `env` of the `values.yaml` |
{{- end }}
{{- define "extra.scannerLinksSection" -}}
{{- end }}