From 48ed7835ab6e08e3ee888d28e0a4530b734e28c8 Mon Sep 17 00:00:00 2001 From: Renato Almeida de Oliveira Date: Sun, 20 Aug 2023 02:31:07 +0000 Subject: [PATCH] Fixes #20, #22, Add changelog file, Add case sensitive constrain to vulnerability names --- CHANGELOG.md | 6 +++++ Makefile | 2 +- README.md | 12 ++++++---- develop/Dockerfile | 2 +- .../0005_alter_vulnerability_cvssbasescore.py | 18 +++++++++++++++ .../0006_vulnerability_unique_vuln_name.py | 17 ++++++++++++++ ...vulnerability_unique_vuln_name_and_more.py | 22 +++++++++++++++++++ nb_risk/models.py | 9 +++++++- nb_risk/template_content.py | 3 ++- nb_risk/version.py | 2 +- nb_risk/views.py | 2 +- 11 files changed, 85 insertions(+), 10 deletions(-) create mode 100644 CHANGELOG.md create mode 100644 nb_risk/migrations/0005_alter_vulnerability_cvssbasescore.py create mode 100644 nb_risk/migrations/0006_vulnerability_unique_vuln_name.py create mode 100644 nb_risk/migrations/0007_remove_vulnerability_unique_vuln_name_and_more.py diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..9da7acf --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,6 @@ +# Changelog + +## 35.1.0 (18/08/2023) + +* Add case sensitive name constrain to Vulnerability model +* Change the import path of get_plugin_config() to extras.plugins.utils [13368](https://github.com/netbox-community/netbox/commit/f5a1f83f9fa9d98c945d21eb0f7ccb8cd37fbf59) \ No newline at end of file diff --git a/Makefile b/Makefile index a0d2303..298dd3e 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ PYTHON_VER?=3.10 -NETBOX_VER?=v3.5.1 +NETBOX_VER?=v3.5.8 COMPOSE_FILE=./develop/docker-compose.yml diff --git a/README.md b/README.md index 45d7c83..b5d23f1 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ ## Netbox Nbrisk -[Netbox](https://github.com/netbox-community/netbox) Plugin inspired in NIST 800-30 Risk Management **BETA VERSION** +[Netbox](https://github.com/netbox-community/netbox) Plugin inspired in NIST 800-30 Risk Management ## Compatibility @@ -13,11 +13,15 @@ To ensure NBRisk plugin is automatically re-installed during future upgrades, cr ### For NetBox 3.4.x ```shell -# echo "NbRisk==^34.0.0" >> local_requirements.txt +# echo "NbRisk==34.*" >> local_requirements.txt ``` -### For NetBox 3.5.x +### For NetBox 3.5.0 to 3.5.7 ```shell -# echo "NbRisk==^35.0.0" >> local_requirements.txt +# echo "NbRisk==35.0.*" >> local_requirements.txt +``` +### For NetBox 3.5.8 or grater +```shell +# echo "NbRisk==35.1.*" >> local_requirements.txt ``` Once installed, the plugin needs to be enabled in your configuration.py diff --git a/develop/Dockerfile b/develop/Dockerfile index 2383f70..541c120 100644 --- a/develop/Dockerfile +++ b/develop/Dockerfile @@ -1,7 +1,7 @@ ARG python_ver=3.10 FROM python:${python_ver} -ARG netbox_ver=v3.5.1 +ARG netbox_ver=v3.5.8 ENV PYTHONUNBUFFERED 1 RUN mkdir -p /opt diff --git a/nb_risk/migrations/0005_alter_vulnerability_cvssbasescore.py b/nb_risk/migrations/0005_alter_vulnerability_cvssbasescore.py new file mode 100644 index 0000000..84bce66 --- /dev/null +++ b/nb_risk/migrations/0005_alter_vulnerability_cvssbasescore.py @@ -0,0 +1,18 @@ +# Generated by Django 4.1.9 on 2023-05-13 16:13 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('nb_risk', '0004_alter_vulnerability_options'), + ] + + operations = [ + migrations.AlterField( + model_name='vulnerability', + name='cvssbaseScore', + field=models.FloatField(blank=True, max_length=100, null=True), + ), + ] diff --git a/nb_risk/migrations/0006_vulnerability_unique_vuln_name.py b/nb_risk/migrations/0006_vulnerability_unique_vuln_name.py new file mode 100644 index 0000000..bb39325 --- /dev/null +++ b/nb_risk/migrations/0006_vulnerability_unique_vuln_name.py @@ -0,0 +1,17 @@ +# Generated by Django 4.1.9 on 2023-05-13 17:11 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('nb_risk', '0005_alter_vulnerability_cvssbasescore'), + ] + + operations = [ + migrations.AddConstraint( + model_name='vulnerability', + constraint=models.UniqueConstraint(fields=('name',), name='unique_vuln_name'), + ), + ] diff --git a/nb_risk/migrations/0007_remove_vulnerability_unique_vuln_name_and_more.py b/nb_risk/migrations/0007_remove_vulnerability_unique_vuln_name_and_more.py new file mode 100644 index 0000000..44af21c --- /dev/null +++ b/nb_risk/migrations/0007_remove_vulnerability_unique_vuln_name_and_more.py @@ -0,0 +1,22 @@ +# Generated by Django 4.1.10 on 2023-08-20 02:18 + +from django.db import migrations, models +import django.db.models.functions.text + + +class Migration(migrations.Migration): + + dependencies = [ + ('nb_risk', '0006_vulnerability_unique_vuln_name'), + ] + + operations = [ + migrations.RemoveConstraint( + model_name='vulnerability', + name='unique_vuln_name', + ), + migrations.AddConstraint( + model_name='vulnerability', + constraint=models.UniqueConstraint(django.db.models.functions.text.Lower('name'), name='unique_vuln_name'), + ), + ] diff --git a/nb_risk/models.py b/nb_risk/models.py index b11334b..0e64de4 100644 --- a/nb_risk/models.py +++ b/nb_risk/models.py @@ -2,6 +2,7 @@ from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.fields import GenericForeignKey from django.urls import reverse +from django.db.models.functions import Lower from netbox.models import NetBoxModel from . import choices @@ -63,7 +64,7 @@ class Vulnerability(NetBoxModel): cvssavailabilityImpact = models.CharField( "Availability Impact (A)", max_length=100, blank=True ) - cvssbaseScore = models.FloatField("Base Score", max_length=100, blank=True) + cvssbaseScore = models.FloatField("Base Score", max_length=100, blank=True, null=True,) def affected_assets(self): return self.vulnerability_assignments.count() @@ -77,6 +78,12 @@ def get_absolute_url(self): class Meta: verbose_name = "Vulnerability" verbose_name_plural = "Vulnerabilities" + constraints = ( + models.UniqueConstraint( + Lower('name'), + name="unique_vuln_name" + ), + ) # VulnearbilityAssingment Model diff --git a/nb_risk/template_content.py b/nb_risk/template_content.py index 99aca57..f85c125 100644 --- a/nb_risk/template_content.py +++ b/nb_risk/template_content.py @@ -1,4 +1,5 @@ -from extras.plugins import PluginTemplateExtension, get_plugin_config +from extras.plugins import PluginTemplateExtension +from extras.plugins.utils import get_plugin_config from django.conf import settings from packaging import version diff --git a/nb_risk/version.py b/nb_risk/version.py index ccea7eb..1a9c569 100644 --- a/nb_risk/version.py +++ b/nb_risk/version.py @@ -1 +1 @@ -__version__ = "35.0.2" +__version__ = "35.1.0" diff --git a/nb_risk/views.py b/nb_risk/views.py index 65b56df..1595f1b 100644 --- a/nb_risk/views.py +++ b/nb_risk/views.py @@ -3,7 +3,7 @@ from tenancy.models import Tenant from virtualization.models import VirtualMachine -from extras.plugins import get_plugin_config +from extras.plugins.utils import get_plugin_config from utilities.views import ViewTab, register_model_view from django.contrib.contenttypes.models import ContentType from django.shortcuts import get_object_or_404