This project provides an automated flow to fetch Common Vulnerabilities and Exposures (CVEs) from the NVD API using Prefect for orchestration. It integrates Pydantic for configuration management, ensuring that environment-specific settings are loaded dynamically via environment variables.
ITL.Prefect.Nist.CVE/
│ .env # Environment variables file
│ Chart.yaml # Helm chart for Kubernetes deployment
│ Dockerfile # Dockerfile for containerization
│ README.md # Project documentation
│ requirements.txt # Python dependencies
│ values.yaml # Helm values for deployment configuration
│
├───.github/
│ └───workflows/
│ └───build-and-push.yaml # GitHub Actions workflow for CI/CD
│
├───cveimporter/
│ │ main.py # Entry point for running the flow
│ │
│ └───base/
│ └───config.py # Configuration management using Pydantic
│ └───flows.py # Prefect flow orchestration
│ └───tasks.py # Prefect tasks for fetching and processing CVEs
│
└───templates/
configmap.yaml # Kubernetes ConfigMap template
job.yaml # Kubernetes Job template
_helpers.tpl # Helm helper functions
-
main.py
:
The entry point that triggers the Prefect flow when executed. It imports and runs thenvd_cve_flow
from theflows.py
module. -
base/config.py
:
This file handles the configuration of environment variables using Pydantic. It ensures that settings like API URLs are correctly loaded from the environment. The configuration structure is as follows:nvd_api_url
: URL for the NVD CVE API.prefect_api_url
: URL for the Prefect API.
These settings are pulled from an
.env
file or environment variables and validated using Pydantic'sBaseSettings
class. -
base/flows.py
:
Defines the Prefect flownvd_cve_flow
. The flow orchestrates the following steps:- Fetches CVE data from the NVD API for a specified date range.
- Processes the fetched CVE data and prints a summary of the first 5 CVEs.
-
base/tasks.py
:
Contains Prefect tasks that are used in the flow:fetch_cves_from_nvd
: Fetches CVEs from the NVD API using HTTP requests.process_cve_data
: Processes and prints key details from the fetched CVE data.
-
templates/
:
Helm templates for Kubernetes deployment, including ConfigMaps, Jobs, and Helm helpers for managing configurations.
The project uses Pydantic's BaseSettings
for managing configuration, making it easier to handle environment-specific settings like API URLs. Pydantic automatically loads these values from environment variables or an .env
file.
Here's an example of the .env
file required to run the project:
NVD_API_URL=https://services.nvd.nist.gov/rest/json/cves/2.0
PREFECT_API_URL=http://your-prefect-server-url
The configuration is defined in base/config.py
:
from pydantic import BaseSettings, Field
class Settings(BaseSettings):
nvd_api_url: str = Field(..., env="NVD_API_URL")
prefect_api_url: str = Field(..., env="PREFECT_API_URL")
class Config:
env_file = ".env"
settings = Settings()
- Python 3.9+
- Docker (if running in containers)
- Prefect (local agent or Prefect Cloud)
- Environment variables set up in an
.env
file
-
Clone the repository:
git clone https://github.com/yourusername/ITL.Prefect.Nist.CVE.git cd ITL.Prefect.Nist.CVE
-
Install dependencies:
pip install -r requirements.txt
-
Create the
.env
file:echo "NVD_API_URL=https://services.nvd.nist.gov/rest/json/cves/2.0" > .env echo "PREFECT_API_URL=http://your-prefect-server-url" >> .env
To run the flow locally, execute the following command:
python cveimporter/main.py
The flow will fetch CVE data from the NVD API for the current day and process the results, printing the details of the first 5 CVEs.
The project includes a GitHub Actions workflow (.github/workflows/build-and-push.yaml
) for automating builds and pushing Docker images. The workflow can be triggered on code push or pull request events and handles the following steps:
- Build the Docker image.
- Push the image to a container registry (e.g., DockerHub).
This project can be deployed to a Kubernetes cluster using Helm. The Helm chart (Chart.yaml
) and values configuration (values.yaml
) allow you to define various deployment configurations like API URLs and resource limits.
-
Package the Helm chart:
helm package .
-
Install the chart in your Kubernetes cluster:
helm install itl-cve-importer ./itl-prefect-nist-cve
- Logging: Add proper logging instead of
print
statements for better observability. - Error Handling: Implement retries for API requests and better error handling.
- Data Storage: Store CVE data in a database or a file system for long-term analysis.