Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notifications: Add support for webhooks #7311

Merged
merged 63 commits into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
2756991
Add go-httpbin
kiblik Dec 21, 2022
77e29cc
First round of changes
kiblik Dec 22, 2022
576e61e
move webhooks to separated model,fix err handliing
kiblik Jan 9, 2023
6b2b167
flake8
kiblik Jan 9, 2023
cf3faca
Uset contant instead of strings
kiblik Jan 10, 2023
3833248
Add basic API endpoints
kiblik Jan 23, 2023
8e4e949
Add owner of endpoint
kiblik Jan 23, 2023
4318941
Update go-httpbin
kiblik Feb 9, 2023
d5c2db0
Basic GUI
kiblik Feb 21, 2023
775b7f8
per line
kiblik Mar 8, 2023
03bb0c4
upgrade go-httpbin, move db_mig
kiblik Mar 9, 2023
1ac2b0e
Disable view and changes if not enabled in setting
kiblik Mar 9, 2023
da32d89
Fix full text of status
kiblik Mar 9, 2023
1e13544
Update go-httpbin
kiblik May 9, 2023
7f0fe36
Move migration
kiblik May 9, 2023
f498fc2
Rename model + flake8
kiblik May 9, 2023
84a7d7a
Rebase db mig
kiblik Jun 8, 2023
6f78c7e
Rearange setting buttons, add connectivity validator
kiblik Jul 22, 2023
a9e4a7f
Handle more generic errors from 'requests'
kiblik Aug 17, 2023
f9e897f
flake8
kiblik Aug 17, 2023
3956710
Rewrite YAML template to JSON request body
kiblik Aug 25, 2023
6c274ee
update go-httpbin
kiblik Oct 10, 2023
966087f
Update go-httpbin
kiblik Dec 5, 2023
e860440
Inc db_mig
kiblik Dec 13, 2023
af5951a
Upgrade
kiblik Mar 16, 2024
5119b5c
Ruff
kiblik May 18, 2024
9f4b3f1
Update httpbin, move db_mig, use as_view
kiblik May 28, 2024
6095fb2
Fix nones, more verbose "missing template"
kiblik Jun 5, 2024
3ee409e
Prepare templates
kiblik Jun 14, 2024
1bf75ff
Usable by admins only
kiblik Jun 14, 2024
3b32e2c
API tests
kiblik Jun 15, 2024
b043b9c
Add main unittests
kiblik Jun 20, 2024
48ab8ea
Update 4xx test
kiblik Jun 20, 2024
a8abc61
Docs: add Transition graph
kiblik Jul 3, 2024
140c2af
ruff
kiblik Jul 5, 2024
a99e661
Rewrite
kiblik Jul 5, 2024
dbbd7ed
Start "webhook.endpoint" in unit-tests
kiblik Jul 5, 2024
6a1b378
Extend webhook_status_cleanup, add note to related places
kiblik Jul 8, 2024
7b8d6bf
More tests
kiblik Jul 8, 2024
50b4562
Small adjustments
kiblik Jul 9, 2024
503ebbd
Set max_length
kiblik Jul 10, 2024
5d97a21
Better handle nones
kiblik Jul 10, 2024
b630f90
Add basic doc + fix findings_list
kiblik Jul 10, 2024
6427496
Update docs
kiblik Jul 12, 2024
f4f43ef
Clean ruff
kiblik Jul 12, 2024
fb50101
Fix db_mig
kiblik Aug 5, 2024
416d040
Fix long notes
kiblik Aug 9, 2024
fb10310
Clean ruff
kiblik Aug 13, 2024
5e1877b
Move "webhook.endpoint" from debug docker to dev
kiblik Aug 16, 2024
f69dcdd
Make fields "editable=False"
kiblik Aug 16, 2024
47fd8c1
Try to fix accesslint
kiblik Aug 16, 2024
82d1652
Use class-based choices
kiblik Aug 16, 2024
ad3beb2
Shorter default timeout
kiblik Aug 16, 2024
3198e81
Update dojo/notifications/views.py
kiblik Aug 16, 2024
a1868e5
Finish preprocess_request
kiblik Aug 16, 2024
219886d
Update dojo/notifications/helper.py
kiblik Aug 16, 2024
454e76d
Show error-times as hint
kiblik Aug 16, 2024
f2e5bd1
Try to fix accesslint
kiblik Aug 22, 2024
6dbbe25
Rename `url` to `url_ui` and add `url_api`
kiblik Aug 23, 2024
f985040
inc db_mig
kiblik Sep 11, 2024
d641327
Accept any 2xx as successful
kiblik Sep 11, 2024
95453cc
Add permission checker for item in menu
kiblik Sep 11, 2024
3cc64f7
Fix editing for superadmin
kiblik Sep 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/rest-framework-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ jobs:
run: docker/setEnv.sh unit_tests_cicd

# phased startup so we can use the exit code from unit test container
- name: Start Postgres
run: docker compose up -d postgres
- name: Start Postgres and webhook.endpoint
run: docker compose up -d postgres webhook.endpoint

# no celery or initializer needed for unit tests
- name: Unit tests
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.override.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,5 @@ services:
published: 8025
protocol: tcp
mode: host
"webhook.endpoint":
image: mccutchen/go-httpbin:v2.14.0@sha256:e0f398a0a29e7cf00a2467326344d70b4d89d0786d8f9a3287c2a0371c804823
2 changes: 2 additions & 0 deletions docker-compose.override.unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ services:
redis:
image: busybox:1.36.1-musl
entrypoint: ['echo', 'skipping', 'redis']
"webhook.endpoint":
image: mccutchen/go-httpbin:v2.14.0@sha256:e0f398a0a29e7cf00a2467326344d70b4d89d0786d8f9a3287c2a0371c804823
volumes:
defectdojo_postgres_unit_tests: {}
defectdojo_media_unit_tests: {}
2 changes: 2 additions & 0 deletions docker-compose.override.unit_tests_cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ services:
redis:
image: busybox:1.36.1-musl
entrypoint: ['echo', 'skipping', 'redis']
"webhook.endpoint":
image: mccutchen/go-httpbin:v2.14.0@sha256:e0f398a0a29e7cf00a2467326344d70b4d89d0786d8f9a3287c2a0371c804823
volumes:
defectdojo_postgres_unit_tests: {}
defectdojo_media_unit_tests: {}
2 changes: 1 addition & 1 deletion docs/content/en/integrations/burp-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: "Defect Dojo Burp plugin"
description: "Export findings directly from Burp to DefectDojo."
draft: false
weight: 8
weight: 9
---

**Please note: The DefectDojo Burp Plugin has been sunset and is no longer a supported feature.**
Expand Down
2 changes: 1 addition & 1 deletion docs/content/en/integrations/exporting.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: "Exporting"
description: "DefectDojo has the ability to export findings."
draft: false
weight: 11
weight: 12
---


Expand Down
2 changes: 1 addition & 1 deletion docs/content/en/integrations/google-sheets-sync.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: "Google Sheets synchronisation"
description: "Export finding details to Google Sheets and upload changes from Google Sheets."
draft: false
weight: 7
weight: 8
---

**Please note - the Google Sheets feature has been deprecated as of DefectDojo version 2.21.0 - these documents are for reference only.**
Expand Down
2 changes: 1 addition & 1 deletion docs/content/en/integrations/languages.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: "Languages and lines of code"
description: "You can import an analysis of languages used in a project, including lines of code."
draft: false
weight: 9
weight: 10
---

## Import of languages for a project
Expand Down
79 changes: 79 additions & 0 deletions docs/content/en/integrations/notification_webhooks/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
---
title: "Notification Webhooks (experimental)"
description: "How to setup and use webhooks"
weight: 7
chapter: true
---

Webhooks are HTTP requests coming from the DefectDojo instance towards user-defined webserver which expects this kind of incoming traffic.

## Transition graph:

It is not unusual that in some cases webhook can not be performed. It is usually connected to network issues, server misconfiguration, or running upgrades on the server. DefectDojo needs to react to these outages. It might temporarily or permanently disable related endpoints. The following graph shows how it might change the status of the webhook definition based on HTTP responses (or manual user interaction).

```mermaid
flowchart TD

START{{Endpoint created}}
ALL{All states}
STATUS_ACTIVE([STATUS_ACTIVE])
STATUS_INACTIVE_TMP
STATUS_INACTIVE_PERMANENT
STATUS_ACTIVE_TMP([STATUS_ACTIVE_TMP])
END{{Endpoint removed}}

START ==> STATUS_ACTIVE
STATUS_ACTIVE --HTTP 200 or 201 --> STATUS_ACTIVE
STATUS_ACTIVE --HTTP 5xx <br>or HTTP 429 <br>or Timeout--> STATUS_INACTIVE_TMP
STATUS_ACTIVE --Any HTTP 4xx response<br>or any other HTTP response<br>or non-HTTP error--> STATUS_INACTIVE_PERMANENT
STATUS_INACTIVE_TMP -.After 60s.-> STATUS_ACTIVE_TMP
STATUS_ACTIVE_TMP --HTTP 5xx <br>or HTTP 429 <br>or Timeout <br>within 24h<br>from the first error-->STATUS_INACTIVE_TMP
STATUS_ACTIVE_TMP -.After 24h.-> STATUS_ACTIVE
STATUS_ACTIVE_TMP --HTTP 200 or 201 --> STATUS_ACTIVE_TMP
STATUS_ACTIVE_TMP --HTTP 5xx <br>or HTTP 429 <br>or Timeout <br>within 24h from the first error<br>or any other HTTP response or error--> STATUS_INACTIVE_PERMANENT
ALL ==Activation by user==> STATUS_ACTIVE
ALL ==Deactivation by user==> STATUS_INACTIVE_PERMANENT
ALL ==Removal of endpoint by user==> END
```

Notes:

1. Transitions:
- bold: manual changes by user
- dotted: automated by celery
- others: based on responses on webhooks
1. Nodes:
- Stadium-shaped: Active - following webhook can be sent
- Rectangles: Inactive - performing of webhook will fail (and not retried)
- Hexagonal: Initial and final states
- Rhombus: All states (meta node to make the graph more readable)

## Body and Headers

The body of each request is JSON which contains data about related events like names and IDs of affected elements.
Examples of bodies are on pages related to each event (see below).

Each request contains the following headers. They might be useful for better handling of events by server this process events.

```yaml
User-Agent: DefectDojo-<version of DD>
X-DefectDojo-Event: <name of the event>
X-DefectDojo-Instance: <Base URL for DD instance>
```
## Disclaimer

This functionality is new and in experimental mode. This means Functionality might generate breaking changes in following DefectDojo releases and might not be considered final.

However, the community is open to feedback to make this functionality better and transform it stable as soon as possible.

## Roadmap

There are a couple of known issues that are expected to be implemented as soon as core functionality is considered ready.

- Support events - Not only adding products, product types, engagements, tests, or upload of new scans but also events around SLA
- User webhook - right now only admins can define webhooks; in the future also users will be able to define their own
- Improvement in UI - add filtering and pagination of webhook endpoints

## Events

<!-- Hugo automatically renders list of subpages here -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
title: "Event: engagement_added"
weight: 3
chapter: true
---

## Event HTTP header
```yaml
X-DefectDojo-Event: engagement_added
```

## Event HTTP body
```json
{
"description": null,
"engagement": {
"id": 7,
"name": "notif eng",
"url_api": "http://localhost:8080/api/v2/engagements/7/",
"url_ui": "http://localhost:8080/engagement/7"
},
"product": {
"id": 4,
"name": "notif prod",
"url_api": "http://localhost:8080/api/v2/products/4/",
"url_ui": "http://localhost:8080/product/4"
},
"product_type": {
"id": 4,
"name": "notif prod type",
"url_api": "http://localhost:8080/api/v2/product_types/4/",
"url_ui": "http://localhost:8080/product/type/4"
},
"url_api": "http://localhost:8080/api/v2/engagements/7/",
"url_ui": "http://localhost:8080/engagement/7",
"user": null
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
title: "Event: product_added"
weight: 2
chapter: true
---

## Event HTTP header
```yaml
X-DefectDojo-Event: product_added
```

## Event HTTP body
```json
{
"description": null,
"product": {
"id": 4,
"name": "notif prod",
"url_api": "http://localhost:8080/api/v2/products/4/",
"url_ui": "http://localhost:8080/product/4"
},
"product_type": {
"id": 4,
"name": "notif prod type",
"url_api": "http://localhost:8080/api/v2/product_types/4/",
"url_ui": "http://localhost:8080/product/type/4"
},
"url_api": "http://localhost:8080/api/v2/products/4/",
"url_ui": "http://localhost:8080/product/4",
"user": null
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
title: "Event: product_type_added"
weight: 1
chapter: true
---

## Event HTTP header
```yaml
X-DefectDojo-Event: product_type_added
```

## Event HTTP body
```json
{
"description": null,
"product_type": {
"id": 4,
"name": "notif prod type",
"url_api": "http://localhost:8080/api/v2/product_types/4/",
"url_ui": "http://localhost:8080/product/type/4"
},
"url_api": "http://localhost:8080/api/v2/product_types/4/",
"url_ui": "http://localhost:8080/product/type/4",
"user": null
}
```
90 changes: 90 additions & 0 deletions docs/content/en/integrations/notification_webhooks/scan_added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
---
title: "Event: scan_added and scan_added_empty"
weight: 5
chapter: true
---

Event `scan_added_empty` describes a situation when reimport did not affect the existing test (no finding has been created or closed).

## Event HTTP header for scan_added
```yaml
X-DefectDojo-Event: scan_added
```

## Event HTTP header for scan_added_empty
```yaml
X-DefectDojo-Event: scan_added_empty
```

## Event HTTP body
```json
{
"description": null,
"engagement": {
"id": 7,
"name": "notif eng",
"url_api": "http://localhost:8080/api/v2/engagements/7/",
"url_ui": "http://localhost:8080/engagement/7"
},
"finding_count": 4,
"findings": {
"mitigated": [
{
"id": 233,
"severity": "Medium",
"title": "Mitigated Finding",
"url_api": "http://localhost:8080/api/v2/findings/233/",
"url_ui": "http://localhost:8080/finding/233"
}
],
"new": [
{
"id": 232,
"severity": "Critical",
"title": "New Finding",
"url_api": "http://localhost:8080/api/v2/findings/232/",
"url_ui": "http://localhost:8080/finding/232"
}
],
"reactivated": [
{
"id": 234,
"severity": "Low",
"title": "Reactivated Finding",
"url_api": "http://localhost:8080/api/v2/findings/234/",
"url_ui": "http://localhost:8080/finding/234"
}
],
"untouched": [
{
"id": 235,
"severity": "Info",
"title": "Untouched Finding",
"url_api": "http://localhost:8080/api/v2/findings/235/",
"url_ui": "http://localhost:8080/finding/235"
}
]
},
"product": {
"id": 4,
"name": "notif prod",
"url_api": "http://localhost:8080/api/v2/products/4/",
"url_ui": "http://localhost:8080/product/4"
},
"product_type": {
"id": 4,
"name": "notif prod type",
"url_api": "http://localhost:8080/api/v2/product_types/4/",
"url_ui": "http://localhost:8080/product/type/4"
},
"test": {
"id": 90,
"title": "notif test",
"url_api": "http://localhost:8080/api/v2/tests/90/",
"url_ui": "http://localhost:8080/test/90"
},
"url_api": "http://localhost:8080/api/v2/tests/90/",
"url_ui": "http://localhost:8080/test/90",
"user": null
}
```
44 changes: 44 additions & 0 deletions docs/content/en/integrations/notification_webhooks/test_added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
title: "Event: test_added"
weight: 4
chapter: true
---

## Event HTTP header
```yaml
X-DefectDojo-Event: test_added
```

## Event HTTP body
```json
{
"description": null,
"engagement": {
"id": 7,
"name": "notif eng",
"url_api": "http://localhost:8080/api/v2/engagements/7/",
"url_ui": "http://localhost:8080/engagement/7"
},
"product": {
"id": 4,
"name": "notif prod",
"url_api": "http://localhost:8080/api/v2/products/4/",
"url_ui": "http://localhost:8080/product/4"
},
"product_type": {
"id": 4,
"name": "notif prod type",
"url_api": "http://localhost:8080/api/v2/product_types/4/",
"url_ui": "http://localhost:8080/product/type/4"
},
"test": {
"id": 90,
"title": "notif test",
"url_api": "http://localhost:8080/api/v2/tests/90/",
"url_ui": "http://localhost:8080/test/90"
},
"url_api": "http://localhost:8080/api/v2/tests/90/",
"url_ui": "http://localhost:8080/test/90",
"user": null
}
```
Loading
Loading