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

App nist CVE sync3.0 #391

Open
wants to merge 32 commits into
base: next3.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
c87ed36
Adding the new NIST CVE Tracking feature for 3.x release.
bminnix Jun 4, 2024
93eea4e
Apply suggestions from code review
bminnix Aug 12, 2024
a8b621a
Updating a couple of things for linting before moving on to other rec…
bminnix Aug 12, 2024
6f015d3
Pinning django-debug-toolbar to <4.4, seems to be what's causing an i…
bminnix Aug 12, 2024
757bb25
Adding the new NIST CVE Tracking feature for 3.x release.
bminnix Jun 4, 2024
c7dc2cb
Apply suggestions from code review
bminnix Aug 12, 2024
f2bfc15
Updating a couple of things for linting before moving on to other rec…
bminnix Aug 12, 2024
3703449
Pinning django-debug-toolbar to <4.4, seems to be what's causing an i…
bminnix Aug 12, 2024
d1fbff2
After the rebase from next3.0, delete and regenerate of migration file.
bminnix Nov 14, 2024
864e229
Updating signals and tracking for ExternalIntegration updates
bminnix Nov 27, 2024
b32a4e1
Required to update the lock file
bminnix Nov 27, 2024
50beb91
Fixing things the tests yelled about.
bminnix Nov 27, 2024
ee77748
Moving init logic into run. Not able to access db items in job init.
bminnix Nov 28, 2024
b56f80d
Regenerated the migration file because it was causing an issue on che…
bminnix Nov 28, 2024
e164a02
Checked out the migrations directory from next3.0 then ran makemigrat…
bminnix Nov 28, 2024
a360874
Added several things including ExternalIntegration, SecretsGroup, Sec…
bminnix Nov 29, 2024
33239fe
Issue with one of the migrated files after I let it get ruffed up.
bminnix Nov 29, 2024
40d4e0d
Update nautobot_device_lifecycle_mgmt/jobs/cve_tracking.py
bminnix Nov 29, 2024
bf8ef5a
Update nautobot_device_lifecycle_mgmt/jobs/cve_tracking.py
bminnix Nov 29, 2024
5ab3ab0
Removed the create_cpe_software_search_urls as recommended and moved …
bminnix Nov 29, 2024
eee6a8e
Updated all calls to use the software object instead of passing softw…
bminnix Nov 29, 2024
20ac571
Updating documentation for use with External Integration selection, a…
bminnix Nov 29, 2024
5952cb3
Realized there were a couple more requested changes that were hidden …
bminnix Nov 29, 2024
e66dea0
Still had a continue that needed to be removed.
bminnix Nov 29, 2024
e6c96d0
Saw a bit of missing instruction in the user doc regarding the secret.
bminnix Dec 2, 2024
fed96c6
Updating to only leave a couple of the retry options configurable.
bminnix Dec 3, 2024
7dddd0e
Fixed files with ruff
bminnix Dec 3, 2024
0089be4
Issues running tests. Updated the tasks.py for ruff, based on dev-ex…
bminnix Dec 3, 2024
222a473
Updated the query_api method to Open, retrieve, and Close the session…
bminnix Dec 5, 2024
153d0f7
Updating some code for readability and catching a known possible exce…
bminnix Dec 5, 2024
74a1cc5
Had an unnecessary else
bminnix Dec 5, 2024
07806b9
Updated logger statement
bminnix Dec 5, 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
Binary file added docs/images/lcm_cve_nist_job.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/lcm_cve_nist_job_log.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/lcm_cve_nist_job_run.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 42 additions & 2 deletions docs/user/cve_tracking.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,20 @@ When creating a CVE object, the following fields are available. Fields in **bold
| Fix | The software fix (if available) for the CVE |
| Comments | Any additional comments or details about the CVE |
| Tags | Arbitrary [tag objects](https://docs.nautobot.com/projects/core/en/stable/models/extras/tag/) that can be applied to this CVE |
| Last Modified Date | The date that the CVE record was last modified |

!!! note
In addition to these standard fields, you can also add one or more [Custom Fields](https://docs.nautobot.com/projects/core/en/stable/models/extras/customfield/) to the model.

### Software Association

As stated previously, you can associate a CVE to one or many [Software objects](./software_lifecycle.md#software-objects). These relationships will present themselves as breadcrumb links on each item's detail view.
As stated previously, you can associate a CVE to one or many [Software objects](./software_lifecycle.md#software-objects). These relationships will present themselves as breadcrumb links on the CVE item's detail view, and as the "Related CVEs" tab on the Software item's detail view.

Example of a breadcrumb link on a CVE item's view:

![](../images/lcm_cve_breadcrumb.png)

Example of a breadcrumb link on a Software item's view:
Example of the "Related CVEs" tab on a Software item's view:

![](../images/lcm_software_breadcrumb.png)

Expand All @@ -60,3 +61,42 @@ After a Vulnerability object has been generated, the CVE, Software, Device and I
In addition to these standard fields, you can also add one or more [Custom Fields](https://docs.nautobot.com/projects/core/en/stable/models/extras/customfield/) to the model.

As was stated previously, running the ``Generate Vulnerabilities`` Job will not modify (or delete) any existing Vulnerability objects - **even if the associations that existed previously no longer exist**. You do have the ability to delete one or more Vulnerability objects via the GUI or API. In addition to manually removing a Vulnerability, if any CVE, Software, Device or Inventory Item objects are removed, any Vulnerability objects that reference the deleted items will also be removed automatically.

## Automated CVE Discovery via NIST API 2.0
The NTC Nautobot Device Lifecycle Management app now supports automated CVE discovery via the NIST NVD API 2.0. This feature is optional and can be enabled by obtaining an API key, updating the necessary Secret, and running the ``NIST - Software CVE Search`` Job. Continue reading for more information.

### External Integration
An External Integration must be created and configured in order to use the NIST NVD API for automatic software CVE discovery. On this note, the following is installed for you:

- A new External Integration object named ``NAUTOBOT DLM NIST EXTERNAL INTEGRATION`` that allows you to control the following behaviors of the integration:
- ``api_call_delay``: A delay between API calls in seconds (default: 6). NIST Recommends a minimum value of 6 to prevent overloading resources.
- ``retries``: Even with using a delay, the NIST API may return a 500 error. The settings in this dictionary allows you to control the number of retries and backoff.
- ``max_attempts``: The maximum number of retry attempts (default: 3).
- ``backoff``: The backoff factor for the retry attempts (default: 2). This is the multiplier for the delay between retries.
- A new Secrets Group object named ``NAUTOBOT DLM NIST SECRETS GROUP`` used for access to the NIST API Key from the External Integration.
- A new Secret object named ``NAUTOBOT DLM NIST API KEY``. This object is created for you during setup with minimum defaults. The Secret name must be exactly as above, but you will need to configure the Secret to properly access the NIST API Key.
- To obtain your NIST API Key go [here]('https://nvd.nist.gov/developers/request-an-api-key').

NOTE: You may change the name of the External Integration or create your own using other configuration settings, but the SecretsGroup and Secret objects must be named as above. The External Integration is selected when starting the Job run.


### Run Job
Automated discovery is used by running the ``NIST - Software CVE Search`` Job.

To run this job, use the "Jobs" menu dropdown and navigate to the **CVE Tracking** section. The jobs will appear here and all you will need to do is click the play button in order to use the default External Integration[^1]. If you have configured additional Integrations, you may select the External Integration that you want to use. **As stated previously, the name of the External Integration does not matter, but the External Integration must contain a SecretsGroup and Secret named as above**.

![](../images/lcm_cve_nist_job.png)

![](../images/lcm_cve_nist_job_run.png)

The job output should indicate the softwares checked and the amount of CVEs received for that software, as well as the amount of CVEs created. These will not always be the same. New CVE will be created for software with existing CVE, also software will share CVEs.

![](../images/lcm_cve_nist_job_log.png)

[^1] Warning: If play button is grayed out. You will need to enable the job by clicking on edit button in the row and navigate to "Job" portion and click on "Enable"


### Additional Notes:
Due to the way vendor platform entries vary in NIST, some platforms may work without issue, others may not work so well (false positives/negatives). Juniper JunOS is a great example and has a custom parser in netutils to handle this.

If the platform you are attempting to gather information from does not work, a custom parser will likely be needed to build a proper NIST search URL.
4 changes: 4 additions & 0 deletions nautobot_device_lifecycle_mgmt/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,10 @@ class CVELCMFilterSet(NautobotFilterSet, StatusModelFilterSetMixin): # , Custom
published_date__gte = django_filters.DateFilter(field_name="published_date", lookup_expr="gte")
published_date__lte = django_filters.DateFilter(field_name="published_date", lookup_expr="lte")

last_modified_date = django_filters.DateTimeFromToRangeFilter()
last_modified_date__gte = django_filters.DateFilter(field_name="last_modified_date", lookup_expr="gte")
last_modified_date__lte = django_filters.DateFilter(field_name="last_modified_date", lookup_expr="lte")

cvss__gte = django_filters.NumberFilter(field_name="cvss", lookup_expr="gte")
cvss__lte = django_filters.NumberFilter(field_name="cvss", lookup_expr="lte")

Expand Down
7 changes: 7 additions & 0 deletions nautobot_device_lifecycle_mgmt/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,7 @@ class CVELCMForm(NautobotModelForm):
"""CVE Lifecycle Management creation/edit form."""

published_date = forms.DateField(widget=DatePicker())
last_modified_date = forms.DateField(widget=DatePicker(), required=False)
severity = forms.ChoiceField(choices=CVESeverityChoices.CHOICES, label="Severity", required=False)
tags = DynamicModelMultipleChoiceField(queryset=Tag.objects.all(), required=False)
affected_softwares = DynamicModelMultipleChoiceField(queryset=SoftwareVersion.objects.all(), required=False)
Expand All @@ -679,6 +680,7 @@ class Meta:

widgets = {
"published_date": DatePicker(),
"last_modified_date": DatePicker(),
}


Expand Down Expand Up @@ -722,6 +724,9 @@ class CVELCMFilterForm(NautobotFilterForm):
published_date_before = forms.DateField(label="Published Date Before", required=False, widget=DatePicker())
published_date_after = forms.DateField(label="Published Date After", required=False, widget=DatePicker())

last_modified_date_before = forms.DateField(label="Last Modified Date Before", required=False, widget=DatePicker())
last_modified_date_after = forms.DateField(label="Last Modified Date After", required=False, widget=DatePicker())

cvss__gte = forms.FloatField(label="CVSS Score Above", required=False)
cvss__lte = forms.FloatField(label="CVSS Score Below", required=False)

Expand Down Expand Up @@ -755,6 +760,8 @@ class Meta:
"q",
"published_date_before",
"published_date_after",
"last_modified_date_before",
"last_modified_date_after",
"severity",
"status",
"affected_softwares",
Expand Down
3 changes: 2 additions & 1 deletion nautobot_device_lifecycle_mgmt/jobs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from nautobot.core.celery import register_jobs

from .cve_tracking import GenerateVulnerabilities
from .cve_tracking import GenerateVulnerabilities, NistCveSyncSoftware
from .lifecycle_reporting import (
DeviceHardwareNoticeFullReport,
DeviceSoftwareValidationFullReport,
Expand All @@ -14,5 +14,6 @@
DeviceSoftwareValidationFullReport,
InventoryItemSoftwareValidationFullReport,
GenerateVulnerabilities,
NistCveSyncSoftware,
]
register_jobs(*jobs)
Loading