How renatoalmeidaoliveira/nbrisk works
1. What this repo is
- nb_risk is a NetBox plugin built as a Django app.
- It extends NetBox with a risk-management domain inspired by NIST 800-30, centered on vulnerabilities, threat sources/events, controls, and risks.
2. Core domain boundary
- The main business logic lives in nb_risk/models.py and the migration history under nb_risk/migrations/.
- The repository is organized around a small set of risk entities and their relationships to NetBox assets, especially the “vulnerability assignment” concept that links vulnerabilities to objects in NetBox and to additional configured asset models.
3. NetBox integration model
- This is not a standalone app; it plugs into the existing NetBox UI and object model.
- nb_risk/template_content.py and nb_risk/navigation.py indicate that the plugin injects panels and menu entries into NetBox pages rather than replacing NetBox screens.
- The README’s PLUGINS_CONFIG['nb_risk']['additional_assets'] setting is an important architectural boundary: the plugin can be extended to support extra asset models beyond the built-in NetBox ones.
4. User-facing UI layer
- The main UI surface is Django-template based, under nb_risk/templates/nb_risk/.
- nb_risk/views.py and nb_risk/custom_views.py provide the page controllers for list/detail/edit screens.
- The templates suggest separate views for vulnerability, threat source, threat event, control, and risk pages, plus asset-specific vulnerability listings and assignment workflows.
5. Presentation helpers and page composition
- nb_risk/tables.py, nb_risk/filtersets.py, nb_risk/forms.py, and nb_risk/columns.py show a classic NetBox/Django pattern:
- filters for query narrowing,
- forms for CRUD and assignment actions,
- tables and columns for list views,
- custom page content for object detail screens.
- This layer is mostly about making the risk data browsable and editable inside NetBox.
6. REST API subsystem
- nb_risk/api/ contains serializers.py, views.py, and urls.py, so the plugin exposes a REST API in parallel with the HTML UI.
- The API is likely used for automation and bulk integration, while the UI handles interactive inspection and assignment.
7. Risk/CVE support modules
- nb_risk/cve.py and nb_risk/choices.py suggest helper logic for CVE/CVSS-related normalization and typed field choices.
- This means the plugin is not just storing arbitrary notes; it models vulnerability severity/metadata in a structured way that supports scoring and classification.
8. Model lifecycle and side effects
- nb_risk/signals.py and nb_risk/middleware.py indicate plugin-level hooks beyond simple CRUD.
- Signals likely keep derived relationships or denormalized views in sync when risk objects or assignments change.
- Middleware suggests there is some request-scoped behavior needed for the plugin’s interaction with NetBox, though the exact behavior is not visible from the tree alone.
9. Administration and internal operations
- nb_risk/admin.py registers models in the Django admin, which is usually used for operational maintenance rather than primary end-user workflows.
- nb_risk/urls.py and nb_risk/api/urls.py define the web entry points for the plugin.
- nb_risk/version.py and setup.py show it is packaged as a distributable Python package for installation into NetBox.
10. Development and deployment shape
- The develop/ directory contains Docker-based local development assets (Dockerfile, docker-compose.yml, environment/config files).
- This implies the plugin can be tested in a containerized NetBox-like environment, but production use is still as a plugin installed into an existing NetBox deployment.
11. Testing coverage
- Tests are organized by feature area: vulnerability, threatsource, vulnerabilityassignment, and some control/custom tests.
- The presence of API, filter, and view tests shows the main architectural seams are the REST layer, query/filter behavior, and page rendering.
12. How data flows through the system
- Users or API clients create vulnerabilities, threat sources/events, controls, and risks.
- Those records are linked to NetBox assets through assignment objects and configurable additional asset models.
- NetBox object pages then render plugin-injected panels and tables showing affected assets, related vulnerabilities, and risk context.
13. What to draw in an architecture diagram
- Show NetBox as the host platform.
- Inside it, show the nb_risk plugin as three major slices:
- domain models + migrations,
- UI/template/table/form/filter layers,
- REST API.
- Add external/configured NetBox models as connected asset targets, with additional_assets as the extension mechanism.
Main entry points: __init__.py nb_risk · models.py Models · nb_risk/views.py Views · api/views.py API views
Components 22
NetBox host
External platform extended by the plugin
- NetBox · Underlying NetBox application and object model
Plugin core
Domain model, lifecycle hooks, and package entry points
- nb_risk · Django plugin that adds risk management to NetBox
nb_risk/__init__.py - Models · Core risk entities and their relationships
nb_risk/models.py - Migrations · Database evolution for the risk domain
nb_risk/migrations/0001_initial.py - CVE utils · CVE and CVSS-related parsing and scoring helpers
nb_risk/cve.py - Choices · Shared field choice definitions
nb_risk/choices.py - Signals · Model side effects and relationship maintenance
nb_risk/signals.py - Middleware · Request-scoped plugin behavior
nb_risk/middleware.py
UI layer
HTML views, tables, forms, filters, and injected panels
- Views · List, detail, and edit screen controllers
nb_risk/views.py - Custom views · Nonstandard workflow and composite page logic
nb_risk/custom_views.py - Forms · CRUD and assignment form definitions
nb_risk/forms.py - Filters · Search and narrowing logic for list views
nb_risk/filtersets.py - Tables · Tabular list-view composition
nb_risk/tables.py - Columns · Custom table column definitions
nb_risk/columns.py - Panels · NetBox page content injection points
nb_risk/template_content.py - Navigation · Plugin menu and navigation entries
nb_risk/navigation.py - Templates · HTML templates for risk pages and embedded panels
nb_risk/templates/nb_risk/vulnerability.html
REST API
Automation-facing JSON API
- API views · REST resource handlers
nb_risk/api/views.py - Serializers · Object-to-JSON mapping for the REST API
nb_risk/api/serializers.py - API routes · REST API URL registration
nb_risk/api/urls.py
Connections 26
- NetBox → nb_risk: hosts · NetBox loads the plugin into its app and object model
- nb_risk → Models: defines · Core domain entities live in the plugin models
- Models → Migrations: evolves via · Schema changes are captured in migrations
- Models → CVE utils: uses · Vulnerability data is normalized and scored with CVE helpers
- Models → Choices: uses · Models share typed choice values
- Models → Signals: triggers · Model changes can emit side effects and sync relationships
- nb_risk → Middleware: loads · Plugin-level request behavior is inserted through middleware
- nb_risk → Views: exposes · Primary HTML workflow entry points
- nb_risk → Custom views: extends · Specialized workflows and composite pages
- Views → Forms: uses · Views depend on forms for CRUD and assignment actions
- Views → Filters: uses · List views narrow results through filtersets
- Views → Tables: uses · Views render tabular collections
- Tables → Columns: uses · Tables are composed from reusable columns
- Views → Templates: renders · Page controllers render Django templates
- Panels → NetBox: injects into · Panels are attached to NetBox object pages
- Navigation → NetBox: adds menu to · The plugin contributes navigation entries to NetBox
- nb_risk → Panels: registers · Plugin hooks into NetBox page composition
- nb_risk → Navigation: registers · Plugin exposes its menu structure
- nb_risk → API routes: exposes · REST API routing is part of the plugin surface
- API routes → API views: routes to · API URLs dispatch to resource views
- API views → Serializers: uses · REST views serialize and validate payloads
- API views → Models: reads/writes · API manipulates the core risk domain objects
- Views → Models: reads/writes · HTML workflows operate on the same domain models
- Templates → Models: presents · Templates show vulnerabilities, controls, risks, and assignments
- nb_risk → Package: packaged by · The plugin is distributed as a Python package
- nb_risk → Dev env: developed with · Local Docker tooling supports plugin development