Skip to content

Commit 53bb5af

Browse files
MrCloudSecandoniaf
andauthored
feat(llm): add LLM provider (#8555)
Co-authored-by: Andoni A. <14891798+andoniaf@users.noreply.github.com>
1 parent 52a5fff commit 53bb5af

File tree

25 files changed

+175953
-15
lines changed

25 files changed

+175953
-15
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ repos:
66
- id: check-merge-conflict
77
- id: check-yaml
88
args: ["--unsafe"]
9+
exclude: prowler/config/llm_config.yaml
910
- id: check-json
1011
- id: end-of-file-fixer
1112
- id: trailing-whitespace

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ prowler dashboard
9090
| M365 | 70 | 7 | 3 | 2 | Official | Stable | UI, API, CLI |
9191
| IaC | [See `trivy` docs.](https://trivy.dev/latest/docs/coverage/iac/) | N/A | N/A | N/A | Official | Beta | CLI |
9292
| MongoDB Atlas | 10 | 3 | 0 | 0 | Official | Beta | CLI |
93+
| LLM | [See `promptfoo` docs.](https://www.promptfoo.dev/docs/red-team/plugins/) | N/A | N/A | N/A | Official | Beta | CLI |
9394
| NHN | 6 | 2 | 1 | 0 | Unofficial | Beta | CLI |
9495

9596
> [!Note]
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# LLM Provider
2+
3+
This page details the [Large Language Model (LLM)](https://en.wikipedia.org/wiki/Large_language_model) provider implementation in Prowler.
4+
5+
The LLM provider enables security testing of language models using red team techniques. By default, Prowler uses the built-in LLM configuration that targets OpenAI models with comprehensive security test suites. To configure it, follow the [LLM getting started guide](../tutorials/llm/getting-started-llm.md).
6+
7+
## LLM Provider Classes Architecture
8+
9+
The LLM provider implementation follows the general [Provider structure](./provider.md). This section focuses on the LLM-specific implementation, highlighting how the generic provider concepts are realized for LLM security testing in Prowler. For a full overview of the provider pattern, base classes, and extension guidelines, see [Provider documentation](./provider.md).
10+
11+
### Main Class
12+
13+
- **Location:** [`prowler/providers/llm/llm_provider.py`](https://github.com/prowler-cloud/prowler/blob/master/prowler/providers/llm/llm_provider.py)
14+
- **Base Class:** Inherits from `Provider` (see [base class details](https://github.com/prowler-cloud/prowler/blob/master/prowler/providers/common/provider.py)).
15+
- **Purpose:** Central orchestrator for LLM-specific logic, configuration management, and integration with promptfoo for red team testing.
16+
- **Key LLM Responsibilities:**
17+
- Initializes and manages LLM configuration using promptfoo.
18+
- Validates configuration and sets up the LLM testing context.
19+
- Loads and manages red team test configuration, plugins, and target models.
20+
- Provides properties and methods for downstream LLM security testing.
21+
- Integrates with promptfoo for comprehensive LLM security evaluation.
22+
23+
### Data Models
24+
25+
- **Location:** [`prowler/providers/llm/models.py`](https://github.com/prowler-cloud/prowler/blob/master/prowler/providers/llm/models.py)
26+
- **Purpose:** Define structured data for LLM output options and configuration.
27+
- **Key LLM Models:**
28+
- `LLMOutputOptions`: Customizes output filename logic for LLM-specific reporting.
29+
30+
### LLM Security Testing Integration
31+
32+
- **Location:** [`prowler/providers/llm/llm_provider.py`](https://github.com/prowler-cloud/prowler/blob/master/prowler/providers/llm/llm_provider.py)
33+
- **Purpose:** Integrates with promptfoo for comprehensive LLM security testing.
34+
- **Key LLM Responsibilities:**
35+
- Executes promptfoo red team evaluations against target LLMs.
36+
- Processes security test results and converts them to Prowler reports.
37+
- Manages test concurrency and progress tracking.
38+
- Handles real-time streaming of test results.
39+
40+
### Configuration Management
41+
42+
The LLM provider uses promptfoo configuration files to define:
43+
44+
- **Target Models**: The LLM models to test (e.g., OpenAI GPT, Anthropic Claude)
45+
- **Red Team Plugins**: Security test suites (OWASP, MITRE, NIST, EU AI Act)
46+
- **Test Parameters**: Concurrency, test counts, and evaluation criteria
47+
48+
### Default Configuration
49+
50+
Prowler includes a comprehensive default LLM configuration that:
51+
52+
- Targets OpenAI models by default
53+
- Includes multiple security test frameworks (OWASP, MITRE, NIST, EU AI Act)
54+
- Provides extensive test coverage for LLM security vulnerabilities
55+
- Supports custom configuration for specific testing needs
56+
57+
## Specific Patterns in LLM Security Testing
58+
59+
The LLM provider implements security testing through integration with promptfoo, following these patterns:
60+
61+
### Red Team Testing Framework
62+
63+
- **Plugin-based Architecture**: Uses promptfoo plugins for different security test categories
64+
- **Comprehensive Coverage**: Includes OWASP LLM Top 10, MITRE ATLAS, NIST AI Risk Management, and EU AI Act compliance
65+
- **Real-Time Evaluation**: Streams test results as they are generated
66+
- **Progress Tracking**: Provides detailed progress information during test execution
67+
68+
### Test Execution Flow
69+
70+
1. **Configuration Loading**: Loads promptfoo configuration with target models and test plugins
71+
2. **Test Generation**: Generates security test cases based on configured plugins
72+
3. **Concurrent Execution**: Runs tests with configurable concurrency limits
73+
4. **Result Processing**: Converts promptfoo results to Prowler security reports
74+
5. **Progress Monitoring**: Tracks and displays test execution progress
75+
76+
### Security Test Categories
77+
78+
The LLM provider supports comprehensive security testing across multiple frameworks:
79+
80+
- **OWASP LLM Top 10**: Covers prompt injection, data leakage, and model security
81+
- **MITRE ATLAS**: Adversarial threat landscape for AI systems
82+
- **NIST AI Risk Management**: AI system risk assessment and mitigation
83+
- **EU AI Act**: European Union AI regulation compliance
84+
- **Custom Tests**: Support for organization-specific security requirements
85+
86+
## Error Handling and Validation
87+
88+
The LLM provider includes comprehensive error handling for:
89+
90+
- **Configuration Validation**: Ensures valid promptfoo configuration files
91+
- **Model Access**: Handles authentication and access issues with target LLMs
92+
- **Test Execution**: Manages test failures and timeout scenarios
93+
- **Result Processing**: Handles malformed or incomplete test results
94+
95+
## Integration with Prowler Ecosystem
96+
97+
The LLM provider seamlessly integrates with Prowler's existing infrastructure:
98+
99+
- **Output Formats**: Supports all Prowler output formats (JSON, CSV, HTML, etc.)
100+
- **Compliance Frameworks**: Integrates with Prowler's compliance reporting
101+
- **Fixer Integration**: Supports automated remediation recommendations
102+
- **Dashboard Integration**: Compatible with Prowler App for centralized management

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ The official supported providers right now are:
1414
| **Github** | Official | Stable | UI, API, CLI |
1515
| **IaC** | Official | Beta | CLI |
1616
| **MongoDB Atlas** | Official | Beta | CLI |
17+
| **LLM** | Official | Beta | CLI |
1718
| **NHN** | Unofficial | Beta | CLI |
1819

1920
Prowler supports **auditing, incident response, continuous monitoring, hardening, forensic readiness, and remediation**.
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# Getting Started With LLM on Prowler
2+
3+
## Overview
4+
5+
Prowler's LLM provider enables comprehensive security testing of large language models using red team techniques. It integrates with [promptfoo](https://promptfoo.dev/) to provide extensive security evaluation capabilities.
6+
7+
## Prerequisites
8+
9+
Before using the LLM provider, ensure the following requirements are met:
10+
11+
- **promptfoo installed**: The LLM provider requires promptfoo to be installed on the system
12+
- **LLM API access**: Valid API keys for the target LLM models to test
13+
- **Email verification**: promptfoo requires email verification for red team evaluations
14+
15+
## Installation
16+
17+
### Install promptfoo
18+
19+
Install promptfoo using one of the following methods:
20+
21+
**Using npm:**
22+
```bash
23+
npm install -g promptfoo
24+
```
25+
26+
**Using Homebrew (macOS):**
27+
```bash
28+
brew install promptfoo
29+
```
30+
31+
**Using other package managers:**
32+
See the [promptfoo installation guide](https://promptfoo.dev/docs/installation/) for additional installation methods.
33+
34+
### Verify Installation
35+
36+
```bash
37+
promptfoo --version
38+
```
39+
40+
## Configuration
41+
42+
### Step 1: Email Verification
43+
44+
promptfoo requires email verification for red team evaluations. Set the email address:
45+
46+
```bash
47+
promptfoo config set email your-email@company.com
48+
```
49+
50+
### Step 2: Configure LLM API Keys
51+
52+
Set up API keys for the target LLM models. For OpenAI (default configuration):
53+
54+
```bash
55+
export OPENAI_API_KEY="your-openai-api-key"
56+
```
57+
58+
For other providers, see the [promptfoo documentation](https://promptfoo.dev/docs/providers/) for specific configuration requirements.
59+
60+
### Step 3: Generate Test Cases (Optional)
61+
62+
Prowler provides a default suite of red team tests but to customize the test cases, generate them first:
63+
64+
```bash
65+
promptfoo redteam generate
66+
```
67+
68+
This creates test cases based on your configuration.
69+
70+
## Usage
71+
72+
### Basic Usage
73+
74+
Run LLM security testing with the default configuration:
75+
76+
```bash
77+
prowler llm
78+
```
79+
80+
### Custom Configuration
81+
82+
Use a custom promptfoo configuration file:
83+
84+
```bash
85+
prowler llm --config-path /path/to/your/config.yaml
86+
```
87+
88+
### Output Options
89+
90+
Generate reports in various formats:
91+
92+
```bash
93+
# JSON output
94+
prowler llm --output-format json
95+
96+
# CSV output
97+
prowler llm --output-format csv
98+
99+
# HTML report
100+
prowler llm --output-format html
101+
```
102+
103+
### Concurrency Control
104+
105+
Adjust the number of concurrent tests:
106+
107+
```bash
108+
prowler llm --max-concurrency 5
109+
```
110+
111+
## Default Configuration
112+
113+
Prowler includes a comprehensive default LLM configuration that provides:
114+
115+
- **Target Models**: OpenAI GPT models by default
116+
- **Security Frameworks**:
117+
- OWASP LLM Top 10
118+
- OWASP API Top 10
119+
- MITRE ATLAS
120+
- NIST AI Risk Management Framework
121+
- EU AI Act compliance
122+
- **Test Coverage**: Over 5,000 security test cases
123+
- **Plugin Support**: Multiple security testing plugins
124+
125+
## Advanced Configuration
126+
127+
### Custom Test Suites
128+
129+
Create custom test configurations by modifying the promptfoo config file in `prowler/config/llm_config.yaml` or pass a custom configuration with `--config-file` flag:
130+
131+
```yaml
132+
description: Custom LLM Security Tests
133+
targets:
134+
- id: openai:gpt-4
135+
redteam:
136+
plugins:
137+
- id: owasp:llm
138+
numTests: 10
139+
- id: mitre:atlas
140+
numTests: 5
141+
```
142+

mkdocs.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ nav:
138138
- MongoDB Atlas:
139139
- Getting Started: tutorials/mongodbatlas/getting-started-mongodbatlas.md
140140
- Authentication: tutorials/mongodbatlas/authentication.md
141-
141+
- LLM:
142+
- Getting Started: tutorials/llm/getting-started-llm.md
142143
- Compliance:
143144
- ThreatScore: tutorials/compliance/threatscore.md
144145

@@ -159,6 +160,7 @@ nav:
159160
- Kubernetes: developer-guide/kubernetes-details.md
160161
- Microsoft 365: developer-guide/m365-details.md
161162
- GitHub: developer-guide/github-details.md
163+
- LLM: developer-guide/llm-details.md
162164
- Miscellaneous:
163165
- Documentation: developer-guide/documentation.md
164166
- Testing:

prowler/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ All notable changes to the **Prowler SDK** are documented in this file.
77
### Added
88
- Support for AdditionalURLs in outputs [(#8651)](https://github.com/prowler-cloud/prowler/pull/8651)
99
- Support for markdown metadata fields in Dashboard [(#8667)](https://github.com/prowler-cloud/prowler/pull/8667)
10+
- LLM provider using `promptfoo` [(#8555)](https://github.com/prowler-cloud/prowler/pull/8555)
1011
- Documentation for renaming checks [(#8717)](https://github.com/prowler-cloud/prowler/pull/8717)
1112
- Add explicit "name" field for each compliance framework and include "FRAMEWORK" and "NAME" in CSV output [(#7920)](https://github.com/prowler-cloud/prowler/pull/7920)
1213

prowler/__main__.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
from prowler.lib.outputs.finding import Finding
9090
from prowler.lib.outputs.html.html import HTML
9191
from prowler.lib.outputs.ocsf.ocsf import OCSF
92-
from prowler.lib.outputs.outputs import extract_findings_statistics
92+
from prowler.lib.outputs.outputs import extract_findings_statistics, report
9393
from prowler.lib.outputs.slack.slack import Slack
9494
from prowler.lib.outputs.summary_table import display_summary_table
9595
from prowler.providers.aws.lib.s3.s3 import S3
@@ -102,6 +102,7 @@
102102
from prowler.providers.github.models import GithubOutputOptions
103103
from prowler.providers.iac.models import IACOutputOptions
104104
from prowler.providers.kubernetes.models import KubernetesOutputOptions
105+
from prowler.providers.llm.models import LLMOutputOptions
105106
from prowler.providers.m365.models import M365OutputOptions
106107
from prowler.providers.mongodbatlas.models import MongoDBAtlasOutputOptions
107108
from prowler.providers.nhn.models import NHNOutputOptions
@@ -180,8 +181,8 @@ def prowler():
180181
# Load compliance frameworks
181182
logger.debug("Loading compliance frameworks from .json files")
182183

183-
# Skip compliance frameworks for IAC provider
184-
if provider != "iac":
184+
# Skip compliance frameworks for IAC and LLM providers
185+
if provider != "iac" and provider != "llm":
185186
bulk_compliance_frameworks = Compliance.get_bulk(provider)
186187
# Complete checks metadata with the compliance framework specification
187188
bulk_checks_metadata = update_checks_metadata_with_compliance(
@@ -238,8 +239,8 @@ def prowler():
238239
if not args.only_logs:
239240
global_provider.print_credentials()
240241

241-
# Skip service and check loading for IAC provider
242-
if provider != "iac":
242+
# Skip service and check loading for IAC and LLM providers
243+
if provider != "iac" and provider != "llm":
243244
# Import custom checks from folder
244245
if checks_folder:
245246
custom_checks = parse_checks_from_folder(global_provider, checks_folder)
@@ -322,6 +323,8 @@ def prowler():
322323
)
323324
elif provider == "iac":
324325
output_options = IACOutputOptions(args, bulk_checks_metadata)
326+
elif provider == "llm":
327+
output_options = LLMOutputOptions(args, bulk_checks_metadata)
325328

326329
# Run the quick inventory for the provider if available
327330
if hasattr(args, "quick_inventory") and args.quick_inventory:
@@ -331,9 +334,20 @@ def prowler():
331334
# Execute checks
332335
findings = []
333336

334-
if provider == "iac":
335-
# For IAC provider, run the scan directly
336-
findings = global_provider.run()
337+
if provider == "iac" or provider == "llm":
338+
# For IAC and LLM providers, run the scan directly
339+
if provider == "llm":
340+
341+
def streaming_callback(findings_batch):
342+
"""Callback to report findings as they are processed in real-time."""
343+
report(findings_batch, global_provider, output_options)
344+
345+
findings = global_provider.run_scan(streaming_callback=streaming_callback)
346+
else:
347+
# Original behavior for IAC or non-verbose LLM
348+
findings = global_provider.run()
349+
# Report findings for verbose output
350+
report(findings, global_provider, output_options)
337351
elif len(checks_to_execute):
338352
findings = execute_checks(
339353
checks_to_execute,

prowler/compliance/llm/__init__.py

Whitespace-only changes.

prowler/config/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ def get_available_compliance_frameworks(provider=None):
7676
default_fixer_config_file_path = (
7777
f"{pathlib.Path(os.path.dirname(os.path.realpath(__file__)))}/fixer_config.yaml"
7878
)
79+
default_redteam_config_file_path = (
80+
f"{pathlib.Path(os.path.dirname(os.path.realpath(__file__)))}/llm_config.yaml"
81+
)
7982
encoding_format_utf_8 = "utf-8"
8083
available_output_formats = ["csv", "json-asff", "json-ocsf", "html"]
8184

0 commit comments

Comments
 (0)