Spaces:
Runtime error
Runtime error
Merge pull request #83 from dewitt4/publish-action
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .dockerignore +105 -0
- .github/workflows/README.md +125 -4
- .github/workflows/docker-publish.yml +129 -0
- .github/workflows/security-scan.yml +121 -0
- .gitignore +1 -0
- docker/README.md +160 -1
- docker/dockerfile +48 -0
- requirements.txt +0 -7
- requirements/base.txt +1 -6
- src/llmguardian/__init__.py +4 -3
- src/llmguardian/agency/__init__.py +2 -2
- src/llmguardian/agency/action_validator.py +2 -1
- src/llmguardian/agency/executor.py +2 -1
- src/llmguardian/agency/permission_manager.py +2 -1
- src/llmguardian/agency/scope_limiter.py +2 -1
- src/llmguardian/api/__init__.py +1 -1
- src/llmguardian/api/app.py +1 -0
- src/llmguardian/api/models.py +4 -3
- src/llmguardian/api/routes.py +10 -2
- src/llmguardian/api/security.py +4 -3
- src/llmguardian/cli/cli_interface.py +9 -8
- src/llmguardian/core/__init__.py +9 -9
- src/llmguardian/core/config.py +9 -7
- src/llmguardian/core/events.py +4 -3
- src/llmguardian/core/exceptions.py +3 -3
- src/llmguardian/core/logger.py +2 -2
- src/llmguardian/core/monitoring.py +6 -5
- src/llmguardian/core/rate_limiter.py +10 -8
- src/llmguardian/core/scanners/prompt_injection_scanner.py +6 -5
- src/llmguardian/core/security.py +4 -2
- src/llmguardian/core/validation.py +3 -2
- src/llmguardian/dashboard/app.py +11 -10
- src/llmguardian/data/leak_detector.py +5 -4
- src/llmguardian/data/poison_detector.py +8 -6
- src/llmguardian/data/privacy_guard.py +7 -7
- src/llmguardian/defenders/__init__.py +2 -2
- src/llmguardian/defenders/content_filter.py +3 -2
- src/llmguardian/defenders/context_validator.py +4 -3
- src/llmguardian/defenders/input_sanitizer.py +3 -2
- src/llmguardian/defenders/output_validator.py +3 -2
- src/llmguardian/defenders/test_context_validator.py +4 -2
- src/llmguardian/defenders/token_validator.py +6 -4
- src/llmguardian/monitors/__init__.py +3 -3
- src/llmguardian/monitors/audit_monitor.py +5 -4
- src/llmguardian/monitors/behavior_monitor.py +3 -2
- src/llmguardian/monitors/performance_monitor.py +5 -4
- src/llmguardian/monitors/threat_detector.py +5 -4
- src/llmguardian/monitors/usage_monitor.py +6 -4
- src/llmguardian/scanners/prompt_injection_scanner.py +3 -3
- src/llmguardian/vectors/__init__.py +1 -1
.dockerignore
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Git files
|
| 2 |
+
.git
|
| 3 |
+
.gitignore
|
| 4 |
+
.gitattributes
|
| 5 |
+
|
| 6 |
+
# GitHub
|
| 7 |
+
.github
|
| 8 |
+
|
| 9 |
+
# Python cache
|
| 10 |
+
__pycache__
|
| 11 |
+
*.py[cod]
|
| 12 |
+
*$py.class
|
| 13 |
+
*.so
|
| 14 |
+
.Python
|
| 15 |
+
build/
|
| 16 |
+
develop-eggs/
|
| 17 |
+
dist/
|
| 18 |
+
downloads/
|
| 19 |
+
eggs/
|
| 20 |
+
.eggs/
|
| 21 |
+
lib/
|
| 22 |
+
lib64/
|
| 23 |
+
parts/
|
| 24 |
+
sdist/
|
| 25 |
+
var/
|
| 26 |
+
wheels/
|
| 27 |
+
*.egg-info/
|
| 28 |
+
.installed.cfg
|
| 29 |
+
*.egg
|
| 30 |
+
MANIFEST
|
| 31 |
+
|
| 32 |
+
# Virtual environments
|
| 33 |
+
.env
|
| 34 |
+
.venv
|
| 35 |
+
env/
|
| 36 |
+
venv/
|
| 37 |
+
ENV/
|
| 38 |
+
env.bak/
|
| 39 |
+
venv.bak/
|
| 40 |
+
|
| 41 |
+
# Testing
|
| 42 |
+
.tox/
|
| 43 |
+
.coverage
|
| 44 |
+
.coverage.*
|
| 45 |
+
.cache
|
| 46 |
+
nosetests.xml
|
| 47 |
+
coverage.xml
|
| 48 |
+
*.cover
|
| 49 |
+
.hypothesis/
|
| 50 |
+
.pytest_cache/
|
| 51 |
+
test-results/
|
| 52 |
+
|
| 53 |
+
# IDE
|
| 54 |
+
.vscode/
|
| 55 |
+
.idea/
|
| 56 |
+
*.swp
|
| 57 |
+
*.swo
|
| 58 |
+
*~
|
| 59 |
+
.DS_Store
|
| 60 |
+
|
| 61 |
+
# Documentation
|
| 62 |
+
docs/_build/
|
| 63 |
+
*.md
|
| 64 |
+
!README.md
|
| 65 |
+
|
| 66 |
+
# Local development files
|
| 67 |
+
*.log
|
| 68 |
+
*.db
|
| 69 |
+
*.sqlite
|
| 70 |
+
*.sqlite3
|
| 71 |
+
.env.example
|
| 72 |
+
|
| 73 |
+
# Jupyter
|
| 74 |
+
.ipynb_checkpoints
|
| 75 |
+
|
| 76 |
+
# Temporary files
|
| 77 |
+
tmp/
|
| 78 |
+
temp/
|
| 79 |
+
*.tmp
|
| 80 |
+
|
| 81 |
+
# Docker
|
| 82 |
+
docker-compose.yml
|
| 83 |
+
Dockerfile
|
| 84 |
+
dockerfile
|
| 85 |
+
.dockerignore
|
| 86 |
+
|
| 87 |
+
# CI/CD
|
| 88 |
+
.travis.yml
|
| 89 |
+
.gitlab-ci.yml
|
| 90 |
+
azure-pipelines.yml
|
| 91 |
+
|
| 92 |
+
# Other
|
| 93 |
+
*.bak
|
| 94 |
+
*.backup
|
| 95 |
+
page/
|
| 96 |
+
examples_dashboard.py
|
| 97 |
+
demo_dashboard.py
|
| 98 |
+
setup.sh
|
| 99 |
+
run_dashboard.bat
|
| 100 |
+
run_dashboard.ps1
|
| 101 |
+
CNAME
|
| 102 |
+
CHANGELOG.md
|
| 103 |
+
CLAUDE.md
|
| 104 |
+
CONTRIBUTING.md
|
| 105 |
+
PROJECT.md
|
.github/workflows/README.md
CHANGED
|
@@ -30,13 +30,60 @@ The main continuous integration workflow with three sequential jobs:
|
|
| 30 |
- Builds Python distribution packages (sdist and wheel)
|
| 31 |
- Uploads build artifacts
|
| 32 |
|
| 33 |
-
### 2.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
**Trigger:** Pull Requests to `main` branch, Manual dispatch
|
| 35 |
|
| 36 |
- Checks for large files (>10MB) to ensure compatibility with HuggingFace Spaces
|
| 37 |
- Helps prevent repository bloat
|
|
|
|
| 38 |
|
| 39 |
-
###
|
| 40 |
**Trigger:** Push to `main` branch, Manual dispatch
|
| 41 |
|
| 42 |
- Syncs repository to HuggingFace Spaces
|
|
@@ -55,12 +102,29 @@ This project has migrated from CircleCI to GitHub Actions. The new CI workflow p
|
|
| 55 |
|
| 56 |
## Required Secrets
|
| 57 |
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
## Local Testing
|
| 61 |
|
| 62 |
To run the same checks locally before pushing:
|
| 63 |
|
|
|
|
| 64 |
```bash
|
| 65 |
# Install development dependencies
|
| 66 |
pip install -e ".[dev,test]"
|
|
@@ -76,4 +140,61 @@ pytest tests/ --cov=src --cov-report=term
|
|
| 76 |
|
| 77 |
# Build package
|
| 78 |
python -m build
|
| 79 |
-
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
- Builds Python distribution packages (sdist and wheel)
|
| 31 |
- Uploads build artifacts
|
| 32 |
|
| 33 |
+
### 2. Security Scan (security-scan.yml)
|
| 34 |
+
**Trigger:** Push and Pull Requests to `main` and `develop` branches, Daily schedule (2 AM UTC), Manual dispatch
|
| 35 |
+
|
| 36 |
+
Comprehensive security scanning with multiple jobs:
|
| 37 |
+
|
| 38 |
+
#### Trivy Repository Scan
|
| 39 |
+
- Scans filesystem for vulnerabilities in dependencies
|
| 40 |
+
- Checks for CRITICAL, HIGH, and MEDIUM severity issues
|
| 41 |
+
- Uploads results to GitHub Security tab (SARIF format)
|
| 42 |
+
|
| 43 |
+
#### Trivy Config Scan
|
| 44 |
+
- Scans configuration files for security misconfigurations
|
| 45 |
+
- Checks Dockerfiles, GitHub Actions, and other config files
|
| 46 |
+
|
| 47 |
+
#### Dependency Review
|
| 48 |
+
- Reviews dependency changes in pull requests
|
| 49 |
+
- Fails on high severity vulnerabilities
|
| 50 |
+
- Posts summary comments on PRs
|
| 51 |
+
|
| 52 |
+
#### Python Safety Check
|
| 53 |
+
- Runs safety check on Python dependencies
|
| 54 |
+
- Identifies known security vulnerabilities in packages
|
| 55 |
+
|
| 56 |
+
### 3. Docker Build & Publish (docker-publish.yml)
|
| 57 |
+
**Trigger:** Push to `main`, Version tags (v*.*.*), Pull Requests to `main`, Releases, Manual dispatch
|
| 58 |
+
|
| 59 |
+
Builds and publishes Docker images to GitHub Container Registry (ghcr.io):
|
| 60 |
+
|
| 61 |
+
#### Build and Push Job
|
| 62 |
+
- Builds Docker image using BuildKit
|
| 63 |
+
- Pushes to GitHub Container Registry (ghcr.io/dewitt4/llmguardian)
|
| 64 |
+
- Supports multi-architecture builds (linux/amd64, linux/arm64)
|
| 65 |
+
- Tags images with:
|
| 66 |
+
- Branch name (e.g., `main`)
|
| 67 |
+
- Semantic version (e.g., `v1.0.0`, `1.0`, `1`)
|
| 68 |
+
- Git SHA (e.g., `main-abc1234`)
|
| 69 |
+
- `latest` for main branch
|
| 70 |
+
- For PRs: Only builds, doesn't push
|
| 71 |
+
- Runs Trivy vulnerability scan on published images
|
| 72 |
+
- Generates artifact attestation for supply chain security
|
| 73 |
+
|
| 74 |
+
#### Test Image Job
|
| 75 |
+
- Pulls published image
|
| 76 |
+
- Validates image can run
|
| 77 |
+
- Checks image size
|
| 78 |
+
|
| 79 |
+
### 4. File Size Check (filesize.yml)
|
| 80 |
**Trigger:** Pull Requests to `main` branch, Manual dispatch
|
| 81 |
|
| 82 |
- Checks for large files (>10MB) to ensure compatibility with HuggingFace Spaces
|
| 83 |
- Helps prevent repository bloat
|
| 84 |
+
- Posts warnings on PRs for large files
|
| 85 |
|
| 86 |
+
### 5. HuggingFace Sync (huggingface.yml)
|
| 87 |
**Trigger:** Push to `main` branch, Manual dispatch
|
| 88 |
|
| 89 |
- Syncs repository to HuggingFace Spaces
|
|
|
|
| 102 |
|
| 103 |
## Required Secrets
|
| 104 |
|
| 105 |
+
### GitHub Container Registry
|
| 106 |
+
- No additional secrets needed - uses `GITHUB_TOKEN` automatically provided by GitHub Actions
|
| 107 |
+
|
| 108 |
+
### HuggingFace (Optional)
|
| 109 |
+
- `HF_TOKEN`: HuggingFace token for syncing to Spaces (only needed if using HuggingFace sync)
|
| 110 |
+
|
| 111 |
+
### Codecov (Optional)
|
| 112 |
+
- Coverage reports will upload anonymously, but you can configure `CODECOV_TOKEN` for private repos
|
| 113 |
+
|
| 114 |
+
## Permissions
|
| 115 |
+
|
| 116 |
+
The workflows use the following permissions:
|
| 117 |
+
|
| 118 |
+
- **CI Workflow**: `contents: read`
|
| 119 |
+
- **Security Scan**: `contents: read`, `security-events: write`
|
| 120 |
+
- **Docker Publish**: `contents: read`, `packages: write`, `id-token: write`
|
| 121 |
+
- **File Size Check**: `contents: read`, `pull-requests: write`
|
| 122 |
|
| 123 |
## Local Testing
|
| 124 |
|
| 125 |
To run the same checks locally before pushing:
|
| 126 |
|
| 127 |
+
### Code Quality & Tests
|
| 128 |
```bash
|
| 129 |
# Install development dependencies
|
| 130 |
pip install -e ".[dev,test]"
|
|
|
|
| 140 |
|
| 141 |
# Build package
|
| 142 |
python -m build
|
| 143 |
+
```
|
| 144 |
+
|
| 145 |
+
### Security Scanning
|
| 146 |
+
```bash
|
| 147 |
+
# Install Trivy (macOS)
|
| 148 |
+
brew install trivy
|
| 149 |
+
|
| 150 |
+
# Install Trivy (Linux)
|
| 151 |
+
wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | sudo apt-key add -
|
| 152 |
+
echo "deb https://aquasecurity.github.io/trivy-repo/deb $(lsb_release -sc) main" | sudo tee -a /etc/apt/sources.list.d/trivy.list
|
| 153 |
+
sudo apt-get update && sudo apt-get install trivy
|
| 154 |
+
|
| 155 |
+
# Run Trivy scans
|
| 156 |
+
trivy fs . --severity CRITICAL,HIGH,MEDIUM
|
| 157 |
+
trivy config .
|
| 158 |
+
|
| 159 |
+
# Run Safety check
|
| 160 |
+
pip install safety
|
| 161 |
+
safety check
|
| 162 |
+
```
|
| 163 |
+
|
| 164 |
+
### Docker Build & Test
|
| 165 |
+
```bash
|
| 166 |
+
# Build Docker image
|
| 167 |
+
docker build -f docker/dockerfile -t llmguardian:local .
|
| 168 |
+
|
| 169 |
+
# Run container
|
| 170 |
+
docker run -p 8000:8000 -p 8501:8501 llmguardian:local
|
| 171 |
+
|
| 172 |
+
# Scan Docker image with Trivy
|
| 173 |
+
trivy image llmguardian:local
|
| 174 |
+
|
| 175 |
+
# Test image
|
| 176 |
+
docker run --rm llmguardian:local python -c "import llmguardian; print(llmguardian.__version__)"
|
| 177 |
+
```
|
| 178 |
+
|
| 179 |
+
## Using Published Docker Images
|
| 180 |
+
|
| 181 |
+
Pull and run the latest published image:
|
| 182 |
+
|
| 183 |
+
```bash
|
| 184 |
+
# Pull latest image
|
| 185 |
+
docker pull ghcr.io/dewitt4/llmguardian:latest
|
| 186 |
+
|
| 187 |
+
# Run API server
|
| 188 |
+
docker run -p 8000:8000 ghcr.io/dewitt4/llmguardian:latest
|
| 189 |
+
|
| 190 |
+
# Run dashboard
|
| 191 |
+
docker run -p 8501:8501 ghcr.io/dewitt4/llmguardian:latest streamlit run src/llmguardian/dashboard/app.py
|
| 192 |
+
|
| 193 |
+
# Run with environment variables
|
| 194 |
+
docker run -p 8000:8000 \
|
| 195 |
+
-e LOG_LEVEL=DEBUG \
|
| 196 |
+
-e SECURITY_RISK_THRESHOLD=8 \
|
| 197 |
+
ghcr.io/dewitt4/llmguardian:latest
|
| 198 |
+
```
|
| 199 |
+
|
| 200 |
+
See `docker/README.md` for more Docker usage examples.
|
.github/workflows/docker-publish.yml
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: Docker Build & Publish
|
| 2 |
+
|
| 3 |
+
on:
|
| 4 |
+
push:
|
| 5 |
+
branches: [ main ]
|
| 6 |
+
tags:
|
| 7 |
+
- 'v*.*.*'
|
| 8 |
+
pull_request:
|
| 9 |
+
branches: [ main ]
|
| 10 |
+
workflow_dispatch:
|
| 11 |
+
release:
|
| 12 |
+
types: [published]
|
| 13 |
+
|
| 14 |
+
env:
|
| 15 |
+
REGISTRY: ghcr.io
|
| 16 |
+
IMAGE_NAME: ${{ github.repository }}
|
| 17 |
+
|
| 18 |
+
permissions:
|
| 19 |
+
contents: read
|
| 20 |
+
packages: write
|
| 21 |
+
|
| 22 |
+
jobs:
|
| 23 |
+
build-and-push:
|
| 24 |
+
name: Build and Push Docker Image
|
| 25 |
+
runs-on: ubuntu-latest
|
| 26 |
+
permissions:
|
| 27 |
+
contents: read
|
| 28 |
+
packages: write
|
| 29 |
+
id-token: write
|
| 30 |
+
|
| 31 |
+
steps:
|
| 32 |
+
- name: Checkout code
|
| 33 |
+
uses: actions/checkout@v4
|
| 34 |
+
|
| 35 |
+
- name: Set up Docker Buildx
|
| 36 |
+
uses: docker/setup-buildx-action@v3
|
| 37 |
+
|
| 38 |
+
- name: Log in to GitHub Container Registry
|
| 39 |
+
uses: docker/login-action@v3
|
| 40 |
+
with:
|
| 41 |
+
registry: ${{ env.REGISTRY }}
|
| 42 |
+
username: ${{ github.actor }}
|
| 43 |
+
password: ${{ secrets.GITHUB_TOKEN }}
|
| 44 |
+
|
| 45 |
+
- name: Extract metadata (tags, labels) for Docker
|
| 46 |
+
id: meta
|
| 47 |
+
uses: docker/metadata-action@v5
|
| 48 |
+
with:
|
| 49 |
+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
| 50 |
+
tags: |
|
| 51 |
+
type=ref,event=branch
|
| 52 |
+
type=ref,event=pr
|
| 53 |
+
type=semver,pattern={{version}}
|
| 54 |
+
type=semver,pattern={{major}}.{{minor}}
|
| 55 |
+
type=semver,pattern={{major}}
|
| 56 |
+
type=sha,prefix=sha-
|
| 57 |
+
type=raw,value=latest,enable={{is_default_branch}}
|
| 58 |
+
|
| 59 |
+
- name: Build Docker image (PR)
|
| 60 |
+
if: github.event_name == 'pull_request'
|
| 61 |
+
uses: docker/build-push-action@v5
|
| 62 |
+
with:
|
| 63 |
+
context: .
|
| 64 |
+
file: ./docker/dockerfile
|
| 65 |
+
push: false
|
| 66 |
+
tags: ${{ steps.meta.outputs.tags }}
|
| 67 |
+
labels: ${{ steps.meta.outputs.labels }}
|
| 68 |
+
cache-from: type=gha
|
| 69 |
+
cache-to: type=gha,mode=max
|
| 70 |
+
load: true
|
| 71 |
+
|
| 72 |
+
- name: Build and push Docker image
|
| 73 |
+
if: github.event_name != 'pull_request'
|
| 74 |
+
uses: docker/build-push-action@v5
|
| 75 |
+
with:
|
| 76 |
+
context: .
|
| 77 |
+
file: ./docker/dockerfile
|
| 78 |
+
push: true
|
| 79 |
+
tags: ${{ steps.meta.outputs.tags }}
|
| 80 |
+
labels: ${{ steps.meta.outputs.labels }}
|
| 81 |
+
cache-from: type=gha
|
| 82 |
+
cache-to: type=gha,mode=max
|
| 83 |
+
platforms: linux/amd64,linux/arm64
|
| 84 |
+
provenance: mode=max
|
| 85 |
+
sbom: true
|
| 86 |
+
|
| 87 |
+
- name: Run Trivy vulnerability scanner on image
|
| 88 |
+
if: github.event_name != 'pull_request'
|
| 89 |
+
uses: aquasecurity/trivy-action@master
|
| 90 |
+
with:
|
| 91 |
+
image-ref: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ fromJSON(steps.meta.outputs.json).tags[0] }}
|
| 92 |
+
format: 'sarif'
|
| 93 |
+
output: 'trivy-image-results.sarif'
|
| 94 |
+
severity: 'CRITICAL,HIGH'
|
| 95 |
+
|
| 96 |
+
- name: Upload Trivy scan results to GitHub Security tab
|
| 97 |
+
if: github.event_name != 'pull_request'
|
| 98 |
+
uses: github/codeql-action/upload-sarif@v3
|
| 99 |
+
with:
|
| 100 |
+
sarif_file: 'trivy-image-results.sarif'
|
| 101 |
+
|
| 102 |
+
test-image:
|
| 103 |
+
name: Test Docker Image
|
| 104 |
+
runs-on: ubuntu-latest
|
| 105 |
+
needs: build-and-push
|
| 106 |
+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
| 107 |
+
permissions:
|
| 108 |
+
contents: read
|
| 109 |
+
packages: read
|
| 110 |
+
|
| 111 |
+
steps:
|
| 112 |
+
- name: Log in to GitHub Container Registry
|
| 113 |
+
uses: docker/login-action@v3
|
| 114 |
+
with:
|
| 115 |
+
registry: ${{ env.REGISTRY }}
|
| 116 |
+
username: ${{ github.actor }}
|
| 117 |
+
password: ${{ secrets.GITHUB_TOKEN }}
|
| 118 |
+
|
| 119 |
+
- name: Pull Docker image
|
| 120 |
+
run: |
|
| 121 |
+
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
|
| 122 |
+
|
| 123 |
+
- name: Test Docker image
|
| 124 |
+
run: |
|
| 125 |
+
docker run --rm ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest python -c "import llmguardian; print(llmguardian.__version__)"
|
| 126 |
+
|
| 127 |
+
- name: Check image size
|
| 128 |
+
run: |
|
| 129 |
+
docker images ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest --format "{{.Size}}"
|
.github/workflows/security-scan.yml
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: Security Scan
|
| 2 |
+
|
| 3 |
+
on:
|
| 4 |
+
push:
|
| 5 |
+
branches: [ main, develop ]
|
| 6 |
+
pull_request:
|
| 7 |
+
branches: [ main, develop ]
|
| 8 |
+
schedule:
|
| 9 |
+
# Run security scan daily at 2 AM UTC
|
| 10 |
+
- cron: '0 2 * * *'
|
| 11 |
+
workflow_dispatch:
|
| 12 |
+
|
| 13 |
+
permissions:
|
| 14 |
+
contents: read
|
| 15 |
+
security-events: write
|
| 16 |
+
|
| 17 |
+
jobs:
|
| 18 |
+
trivy-repo-scan:
|
| 19 |
+
name: Trivy Repository Scan
|
| 20 |
+
runs-on: ubuntu-latest
|
| 21 |
+
permissions:
|
| 22 |
+
contents: read
|
| 23 |
+
security-events: write
|
| 24 |
+
|
| 25 |
+
steps:
|
| 26 |
+
- name: Checkout code
|
| 27 |
+
uses: actions/checkout@v4
|
| 28 |
+
|
| 29 |
+
- name: Run Trivy vulnerability scanner in repo mode
|
| 30 |
+
uses: aquasecurity/trivy-action@master
|
| 31 |
+
with:
|
| 32 |
+
scan-type: 'fs'
|
| 33 |
+
scan-ref: '.'
|
| 34 |
+
format: 'sarif'
|
| 35 |
+
output: 'trivy-results.sarif'
|
| 36 |
+
severity: 'CRITICAL,HIGH,MEDIUM'
|
| 37 |
+
ignore-unfixed: true
|
| 38 |
+
|
| 39 |
+
- name: Upload Trivy results to GitHub Security tab
|
| 40 |
+
uses: github/codeql-action/upload-sarif@v3
|
| 41 |
+
if: always()
|
| 42 |
+
with:
|
| 43 |
+
sarif_file: 'trivy-results.sarif'
|
| 44 |
+
|
| 45 |
+
- name: Run Trivy vulnerability scanner (table output)
|
| 46 |
+
uses: aquasecurity/trivy-action@master
|
| 47 |
+
with:
|
| 48 |
+
scan-type: 'fs'
|
| 49 |
+
scan-ref: '.'
|
| 50 |
+
format: 'table'
|
| 51 |
+
severity: 'CRITICAL,HIGH,MEDIUM'
|
| 52 |
+
ignore-unfixed: true
|
| 53 |
+
|
| 54 |
+
trivy-config-scan:
|
| 55 |
+
name: Trivy Config Scan
|
| 56 |
+
runs-on: ubuntu-latest
|
| 57 |
+
permissions:
|
| 58 |
+
contents: read
|
| 59 |
+
security-events: write
|
| 60 |
+
|
| 61 |
+
steps:
|
| 62 |
+
- name: Checkout code
|
| 63 |
+
uses: actions/checkout@v4
|
| 64 |
+
|
| 65 |
+
- name: Run Trivy config scanner
|
| 66 |
+
uses: aquasecurity/trivy-action@master
|
| 67 |
+
with:
|
| 68 |
+
scan-type: 'config'
|
| 69 |
+
scan-ref: '.'
|
| 70 |
+
format: 'sarif'
|
| 71 |
+
output: 'trivy-config-results.sarif'
|
| 72 |
+
exit-code: '0'
|
| 73 |
+
|
| 74 |
+
- name: Upload Trivy config results to GitHub Security tab
|
| 75 |
+
uses: github/codeql-action/upload-sarif@v3
|
| 76 |
+
if: always()
|
| 77 |
+
with:
|
| 78 |
+
sarif_file: 'trivy-config-results.sarif'
|
| 79 |
+
|
| 80 |
+
dependency-review:
|
| 81 |
+
name: Dependency Review
|
| 82 |
+
runs-on: ubuntu-latest
|
| 83 |
+
if: github.event_name == 'pull_request'
|
| 84 |
+
permissions:
|
| 85 |
+
contents: read
|
| 86 |
+
pull-requests: write
|
| 87 |
+
|
| 88 |
+
steps:
|
| 89 |
+
- name: Checkout code
|
| 90 |
+
uses: actions/checkout@v4
|
| 91 |
+
|
| 92 |
+
- name: Dependency Review
|
| 93 |
+
uses: actions/dependency-review-action@v4
|
| 94 |
+
with:
|
| 95 |
+
fail-on-severity: high
|
| 96 |
+
comment-summary-in-pr: true
|
| 97 |
+
|
| 98 |
+
python-safety-check:
|
| 99 |
+
name: Python Safety Check
|
| 100 |
+
runs-on: ubuntu-latest
|
| 101 |
+
permissions:
|
| 102 |
+
contents: read
|
| 103 |
+
|
| 104 |
+
steps:
|
| 105 |
+
- name: Checkout code
|
| 106 |
+
uses: actions/checkout@v4
|
| 107 |
+
|
| 108 |
+
- name: Set up Python
|
| 109 |
+
uses: actions/setup-python@v5
|
| 110 |
+
with:
|
| 111 |
+
python-version: '3.11'
|
| 112 |
+
cache: 'pip'
|
| 113 |
+
|
| 114 |
+
- name: Install safety
|
| 115 |
+
run: pip install safety
|
| 116 |
+
|
| 117 |
+
- name: Run safety check
|
| 118 |
+
run: |
|
| 119 |
+
pip install -r requirements.txt
|
| 120 |
+
safety check --json
|
| 121 |
+
continue-on-error: true
|
.gitignore
CHANGED
|
@@ -167,3 +167,4 @@ cython_debug/
|
|
| 167 |
CNAME
|
| 168 |
CLAUDE.md
|
| 169 |
PROJECT.md
|
|
|
|
|
|
| 167 |
CNAME
|
| 168 |
CLAUDE.md
|
| 169 |
PROJECT.md
|
| 170 |
+
GITHUB_ACTIONS_SUMMARY.md
|
docker/README.md
CHANGED
|
@@ -1 +1,160 @@
|
|
| 1 |
-
# Docker
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Docker Configuration
|
| 2 |
+
|
| 3 |
+
This directory contains Docker configuration for LLMGuardian.
|
| 4 |
+
|
| 5 |
+
## Quick Start
|
| 6 |
+
|
| 7 |
+
### Using Pre-built Images from GitHub Container Registry
|
| 8 |
+
|
| 9 |
+
Pull and run the latest image:
|
| 10 |
+
|
| 11 |
+
```bash
|
| 12 |
+
docker pull ghcr.io/dewitt4/llmguardian:latest
|
| 13 |
+
docker run -p 8000:8000 -p 8501:8501 ghcr.io/dewitt4/llmguardian:latest
|
| 14 |
+
```
|
| 15 |
+
|
| 16 |
+
### Building Locally
|
| 17 |
+
|
| 18 |
+
Build the Docker image:
|
| 19 |
+
|
| 20 |
+
```bash
|
| 21 |
+
docker build -f docker/dockerfile -t llmguardian:local .
|
| 22 |
+
```
|
| 23 |
+
|
| 24 |
+
Run the container:
|
| 25 |
+
|
| 26 |
+
```bash
|
| 27 |
+
docker run -p 8000:8000 -p 8501:8501 llmguardian:local
|
| 28 |
+
```
|
| 29 |
+
|
| 30 |
+
## Available Tags
|
| 31 |
+
|
| 32 |
+
- `latest` - Latest stable release from main branch
|
| 33 |
+
- `v*.*.*` - Specific version tags (e.g., v1.0.0)
|
| 34 |
+
- `main` - Latest commit on main branch
|
| 35 |
+
- `develop` - Latest commit on develop branch
|
| 36 |
+
|
| 37 |
+
## Environment Variables
|
| 38 |
+
|
| 39 |
+
Configure the container using environment variables:
|
| 40 |
+
|
| 41 |
+
```bash
|
| 42 |
+
docker run -p 8000:8000 \
|
| 43 |
+
-e SECURITY_RISK_THRESHOLD=8 \
|
| 44 |
+
-e LOG_LEVEL=DEBUG \
|
| 45 |
+
-e API_SERVER_PORT=8000 \
|
| 46 |
+
ghcr.io/dewitt4/llmguardian:latest
|
| 47 |
+
```
|
| 48 |
+
|
| 49 |
+
See `.env.example` in the root directory for all available environment variables.
|
| 50 |
+
|
| 51 |
+
## Exposed Ports
|
| 52 |
+
|
| 53 |
+
- `8000` - API Server
|
| 54 |
+
- `8501` - Dashboard (Streamlit)
|
| 55 |
+
|
| 56 |
+
## Volume Mounts
|
| 57 |
+
|
| 58 |
+
Mount volumes for persistent data:
|
| 59 |
+
|
| 60 |
+
```bash
|
| 61 |
+
docker run -p 8000:8000 \
|
| 62 |
+
-v $(pwd)/logs:/app/logs \
|
| 63 |
+
-v $(pwd)/data:/app/data \
|
| 64 |
+
ghcr.io/dewitt4/llmguardian:latest
|
| 65 |
+
```
|
| 66 |
+
|
| 67 |
+
## Docker Compose (Example)
|
| 68 |
+
|
| 69 |
+
Create a `docker-compose.yml` file:
|
| 70 |
+
|
| 71 |
+
```yaml
|
| 72 |
+
version: '3.8'
|
| 73 |
+
|
| 74 |
+
services:
|
| 75 |
+
llmguardian-api:
|
| 76 |
+
image: ghcr.io/dewitt4/llmguardian:latest
|
| 77 |
+
ports:
|
| 78 |
+
- "8000:8000"
|
| 79 |
+
environment:
|
| 80 |
+
- LOG_LEVEL=INFO
|
| 81 |
+
- SECURITY_RISK_THRESHOLD=7
|
| 82 |
+
volumes:
|
| 83 |
+
- ./logs:/app/logs
|
| 84 |
+
- ./data:/app/data
|
| 85 |
+
restart: unless-stopped
|
| 86 |
+
|
| 87 |
+
llmguardian-dashboard:
|
| 88 |
+
image: ghcr.io/dewitt4/llmguardian:latest
|
| 89 |
+
command: ["streamlit", "run", "src/llmguardian/dashboard/app.py"]
|
| 90 |
+
ports:
|
| 91 |
+
- "8501:8501"
|
| 92 |
+
environment:
|
| 93 |
+
- DASHBOARD_PORT=8501
|
| 94 |
+
- DASHBOARD_HOST=0.0.0.0
|
| 95 |
+
depends_on:
|
| 96 |
+
- llmguardian-api
|
| 97 |
+
restart: unless-stopped
|
| 98 |
+
```
|
| 99 |
+
|
| 100 |
+
Run with:
|
| 101 |
+
|
| 102 |
+
```bash
|
| 103 |
+
docker-compose up -d
|
| 104 |
+
```
|
| 105 |
+
|
| 106 |
+
## Health Check
|
| 107 |
+
|
| 108 |
+
The container includes a health check endpoint:
|
| 109 |
+
|
| 110 |
+
```bash
|
| 111 |
+
curl http://localhost:8000/health
|
| 112 |
+
```
|
| 113 |
+
|
| 114 |
+
## Security Scanning
|
| 115 |
+
|
| 116 |
+
All published images are automatically scanned with Trivy for vulnerabilities. Check the [Security tab](https://github.com/dewitt4/LLMGuardian/security) for scan results.
|
| 117 |
+
|
| 118 |
+
## Multi-Architecture Support
|
| 119 |
+
|
| 120 |
+
Images are built for both AMD64 and ARM64 architectures:
|
| 121 |
+
|
| 122 |
+
```bash
|
| 123 |
+
# Automatically pulls the correct architecture
|
| 124 |
+
docker pull ghcr.io/dewitt4/llmguardian:latest
|
| 125 |
+
```
|
| 126 |
+
|
| 127 |
+
## Troubleshooting
|
| 128 |
+
|
| 129 |
+
### Permission Issues
|
| 130 |
+
|
| 131 |
+
If you encounter permission issues with volume mounts:
|
| 132 |
+
|
| 133 |
+
```bash
|
| 134 |
+
docker run --user $(id -u):$(id -g) \
|
| 135 |
+
-v $(pwd)/logs:/app/logs \
|
| 136 |
+
ghcr.io/dewitt4/llmguardian:latest
|
| 137 |
+
```
|
| 138 |
+
|
| 139 |
+
### View Logs
|
| 140 |
+
|
| 141 |
+
```bash
|
| 142 |
+
docker logs <container-id>
|
| 143 |
+
```
|
| 144 |
+
|
| 145 |
+
### Interactive Shell
|
| 146 |
+
|
| 147 |
+
```bash
|
| 148 |
+
docker run -it --entrypoint /bin/bash ghcr.io/dewitt4/llmguardian:latest
|
| 149 |
+
```
|
| 150 |
+
|
| 151 |
+
## CI/CD Integration
|
| 152 |
+
|
| 153 |
+
Images are automatically built and published via GitHub Actions:
|
| 154 |
+
|
| 155 |
+
- **On push to main**: Builds and publishes `latest` tag
|
| 156 |
+
- **On version tags**: Builds and publishes version-specific tags
|
| 157 |
+
- **On pull requests**: Builds image but doesn't publish
|
| 158 |
+
- **Daily security scans**: Automated Trivy scans
|
| 159 |
+
|
| 160 |
+
See `.github/workflows/docker-publish.yml` for workflow details.
|
docker/dockerfile
CHANGED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# LLMGuardian Docker Image
|
| 2 |
+
FROM python:3.11-slim
|
| 3 |
+
|
| 4 |
+
# Set environment variables
|
| 5 |
+
ENV PYTHONUNBUFFERED=1 \
|
| 6 |
+
PYTHONDONTWRITEBYTECODE=1 \
|
| 7 |
+
PIP_NO_CACHE_DIR=1 \
|
| 8 |
+
PIP_DISABLE_PIP_VERSION_CHECK=1
|
| 9 |
+
|
| 10 |
+
# Set working directory
|
| 11 |
+
WORKDIR /app
|
| 12 |
+
|
| 13 |
+
# Install system dependencies
|
| 14 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 15 |
+
gcc \
|
| 16 |
+
git \
|
| 17 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 18 |
+
|
| 19 |
+
# Copy requirements files
|
| 20 |
+
COPY requirements/ /app/requirements/
|
| 21 |
+
COPY requirements.txt /app/
|
| 22 |
+
|
| 23 |
+
# Install Python dependencies
|
| 24 |
+
RUN pip install --upgrade pip && \
|
| 25 |
+
pip install -r requirements.txt
|
| 26 |
+
|
| 27 |
+
# Copy source code
|
| 28 |
+
COPY src/ /app/src/
|
| 29 |
+
COPY setup.py /app/
|
| 30 |
+
COPY pyproject.toml /app/
|
| 31 |
+
COPY README.md /app/
|
| 32 |
+
COPY LICENSE /app/
|
| 33 |
+
|
| 34 |
+
# Install the package
|
| 35 |
+
RUN pip install -e .
|
| 36 |
+
|
| 37 |
+
# Create necessary directories
|
| 38 |
+
RUN mkdir -p /app/logs /app/data /app/.cache
|
| 39 |
+
|
| 40 |
+
# Expose ports for API and Dashboard
|
| 41 |
+
EXPOSE 8000 8501
|
| 42 |
+
|
| 43 |
+
# Add health check
|
| 44 |
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
| 45 |
+
CMD python -c "import requests; requests.get('http://localhost:8000/health')" || exit 1
|
| 46 |
+
|
| 47 |
+
# Default command (can be overridden)
|
| 48 |
+
CMD ["python", "-m", "llmguardian.api.app"]
|
requirements.txt
CHANGED
|
@@ -4,13 +4,6 @@
|
|
| 4 |
# CLI Dependencies
|
| 5 |
click>=8.1.0
|
| 6 |
rich>=13.0.0
|
| 7 |
-
pathlib>=1.0.1
|
| 8 |
-
|
| 9 |
-
# Core Dependencies
|
| 10 |
-
dataclasses>=0.6
|
| 11 |
-
typing>=3.7.4
|
| 12 |
-
logging>=0.5.1.2
|
| 13 |
-
enum34>=1.1.10
|
| 14 |
|
| 15 |
# Dashboard Dependencies
|
| 16 |
streamlit>=1.28.0
|
|
|
|
| 4 |
# CLI Dependencies
|
| 5 |
click>=8.1.0
|
| 6 |
rich>=13.0.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
# Dashboard Dependencies
|
| 9 |
streamlit>=1.28.0
|
requirements/base.txt
CHANGED
|
@@ -2,15 +2,10 @@
|
|
| 2 |
# Core dependencies
|
| 3 |
click>=8.1.0
|
| 4 |
rich>=13.0.0
|
| 5 |
-
|
| 6 |
-
dataclasses>=0.6
|
| 7 |
-
typing>=3.7.4
|
| 8 |
-
enum34>=1.1.10
|
| 9 |
pyyaml>=6.0.1
|
| 10 |
psutil>=5.9.0
|
| 11 |
python-json-logger>=2.0.7
|
| 12 |
-
dataclasses>=0.6
|
| 13 |
-
typing-extensions>=4.5.0
|
| 14 |
pyjwt>=2.8.0
|
| 15 |
cryptography>=41.0.0
|
| 16 |
certifi>=2023.7.22
|
|
|
|
| 2 |
# Core dependencies
|
| 3 |
click>=8.1.0
|
| 4 |
rich>=13.0.0
|
| 5 |
+
typing-extensions>=4.5.0
|
|
|
|
|
|
|
|
|
|
| 6 |
pyyaml>=6.0.1
|
| 7 |
psutil>=5.9.0
|
| 8 |
python-json-logger>=2.0.7
|
|
|
|
|
|
|
| 9 |
pyjwt>=2.8.0
|
| 10 |
cryptography>=41.0.0
|
| 11 |
certifi>=2023.7.22
|
src/llmguardian/__init__.py
CHANGED
|
@@ -7,13 +7,14 @@ __version__ = "1.4.0"
|
|
| 7 |
__author__ = "dewitt4"
|
| 8 |
__license__ = "Apache-2.0"
|
| 9 |
|
| 10 |
-
from typing import
|
| 11 |
|
| 12 |
-
# Package level imports
|
| 13 |
-
from .scanners.prompt_injection_scanner import PromptInjectionScanner
|
| 14 |
from .core.config import Config
|
| 15 |
from .core.logger import setup_logging
|
| 16 |
|
|
|
|
|
|
|
|
|
|
| 17 |
# Initialize logging
|
| 18 |
setup_logging()
|
| 19 |
|
|
|
|
| 7 |
__author__ = "dewitt4"
|
| 8 |
__license__ = "Apache-2.0"
|
| 9 |
|
| 10 |
+
from typing import Dict, List, Optional
|
| 11 |
|
|
|
|
|
|
|
| 12 |
from .core.config import Config
|
| 13 |
from .core.logger import setup_logging
|
| 14 |
|
| 15 |
+
# Package level imports
|
| 16 |
+
from .scanners.prompt_injection_scanner import PromptInjectionScanner
|
| 17 |
+
|
| 18 |
# Initialize logging
|
| 19 |
setup_logging()
|
| 20 |
|
src/llmguardian/agency/__init__.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
# src/llmguardian/agency/__init__.py
|
| 2 |
-
from .permission_manager import PermissionManager
|
| 3 |
from .action_validator import ActionValidator
|
| 4 |
-
from .scope_limiter import ScopeLimiter
|
| 5 |
from .executor import SafeExecutor
|
|
|
|
|
|
|
|
|
| 1 |
# src/llmguardian/agency/__init__.py
|
|
|
|
| 2 |
from .action_validator import ActionValidator
|
|
|
|
| 3 |
from .executor import SafeExecutor
|
| 4 |
+
from .permission_manager import PermissionManager
|
| 5 |
+
from .scope_limiter import ScopeLimiter
|
src/llmguardian/agency/action_validator.py
CHANGED
|
@@ -1,7 +1,8 @@
|
|
| 1 |
# src/llmguardian/agency/action_validator.py
|
| 2 |
-
from typing import Dict, List, Optional
|
| 3 |
from dataclasses import dataclass
|
| 4 |
from enum import Enum
|
|
|
|
|
|
|
| 5 |
from ..core.logger import SecurityLogger
|
| 6 |
|
| 7 |
|
|
|
|
| 1 |
# src/llmguardian/agency/action_validator.py
|
|
|
|
| 2 |
from dataclasses import dataclass
|
| 3 |
from enum import Enum
|
| 4 |
+
from typing import Dict, List, Optional
|
| 5 |
+
|
| 6 |
from ..core.logger import SecurityLogger
|
| 7 |
|
| 8 |
|
src/llmguardian/agency/executor.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
# src/llmguardian/agency/executor.py
|
| 2 |
-
from typing import Dict, Any, Optional
|
| 3 |
from dataclasses import dataclass
|
|
|
|
|
|
|
| 4 |
from ..core.logger import SecurityLogger
|
| 5 |
from .action_validator import Action, ActionValidator
|
| 6 |
from .permission_manager import PermissionManager
|
|
|
|
| 1 |
# src/llmguardian/agency/executor.py
|
|
|
|
| 2 |
from dataclasses import dataclass
|
| 3 |
+
from typing import Any, Dict, Optional
|
| 4 |
+
|
| 5 |
from ..core.logger import SecurityLogger
|
| 6 |
from .action_validator import Action, ActionValidator
|
| 7 |
from .permission_manager import PermissionManager
|
src/llmguardian/agency/permission_manager.py
CHANGED
|
@@ -1,7 +1,8 @@
|
|
| 1 |
# src/llmguardian/agency/permission_manager.py
|
| 2 |
-
from typing import Dict, List, Optional, Set
|
| 3 |
from dataclasses import dataclass
|
| 4 |
from enum import Enum
|
|
|
|
|
|
|
| 5 |
from ..core.logger import SecurityLogger
|
| 6 |
|
| 7 |
|
|
|
|
| 1 |
# src/llmguardian/agency/permission_manager.py
|
|
|
|
| 2 |
from dataclasses import dataclass
|
| 3 |
from enum import Enum
|
| 4 |
+
from typing import Dict, List, Optional, Set
|
| 5 |
+
|
| 6 |
from ..core.logger import SecurityLogger
|
| 7 |
|
| 8 |
|
src/llmguardian/agency/scope_limiter.py
CHANGED
|
@@ -1,7 +1,8 @@
|
|
| 1 |
# src/llmguardian/agency/scope_limiter.py
|
| 2 |
-
from typing import Dict, List, Optional, Set
|
| 3 |
from dataclasses import dataclass
|
| 4 |
from enum import Enum
|
|
|
|
|
|
|
| 5 |
from ..core.logger import SecurityLogger
|
| 6 |
|
| 7 |
|
|
|
|
| 1 |
# src/llmguardian/agency/scope_limiter.py
|
|
|
|
| 2 |
from dataclasses import dataclass
|
| 3 |
from enum import Enum
|
| 4 |
+
from typing import Dict, List, Optional, Set
|
| 5 |
+
|
| 6 |
from ..core.logger import SecurityLogger
|
| 7 |
|
| 8 |
|
src/llmguardian/api/__init__.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
# src/llmguardian/api/__init__.py
|
| 2 |
-
from .routes import router
|
| 3 |
from .models import SecurityRequest, SecurityResponse
|
|
|
|
| 4 |
from .security import SecurityMiddleware
|
|
|
|
| 1 |
# src/llmguardian/api/__init__.py
|
|
|
|
| 2 |
from .models import SecurityRequest, SecurityResponse
|
| 3 |
+
from .routes import router
|
| 4 |
from .security import SecurityMiddleware
|
src/llmguardian/api/app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
# src/llmguardian/api/app.py
|
| 2 |
from fastapi import FastAPI
|
| 3 |
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
| 4 |
from .routes import router
|
| 5 |
from .security import SecurityMiddleware
|
| 6 |
|
|
|
|
| 1 |
# src/llmguardian/api/app.py
|
| 2 |
from fastapi import FastAPI
|
| 3 |
from fastapi.middleware.cors import CORSMiddleware
|
| 4 |
+
|
| 5 |
from .routes import router
|
| 6 |
from .security import SecurityMiddleware
|
| 7 |
|
src/llmguardian/api/models.py
CHANGED
|
@@ -1,8 +1,9 @@
|
|
| 1 |
# src/llmguardian/api/models.py
|
| 2 |
-
from pydantic import BaseModel
|
| 3 |
-
from typing import List, Optional, Dict, Any
|
| 4 |
-
from enum import Enum
|
| 5 |
from datetime import datetime
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
|
| 8 |
class SecurityLevel(str, Enum):
|
|
|
|
| 1 |
# src/llmguardian/api/models.py
|
|
|
|
|
|
|
|
|
|
| 2 |
from datetime import datetime
|
| 3 |
+
from enum import Enum
|
| 4 |
+
from typing import Any, Dict, List, Optional
|
| 5 |
+
|
| 6 |
+
from pydantic import BaseModel
|
| 7 |
|
| 8 |
|
| 9 |
class SecurityLevel(str, Enum):
|
src/llmguardian/api/routes.py
CHANGED
|
@@ -1,14 +1,22 @@
|
|
| 1 |
# src/llmguardian/api/routes.py
|
| 2 |
-
from fastapi import APIRouter, Depends, HTTPException
|
| 3 |
from typing import List
|
| 4 |
-
|
|
|
|
|
|
|
| 5 |
from ..data.privacy_guard import PrivacyGuard
|
| 6 |
from ..vectors.vector_scanner import VectorScanner
|
|
|
|
| 7 |
from .security import verify_token
|
| 8 |
|
| 9 |
router = APIRouter()
|
| 10 |
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
@router.post("/scan", response_model=SecurityResponse)
|
| 13 |
async def scan_content(request: SecurityRequest, token: str = Depends(verify_token)):
|
| 14 |
try:
|
|
|
|
| 1 |
# src/llmguardian/api/routes.py
|
|
|
|
| 2 |
from typing import List
|
| 3 |
+
|
| 4 |
+
from fastapi import APIRouter, Depends, HTTPException
|
| 5 |
+
|
| 6 |
from ..data.privacy_guard import PrivacyGuard
|
| 7 |
from ..vectors.vector_scanner import VectorScanner
|
| 8 |
+
from .models import PrivacyRequest, SecurityRequest, SecurityResponse, VectorRequest
|
| 9 |
from .security import verify_token
|
| 10 |
|
| 11 |
router = APIRouter()
|
| 12 |
|
| 13 |
|
| 14 |
+
@router.get("/health")
|
| 15 |
+
async def health_check():
|
| 16 |
+
"""Health check endpoint for container orchestration"""
|
| 17 |
+
return {"status": "healthy", "service": "llmguardian"}
|
| 18 |
+
|
| 19 |
+
|
| 20 |
@router.post("/scan", response_model=SecurityResponse)
|
| 21 |
async def scan_content(request: SecurityRequest, token: str = Depends(verify_token)):
|
| 22 |
try:
|
src/llmguardian/api/security.py
CHANGED
|
@@ -1,10 +1,11 @@
|
|
| 1 |
# src/llmguardian/api/security.py
|
| 2 |
-
from fastapi import HTTPException, Security
|
| 3 |
-
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
|
| 4 |
-
import jwt
|
| 5 |
from datetime import datetime, timedelta
|
| 6 |
from typing import Optional
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
security = HTTPBearer()
|
| 9 |
|
| 10 |
|
|
|
|
| 1 |
# src/llmguardian/api/security.py
|
|
|
|
|
|
|
|
|
|
| 2 |
from datetime import datetime, timedelta
|
| 3 |
from typing import Optional
|
| 4 |
|
| 5 |
+
import jwt
|
| 6 |
+
from fastapi import HTTPException, Security
|
| 7 |
+
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
|
| 8 |
+
|
| 9 |
security = HTTPBearer()
|
| 10 |
|
| 11 |
|
src/llmguardian/cli/cli_interface.py
CHANGED
|
@@ -3,21 +3,22 @@ LLMGuardian CLI Interface
|
|
| 3 |
Command-line interface for the LLMGuardian security tool.
|
| 4 |
"""
|
| 5 |
|
| 6 |
-
import click
|
| 7 |
import json
|
| 8 |
import logging
|
| 9 |
-
from typing import Optional, Dict
|
| 10 |
from pathlib import Path
|
| 11 |
-
from
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
from rich import print as rprint
|
| 15 |
-
from rich.logging import RichHandler
|
| 16 |
from prompt_injection_scanner import (
|
| 17 |
-
PromptInjectionScanner,
|
| 18 |
InjectionPattern,
|
| 19 |
InjectionType,
|
|
|
|
| 20 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
# Set up logging with rich
|
| 23 |
logging.basicConfig(
|
|
|
|
| 3 |
Command-line interface for the LLMGuardian security tool.
|
| 4 |
"""
|
| 5 |
|
|
|
|
| 6 |
import json
|
| 7 |
import logging
|
|
|
|
| 8 |
from pathlib import Path
|
| 9 |
+
from typing import Dict, Optional
|
| 10 |
+
|
| 11 |
+
import click
|
|
|
|
|
|
|
| 12 |
from prompt_injection_scanner import (
|
|
|
|
| 13 |
InjectionPattern,
|
| 14 |
InjectionType,
|
| 15 |
+
PromptInjectionScanner,
|
| 16 |
)
|
| 17 |
+
from rich import print as rprint
|
| 18 |
+
from rich.console import Console
|
| 19 |
+
from rich.logging import RichHandler
|
| 20 |
+
from rich.panel import Panel
|
| 21 |
+
from rich.table import Table
|
| 22 |
|
| 23 |
# Set up logging with rich
|
| 24 |
logging.basicConfig(
|
src/llmguardian/core/__init__.py
CHANGED
|
@@ -2,9 +2,9 @@
|
|
| 2 |
core/__init__.py - Core module initialization for LLMGuardian
|
| 3 |
"""
|
| 4 |
|
| 5 |
-
from typing import Dict, Any, Optional
|
| 6 |
import logging
|
| 7 |
from pathlib import Path
|
|
|
|
| 8 |
|
| 9 |
# Version information
|
| 10 |
__version__ = "1.0.0"
|
|
@@ -12,29 +12,29 @@ __author__ = "dewitt4"
|
|
| 12 |
__license__ = "Apache-2.0"
|
| 13 |
|
| 14 |
# Core components
|
| 15 |
-
from .config import
|
| 16 |
from .exceptions import (
|
| 17 |
-
LLMGuardianError,
|
| 18 |
-
SecurityError,
|
| 19 |
-
ValidationError,
|
| 20 |
ConfigurationError,
|
|
|
|
| 21 |
PromptInjectionError,
|
| 22 |
RateLimitError,
|
|
|
|
|
|
|
| 23 |
)
|
| 24 |
-
from .logger import
|
| 25 |
from .rate_limiter import (
|
| 26 |
-
RateLimiter,
|
| 27 |
RateLimit,
|
|
|
|
| 28 |
RateLimitType,
|
| 29 |
TokenBucket,
|
| 30 |
create_rate_limiter,
|
| 31 |
)
|
| 32 |
from .security import (
|
| 33 |
-
SecurityService,
|
| 34 |
SecurityContext,
|
| 35 |
-
SecurityPolicy,
|
| 36 |
SecurityMetrics,
|
| 37 |
SecurityMonitor,
|
|
|
|
|
|
|
| 38 |
)
|
| 39 |
|
| 40 |
# Initialize logging
|
|
|
|
| 2 |
core/__init__.py - Core module initialization for LLMGuardian
|
| 3 |
"""
|
| 4 |
|
|
|
|
| 5 |
import logging
|
| 6 |
from pathlib import Path
|
| 7 |
+
from typing import Any, Dict, Optional
|
| 8 |
|
| 9 |
# Version information
|
| 10 |
__version__ = "1.0.0"
|
|
|
|
| 12 |
__license__ = "Apache-2.0"
|
| 13 |
|
| 14 |
# Core components
|
| 15 |
+
from .config import APIConfig, Config, LoggingConfig, MonitoringConfig, SecurityConfig
|
| 16 |
from .exceptions import (
|
|
|
|
|
|
|
|
|
|
| 17 |
ConfigurationError,
|
| 18 |
+
LLMGuardianError,
|
| 19 |
PromptInjectionError,
|
| 20 |
RateLimitError,
|
| 21 |
+
SecurityError,
|
| 22 |
+
ValidationError,
|
| 23 |
)
|
| 24 |
+
from .logger import AuditLogger, SecurityLogger
|
| 25 |
from .rate_limiter import (
|
|
|
|
| 26 |
RateLimit,
|
| 27 |
+
RateLimiter,
|
| 28 |
RateLimitType,
|
| 29 |
TokenBucket,
|
| 30 |
create_rate_limiter,
|
| 31 |
)
|
| 32 |
from .security import (
|
|
|
|
| 33 |
SecurityContext,
|
|
|
|
| 34 |
SecurityMetrics,
|
| 35 |
SecurityMonitor,
|
| 36 |
+
SecurityPolicy,
|
| 37 |
+
SecurityService,
|
| 38 |
)
|
| 39 |
|
| 40 |
# Initialize logging
|
src/llmguardian/core/config.py
CHANGED
|
@@ -2,19 +2,21 @@
|
|
| 2 |
core/config.py - Configuration management for LLMGuardian
|
| 3 |
"""
|
| 4 |
|
| 5 |
-
import os
|
| 6 |
-
import yaml
|
| 7 |
import json
|
| 8 |
-
from pathlib import Path
|
| 9 |
-
from typing import Dict, Any, Optional, List
|
| 10 |
-
from dataclasses import dataclass, asdict, field
|
| 11 |
import logging
|
| 12 |
-
|
| 13 |
import threading
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
from .exceptions import (
|
| 15 |
ConfigLoadError,
|
| 16 |
-
ConfigValidationError,
|
| 17 |
ConfigurationNotFoundError,
|
|
|
|
| 18 |
)
|
| 19 |
from .logger import SecurityLogger
|
| 20 |
|
|
|
|
| 2 |
core/config.py - Configuration management for LLMGuardian
|
| 3 |
"""
|
| 4 |
|
|
|
|
|
|
|
| 5 |
import json
|
|
|
|
|
|
|
|
|
|
| 6 |
import logging
|
| 7 |
+
import os
|
| 8 |
import threading
|
| 9 |
+
from dataclasses import asdict, dataclass, field
|
| 10 |
+
from enum import Enum
|
| 11 |
+
from pathlib import Path
|
| 12 |
+
from typing import Any, Dict, List, Optional
|
| 13 |
+
|
| 14 |
+
import yaml
|
| 15 |
+
|
| 16 |
from .exceptions import (
|
| 17 |
ConfigLoadError,
|
|
|
|
| 18 |
ConfigurationNotFoundError,
|
| 19 |
+
ConfigValidationError,
|
| 20 |
)
|
| 21 |
from .logger import SecurityLogger
|
| 22 |
|
src/llmguardian/core/events.py
CHANGED
|
@@ -2,13 +2,14 @@
|
|
| 2 |
core/events.py - Event handling system for LLMGuardian
|
| 3 |
"""
|
| 4 |
|
| 5 |
-
from typing import Dict, List, Callable, Any, Optional
|
| 6 |
-
from datetime import datetime
|
| 7 |
import threading
|
| 8 |
from dataclasses import dataclass
|
|
|
|
| 9 |
from enum import Enum
|
| 10 |
-
from
|
|
|
|
| 11 |
from .exceptions import LLMGuardianError
|
|
|
|
| 12 |
|
| 13 |
|
| 14 |
class EventType(Enum):
|
|
|
|
| 2 |
core/events.py - Event handling system for LLMGuardian
|
| 3 |
"""
|
| 4 |
|
|
|
|
|
|
|
| 5 |
import threading
|
| 6 |
from dataclasses import dataclass
|
| 7 |
+
from datetime import datetime
|
| 8 |
from enum import Enum
|
| 9 |
+
from typing import Any, Callable, Dict, List, Optional
|
| 10 |
+
|
| 11 |
from .exceptions import LLMGuardianError
|
| 12 |
+
from .logger import SecurityLogger
|
| 13 |
|
| 14 |
|
| 15 |
class EventType(Enum):
|
src/llmguardian/core/exceptions.py
CHANGED
|
@@ -2,11 +2,11 @@
|
|
| 2 |
core/exceptions.py - Custom exceptions for LLMGuardian
|
| 3 |
"""
|
| 4 |
|
| 5 |
-
from typing import Dict, Any, Optional
|
| 6 |
-
from dataclasses import dataclass
|
| 7 |
-
import traceback
|
| 8 |
import logging
|
|
|
|
|
|
|
| 9 |
from datetime import datetime
|
|
|
|
| 10 |
|
| 11 |
|
| 12 |
@dataclass
|
|
|
|
| 2 |
core/exceptions.py - Custom exceptions for LLMGuardian
|
| 3 |
"""
|
| 4 |
|
|
|
|
|
|
|
|
|
|
| 5 |
import logging
|
| 6 |
+
import traceback
|
| 7 |
+
from dataclasses import dataclass
|
| 8 |
from datetime import datetime
|
| 9 |
+
from typing import Any, Dict, Optional
|
| 10 |
|
| 11 |
|
| 12 |
@dataclass
|
src/llmguardian/core/logger.py
CHANGED
|
@@ -2,12 +2,12 @@
|
|
| 2 |
core/logger.py - Logging configuration for LLMGuardian
|
| 3 |
"""
|
| 4 |
|
|
|
|
| 5 |
import logging
|
| 6 |
import logging.handlers
|
| 7 |
-
import json
|
| 8 |
from datetime import datetime
|
| 9 |
from pathlib import Path
|
| 10 |
-
from typing import
|
| 11 |
|
| 12 |
|
| 13 |
class SecurityLogger:
|
|
|
|
| 2 |
core/logger.py - Logging configuration for LLMGuardian
|
| 3 |
"""
|
| 4 |
|
| 5 |
+
import json
|
| 6 |
import logging
|
| 7 |
import logging.handlers
|
|
|
|
| 8 |
from datetime import datetime
|
| 9 |
from pathlib import Path
|
| 10 |
+
from typing import Any, Dict, Optional
|
| 11 |
|
| 12 |
|
| 13 |
class SecurityLogger:
|
src/llmguardian/core/monitoring.py
CHANGED
|
@@ -2,14 +2,15 @@
|
|
| 2 |
core/monitoring.py - Monitoring system for LLMGuardian
|
| 3 |
"""
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
from dataclasses import dataclass
|
| 8 |
import threading
|
| 9 |
import time
|
| 10 |
-
import json
|
| 11 |
from collections import deque
|
| 12 |
-
import
|
|
|
|
|
|
|
|
|
|
| 13 |
from .logger import SecurityLogger
|
| 14 |
|
| 15 |
|
|
|
|
| 2 |
core/monitoring.py - Monitoring system for LLMGuardian
|
| 3 |
"""
|
| 4 |
|
| 5 |
+
import json
|
| 6 |
+
import statistics
|
|
|
|
| 7 |
import threading
|
| 8 |
import time
|
|
|
|
| 9 |
from collections import deque
|
| 10 |
+
from dataclasses import dataclass
|
| 11 |
+
from datetime import datetime, timedelta
|
| 12 |
+
from typing import Any, Dict, List, Optional
|
| 13 |
+
|
| 14 |
from .logger import SecurityLogger
|
| 15 |
|
| 16 |
|
src/llmguardian/core/rate_limiter.py
CHANGED
|
@@ -2,18 +2,20 @@
|
|
| 2 |
core/rate_limiter.py - Rate limiting implementation for LLMGuardian
|
| 3 |
"""
|
| 4 |
|
| 5 |
-
import
|
| 6 |
import os
|
| 7 |
-
import psutil
|
| 8 |
-
from datetime import datetime, timedelta
|
| 9 |
-
from typing import Dict, Optional, List, Tuple, Any
|
| 10 |
import threading
|
|
|
|
| 11 |
from dataclasses import dataclass
|
|
|
|
| 12 |
from enum import Enum
|
| 13 |
-
import
|
| 14 |
-
|
| 15 |
-
|
|
|
|
| 16 |
from .events import EventManager, EventType
|
|
|
|
|
|
|
| 17 |
|
| 18 |
|
| 19 |
class RateLimitType(Enum):
|
|
@@ -327,8 +329,8 @@ def create_rate_limiter(
|
|
| 327 |
|
| 328 |
if __name__ == "__main__":
|
| 329 |
# Example usage
|
| 330 |
-
from .logger import setup_logging
|
| 331 |
from .events import create_event_manager
|
|
|
|
| 332 |
|
| 333 |
security_logger, _ = setup_logging()
|
| 334 |
event_manager = create_event_manager(security_logger)
|
|
|
|
| 2 |
core/rate_limiter.py - Rate limiting implementation for LLMGuardian
|
| 3 |
"""
|
| 4 |
|
| 5 |
+
import json
|
| 6 |
import os
|
|
|
|
|
|
|
|
|
|
| 7 |
import threading
|
| 8 |
+
import time
|
| 9 |
from dataclasses import dataclass
|
| 10 |
+
from datetime import datetime, timedelta
|
| 11 |
from enum import Enum
|
| 12 |
+
from typing import Any, Dict, List, Optional, Tuple
|
| 13 |
+
|
| 14 |
+
import psutil
|
| 15 |
+
|
| 16 |
from .events import EventManager, EventType
|
| 17 |
+
from .exceptions import RateLimitError
|
| 18 |
+
from .logger import SecurityLogger
|
| 19 |
|
| 20 |
|
| 21 |
class RateLimitType(Enum):
|
|
|
|
| 329 |
|
| 330 |
if __name__ == "__main__":
|
| 331 |
# Example usage
|
|
|
|
| 332 |
from .events import create_event_manager
|
| 333 |
+
from .logger import setup_logging
|
| 334 |
|
| 335 |
security_logger, _ = setup_logging()
|
| 336 |
event_manager = create_event_manager(security_logger)
|
src/llmguardian/core/scanners/prompt_injection_scanner.py
CHANGED
|
@@ -2,16 +2,17 @@
|
|
| 2 |
core/scanners/prompt_injection_scanner.py - Prompt injection detection for LLMGuardian
|
| 3 |
"""
|
| 4 |
|
| 5 |
-
import re
|
| 6 |
-
from dataclasses import dataclass
|
| 7 |
-
from enum import Enum
|
| 8 |
-
from typing import List, Optional, Dict, Set, Pattern
|
| 9 |
import json
|
| 10 |
import logging
|
|
|
|
|
|
|
| 11 |
from datetime import datetime
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
from ..exceptions import PromptInjectionError
|
| 13 |
from ..logger import SecurityLogger
|
| 14 |
-
from ..config import Config
|
| 15 |
|
| 16 |
|
| 17 |
class InjectionType(Enum):
|
|
|
|
| 2 |
core/scanners/prompt_injection_scanner.py - Prompt injection detection for LLMGuardian
|
| 3 |
"""
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
import json
|
| 6 |
import logging
|
| 7 |
+
import re
|
| 8 |
+
from dataclasses import dataclass
|
| 9 |
from datetime import datetime
|
| 10 |
+
from enum import Enum
|
| 11 |
+
from typing import Dict, List, Optional, Pattern, Set
|
| 12 |
+
|
| 13 |
+
from ..config import Config
|
| 14 |
from ..exceptions import PromptInjectionError
|
| 15 |
from ..logger import SecurityLogger
|
|
|
|
| 16 |
|
| 17 |
|
| 18 |
class InjectionType(Enum):
|
src/llmguardian/core/security.py
CHANGED
|
@@ -5,12 +5,14 @@ core/security.py - Core security services for LLMGuardian
|
|
| 5 |
import hashlib
|
| 6 |
import hmac
|
| 7 |
import secrets
|
| 8 |
-
from typing import Optional, Dict, Any, List
|
| 9 |
from dataclasses import dataclass
|
| 10 |
from datetime import datetime, timedelta
|
|
|
|
|
|
|
| 11 |
import jwt
|
|
|
|
| 12 |
from .config import Config
|
| 13 |
-
from .logger import
|
| 14 |
|
| 15 |
|
| 16 |
@dataclass
|
|
|
|
| 5 |
import hashlib
|
| 6 |
import hmac
|
| 7 |
import secrets
|
|
|
|
| 8 |
from dataclasses import dataclass
|
| 9 |
from datetime import datetime, timedelta
|
| 10 |
+
from typing import Any, Dict, List, Optional
|
| 11 |
+
|
| 12 |
import jwt
|
| 13 |
+
|
| 14 |
from .config import Config
|
| 15 |
+
from .logger import AuditLogger, SecurityLogger
|
| 16 |
|
| 17 |
|
| 18 |
@dataclass
|
src/llmguardian/core/validation.py
CHANGED
|
@@ -2,10 +2,11 @@
|
|
| 2 |
core/validation.py - Input/Output validation for LLMGuardian
|
| 3 |
"""
|
| 4 |
|
|
|
|
| 5 |
import re
|
| 6 |
-
from typing import Dict, Any, List, Optional, Tuple
|
| 7 |
from dataclasses import dataclass
|
| 8 |
-
import
|
|
|
|
| 9 |
from .logger import SecurityLogger
|
| 10 |
|
| 11 |
|
|
|
|
| 2 |
core/validation.py - Input/Output validation for LLMGuardian
|
| 3 |
"""
|
| 4 |
|
| 5 |
+
import json
|
| 6 |
import re
|
|
|
|
| 7 |
from dataclasses import dataclass
|
| 8 |
+
from typing import Any, Dict, List, Optional, Tuple
|
| 9 |
+
|
| 10 |
from .logger import SecurityLogger
|
| 11 |
|
| 12 |
|
src/llmguardian/dashboard/app.py
CHANGED
|
@@ -1,26 +1,27 @@
|
|
| 1 |
# src/llmguardian/dashboard/app.py
|
| 2 |
|
| 3 |
-
import streamlit as st
|
| 4 |
-
import plotly.express as px
|
| 5 |
-
import plotly.graph_objects as go
|
| 6 |
-
import pandas as pd
|
| 7 |
-
import numpy as np
|
| 8 |
-
from datetime import datetime, timedelta
|
| 9 |
-
from typing import Dict, List, Any, Optional
|
| 10 |
-
import sys
|
| 11 |
import os
|
|
|
|
|
|
|
| 12 |
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
# Add parent directory to path for imports
|
| 15 |
sys.path.insert(0, str(Path(__file__).parent.parent.parent))
|
| 16 |
|
| 17 |
try:
|
| 18 |
from llmguardian.core.config import Config
|
|
|
|
| 19 |
from llmguardian.data.privacy_guard import PrivacyGuard
|
| 20 |
-
from llmguardian.monitors.usage_monitor import UsageMonitor
|
| 21 |
from llmguardian.monitors.threat_detector import ThreatDetector, ThreatLevel
|
|
|
|
| 22 |
from llmguardian.scanners.prompt_injection_scanner import PromptInjectionScanner
|
| 23 |
-
from llmguardian.core.logger import setup_logging
|
| 24 |
except ImportError:
|
| 25 |
# Fallback for demo mode
|
| 26 |
Config = None
|
|
|
|
| 1 |
# src/llmguardian/dashboard/app.py
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
import os
|
| 4 |
+
import sys
|
| 5 |
+
from datetime import datetime, timedelta
|
| 6 |
from pathlib import Path
|
| 7 |
+
from typing import Any, Dict, List, Optional
|
| 8 |
+
|
| 9 |
+
import numpy as np
|
| 10 |
+
import pandas as pd
|
| 11 |
+
import plotly.express as px
|
| 12 |
+
import plotly.graph_objects as go
|
| 13 |
+
import streamlit as st
|
| 14 |
|
| 15 |
# Add parent directory to path for imports
|
| 16 |
sys.path.insert(0, str(Path(__file__).parent.parent.parent))
|
| 17 |
|
| 18 |
try:
|
| 19 |
from llmguardian.core.config import Config
|
| 20 |
+
from llmguardian.core.logger import setup_logging
|
| 21 |
from llmguardian.data.privacy_guard import PrivacyGuard
|
|
|
|
| 22 |
from llmguardian.monitors.threat_detector import ThreatDetector, ThreatLevel
|
| 23 |
+
from llmguardian.monitors.usage_monitor import UsageMonitor
|
| 24 |
from llmguardian.scanners.prompt_injection_scanner import PromptInjectionScanner
|
|
|
|
| 25 |
except ImportError:
|
| 26 |
# Fallback for demo mode
|
| 27 |
Config = None
|
src/llmguardian/data/leak_detector.py
CHANGED
|
@@ -2,15 +2,16 @@
|
|
| 2 |
data/leak_detector.py - Data leakage detection and prevention
|
| 3 |
"""
|
| 4 |
|
|
|
|
| 5 |
import re
|
| 6 |
-
from
|
| 7 |
from dataclasses import dataclass
|
| 8 |
from datetime import datetime
|
| 9 |
from enum import Enum
|
| 10 |
-
import
|
| 11 |
-
|
| 12 |
-
from ..core.logger import SecurityLogger
|
| 13 |
from ..core.exceptions import SecurityError
|
|
|
|
| 14 |
|
| 15 |
|
| 16 |
class LeakageType(Enum):
|
|
|
|
| 2 |
data/leak_detector.py - Data leakage detection and prevention
|
| 3 |
"""
|
| 4 |
|
| 5 |
+
import hashlib
|
| 6 |
import re
|
| 7 |
+
from collections import defaultdict
|
| 8 |
from dataclasses import dataclass
|
| 9 |
from datetime import datetime
|
| 10 |
from enum import Enum
|
| 11 |
+
from typing import Any, Dict, List, Optional, Set
|
| 12 |
+
|
|
|
|
| 13 |
from ..core.exceptions import SecurityError
|
| 14 |
+
from ..core.logger import SecurityLogger
|
| 15 |
|
| 16 |
|
| 17 |
class LeakageType(Enum):
|
src/llmguardian/data/poison_detector.py
CHANGED
|
@@ -2,16 +2,18 @@
|
|
| 2 |
data/poison_detector.py - Detection and prevention of data poisoning attacks
|
| 3 |
"""
|
| 4 |
|
| 5 |
-
import
|
| 6 |
-
|
|
|
|
| 7 |
from dataclasses import dataclass
|
| 8 |
from datetime import datetime
|
| 9 |
from enum import Enum
|
| 10 |
-
from
|
| 11 |
-
|
| 12 |
-
import
|
| 13 |
-
|
| 14 |
from ..core.exceptions import SecurityError
|
|
|
|
| 15 |
|
| 16 |
|
| 17 |
class PoisonType(Enum):
|
|
|
|
| 2 |
data/poison_detector.py - Detection and prevention of data poisoning attacks
|
| 3 |
"""
|
| 4 |
|
| 5 |
+
import hashlib
|
| 6 |
+
import json
|
| 7 |
+
from collections import defaultdict
|
| 8 |
from dataclasses import dataclass
|
| 9 |
from datetime import datetime
|
| 10 |
from enum import Enum
|
| 11 |
+
from typing import Any, Dict, List, Optional, Set, Tuple
|
| 12 |
+
|
| 13 |
+
import numpy as np
|
| 14 |
+
|
| 15 |
from ..core.exceptions import SecurityError
|
| 16 |
+
from ..core.logger import SecurityLogger
|
| 17 |
|
| 18 |
|
| 19 |
class PoisonType(Enum):
|
src/llmguardian/data/privacy_guard.py
CHANGED
|
@@ -2,19 +2,19 @@
|
|
| 2 |
data/privacy_guard.py - Privacy protection and enforcement
|
| 3 |
"""
|
| 4 |
|
| 5 |
-
# Add these imports at the top
|
| 6 |
-
from typing import Dict, List, Optional, Any, Set, Union
|
| 7 |
-
from dataclasses import dataclass, field
|
| 8 |
-
from datetime import datetime
|
| 9 |
-
from enum import Enum
|
| 10 |
-
import re
|
| 11 |
import hashlib
|
| 12 |
import json
|
|
|
|
| 13 |
import threading
|
| 14 |
import time
|
| 15 |
from collections import defaultdict
|
| 16 |
-
from
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
from ..core.exceptions import SecurityError
|
|
|
|
| 18 |
|
| 19 |
|
| 20 |
class PrivacyLevel(Enum):
|
|
|
|
| 2 |
data/privacy_guard.py - Privacy protection and enforcement
|
| 3 |
"""
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
import hashlib
|
| 6 |
import json
|
| 7 |
+
import re
|
| 8 |
import threading
|
| 9 |
import time
|
| 10 |
from collections import defaultdict
|
| 11 |
+
from dataclasses import dataclass, field
|
| 12 |
+
from datetime import datetime
|
| 13 |
+
from enum import Enum
|
| 14 |
+
from typing import Any, Dict, List, Optional, Set, Union
|
| 15 |
+
|
| 16 |
from ..core.exceptions import SecurityError
|
| 17 |
+
from ..core.logger import SecurityLogger
|
| 18 |
|
| 19 |
|
| 20 |
class PrivacyLevel(Enum):
|
src/llmguardian/defenders/__init__.py
CHANGED
|
@@ -2,11 +2,11 @@
|
|
| 2 |
defenders/__init__.py - Security defenders initialization
|
| 3 |
"""
|
| 4 |
|
|
|
|
|
|
|
| 5 |
from .input_sanitizer import InputSanitizer
|
| 6 |
from .output_validator import OutputValidator
|
| 7 |
from .token_validator import TokenValidator
|
| 8 |
-
from .content_filter import ContentFilter
|
| 9 |
-
from .context_validator import ContextValidator
|
| 10 |
|
| 11 |
__all__ = [
|
| 12 |
"InputSanitizer",
|
|
|
|
| 2 |
defenders/__init__.py - Security defenders initialization
|
| 3 |
"""
|
| 4 |
|
| 5 |
+
from .content_filter import ContentFilter
|
| 6 |
+
from .context_validator import ContextValidator
|
| 7 |
from .input_sanitizer import InputSanitizer
|
| 8 |
from .output_validator import OutputValidator
|
| 9 |
from .token_validator import TokenValidator
|
|
|
|
|
|
|
| 10 |
|
| 11 |
__all__ = [
|
| 12 |
"InputSanitizer",
|
src/llmguardian/defenders/content_filter.py
CHANGED
|
@@ -3,11 +3,12 @@ defenders/content_filter.py - Content filtering and moderation
|
|
| 3 |
"""
|
| 4 |
|
| 5 |
import re
|
| 6 |
-
from typing import Dict, List, Optional, Any, Set
|
| 7 |
from dataclasses import dataclass
|
| 8 |
from enum import Enum
|
| 9 |
-
from
|
|
|
|
| 10 |
from ..core.exceptions import ValidationError
|
|
|
|
| 11 |
|
| 12 |
|
| 13 |
class ContentCategory(Enum):
|
|
|
|
| 3 |
"""
|
| 4 |
|
| 5 |
import re
|
|
|
|
| 6 |
from dataclasses import dataclass
|
| 7 |
from enum import Enum
|
| 8 |
+
from typing import Any, Dict, List, Optional, Set
|
| 9 |
+
|
| 10 |
from ..core.exceptions import ValidationError
|
| 11 |
+
from ..core.logger import SecurityLogger
|
| 12 |
|
| 13 |
|
| 14 |
class ContentCategory(Enum):
|
src/llmguardian/defenders/context_validator.py
CHANGED
|
@@ -2,12 +2,13 @@
|
|
| 2 |
defenders/context_validator.py - Context validation for LLM interactions
|
| 3 |
"""
|
| 4 |
|
| 5 |
-
|
| 6 |
from dataclasses import dataclass
|
| 7 |
from datetime import datetime
|
| 8 |
-
import
|
| 9 |
-
|
| 10 |
from ..core.exceptions import ValidationError
|
|
|
|
| 11 |
|
| 12 |
|
| 13 |
@dataclass
|
|
|
|
| 2 |
defenders/context_validator.py - Context validation for LLM interactions
|
| 3 |
"""
|
| 4 |
|
| 5 |
+
import hashlib
|
| 6 |
from dataclasses import dataclass
|
| 7 |
from datetime import datetime
|
| 8 |
+
from typing import Any, Dict, List, Optional
|
| 9 |
+
|
| 10 |
from ..core.exceptions import ValidationError
|
| 11 |
+
from ..core.logger import SecurityLogger
|
| 12 |
|
| 13 |
|
| 14 |
@dataclass
|
src/llmguardian/defenders/input_sanitizer.py
CHANGED
|
@@ -3,10 +3,11 @@ defenders/input_sanitizer.py - Input sanitization for LLM inputs
|
|
| 3 |
"""
|
| 4 |
|
| 5 |
import re
|
| 6 |
-
from typing import Dict, Any, List, Optional
|
| 7 |
from dataclasses import dataclass
|
| 8 |
-
from
|
|
|
|
| 9 |
from ..core.exceptions import ValidationError
|
|
|
|
| 10 |
|
| 11 |
|
| 12 |
@dataclass
|
|
|
|
| 3 |
"""
|
| 4 |
|
| 5 |
import re
|
|
|
|
| 6 |
from dataclasses import dataclass
|
| 7 |
+
from typing import Any, Dict, List, Optional
|
| 8 |
+
|
| 9 |
from ..core.exceptions import ValidationError
|
| 10 |
+
from ..core.logger import SecurityLogger
|
| 11 |
|
| 12 |
|
| 13 |
@dataclass
|
src/llmguardian/defenders/output_validator.py
CHANGED
|
@@ -3,10 +3,11 @@ defenders/output_validator.py - Output validation and sanitization
|
|
| 3 |
"""
|
| 4 |
|
| 5 |
import re
|
| 6 |
-
from typing import Dict, List, Optional, Set, Any
|
| 7 |
from dataclasses import dataclass
|
| 8 |
-
from
|
|
|
|
| 9 |
from ..core.exceptions import ValidationError
|
|
|
|
| 10 |
|
| 11 |
|
| 12 |
@dataclass
|
|
|
|
| 3 |
"""
|
| 4 |
|
| 5 |
import re
|
|
|
|
| 6 |
from dataclasses import dataclass
|
| 7 |
+
from typing import Any, Dict, List, Optional, Set
|
| 8 |
+
|
| 9 |
from ..core.exceptions import ValidationError
|
| 10 |
+
from ..core.logger import SecurityLogger
|
| 11 |
|
| 12 |
|
| 13 |
@dataclass
|
src/llmguardian/defenders/test_context_validator.py
CHANGED
|
@@ -2,10 +2,12 @@
|
|
| 2 |
tests/defenders/test_context_validator.py - Tests for context validation
|
| 3 |
"""
|
| 4 |
|
| 5 |
-
import pytest
|
| 6 |
from datetime import datetime, timedelta
|
| 7 |
-
|
|
|
|
|
|
|
| 8 |
from llmguardian.core.exceptions import ValidationError
|
|
|
|
| 9 |
|
| 10 |
|
| 11 |
@pytest.fixture
|
|
|
|
| 2 |
tests/defenders/test_context_validator.py - Tests for context validation
|
| 3 |
"""
|
| 4 |
|
|
|
|
| 5 |
from datetime import datetime, timedelta
|
| 6 |
+
|
| 7 |
+
import pytest
|
| 8 |
+
|
| 9 |
from llmguardian.core.exceptions import ValidationError
|
| 10 |
+
from llmguardian.defenders.context_validator import ContextValidator, ValidationResult
|
| 11 |
|
| 12 |
|
| 13 |
@pytest.fixture
|
src/llmguardian/defenders/token_validator.py
CHANGED
|
@@ -2,13 +2,15 @@
|
|
| 2 |
defenders/token_validator.py - Token and credential validation
|
| 3 |
"""
|
| 4 |
|
| 5 |
-
from typing import Dict, Optional, Any, List
|
| 6 |
-
from dataclasses import dataclass
|
| 7 |
import re
|
| 8 |
-
import
|
| 9 |
from datetime import datetime, timedelta
|
| 10 |
-
from
|
|
|
|
|
|
|
|
|
|
| 11 |
from ..core.exceptions import TokenValidationError
|
|
|
|
| 12 |
|
| 13 |
|
| 14 |
@dataclass
|
|
|
|
| 2 |
defenders/token_validator.py - Token and credential validation
|
| 3 |
"""
|
| 4 |
|
|
|
|
|
|
|
| 5 |
import re
|
| 6 |
+
from dataclasses import dataclass
|
| 7 |
from datetime import datetime, timedelta
|
| 8 |
+
from typing import Any, Dict, List, Optional
|
| 9 |
+
|
| 10 |
+
import jwt
|
| 11 |
+
|
| 12 |
from ..core.exceptions import TokenValidationError
|
| 13 |
+
from ..core.logger import SecurityLogger
|
| 14 |
|
| 15 |
|
| 16 |
@dataclass
|
src/llmguardian/monitors/__init__.py
CHANGED
|
@@ -2,11 +2,11 @@
|
|
| 2 |
monitors/__init__.py - Monitoring system initialization
|
| 3 |
"""
|
| 4 |
|
| 5 |
-
from .
|
| 6 |
from .behavior_monitor import BehaviorMonitor
|
| 7 |
-
from .threat_detector import ThreatDetector
|
| 8 |
from .performance_monitor import PerformanceMonitor
|
| 9 |
-
from .
|
|
|
|
| 10 |
|
| 11 |
__all__ = [
|
| 12 |
"UsageMonitor",
|
|
|
|
| 2 |
monitors/__init__.py - Monitoring system initialization
|
| 3 |
"""
|
| 4 |
|
| 5 |
+
from .audit_monitor import AuditMonitor
|
| 6 |
from .behavior_monitor import BehaviorMonitor
|
|
|
|
| 7 |
from .performance_monitor import PerformanceMonitor
|
| 8 |
+
from .threat_detector import ThreatDetector
|
| 9 |
+
from .usage_monitor import UsageMonitor
|
| 10 |
|
| 11 |
__all__ = [
|
| 12 |
"UsageMonitor",
|
src/llmguardian/monitors/audit_monitor.py
CHANGED
|
@@ -3,15 +3,16 @@ monitors/audit_monitor.py - Audit trail and compliance monitoring
|
|
| 3 |
"""
|
| 4 |
|
| 5 |
import json
|
| 6 |
-
|
|
|
|
| 7 |
from dataclasses import dataclass
|
| 8 |
from datetime import datetime, timedelta
|
| 9 |
from enum import Enum
|
| 10 |
-
import threading
|
| 11 |
from pathlib import Path
|
| 12 |
-
from
|
| 13 |
-
|
| 14 |
from ..core.exceptions import MonitoringError
|
|
|
|
| 15 |
|
| 16 |
|
| 17 |
class AuditEventType(Enum):
|
|
|
|
| 3 |
"""
|
| 4 |
|
| 5 |
import json
|
| 6 |
+
import threading
|
| 7 |
+
from collections import defaultdict
|
| 8 |
from dataclasses import dataclass
|
| 9 |
from datetime import datetime, timedelta
|
| 10 |
from enum import Enum
|
|
|
|
| 11 |
from pathlib import Path
|
| 12 |
+
from typing import Any, Dict, List, Optional, Set
|
| 13 |
+
|
| 14 |
from ..core.exceptions import MonitoringError
|
| 15 |
+
from ..core.logger import SecurityLogger
|
| 16 |
|
| 17 |
|
| 18 |
class AuditEventType(Enum):
|
src/llmguardian/monitors/behavior_monitor.py
CHANGED
|
@@ -2,11 +2,12 @@
|
|
| 2 |
monitors/behavior_monitor.py - LLM behavior monitoring
|
| 3 |
"""
|
| 4 |
|
| 5 |
-
from typing import Dict, List, Optional, Any
|
| 6 |
from dataclasses import dataclass
|
| 7 |
from datetime import datetime
|
| 8 |
-
from
|
|
|
|
| 9 |
from ..core.exceptions import MonitoringError
|
|
|
|
| 10 |
|
| 11 |
|
| 12 |
@dataclass
|
|
|
|
| 2 |
monitors/behavior_monitor.py - LLM behavior monitoring
|
| 3 |
"""
|
| 4 |
|
|
|
|
| 5 |
from dataclasses import dataclass
|
| 6 |
from datetime import datetime
|
| 7 |
+
from typing import Any, Dict, List, Optional
|
| 8 |
+
|
| 9 |
from ..core.exceptions import MonitoringError
|
| 10 |
+
from ..core.logger import SecurityLogger
|
| 11 |
|
| 12 |
|
| 13 |
@dataclass
|
src/llmguardian/monitors/performance_monitor.py
CHANGED
|
@@ -2,15 +2,16 @@
|
|
| 2 |
monitors/performance_monitor.py - LLM performance monitoring
|
| 3 |
"""
|
| 4 |
|
| 5 |
-
import time
|
| 6 |
import threading
|
| 7 |
-
|
|
|
|
| 8 |
from dataclasses import dataclass
|
| 9 |
from datetime import datetime, timedelta
|
| 10 |
from statistics import mean, median, stdev
|
| 11 |
-
from
|
| 12 |
-
|
| 13 |
from ..core.exceptions import MonitoringError
|
|
|
|
| 14 |
|
| 15 |
|
| 16 |
@dataclass
|
|
|
|
| 2 |
monitors/performance_monitor.py - LLM performance monitoring
|
| 3 |
"""
|
| 4 |
|
|
|
|
| 5 |
import threading
|
| 6 |
+
import time
|
| 7 |
+
from collections import deque
|
| 8 |
from dataclasses import dataclass
|
| 9 |
from datetime import datetime, timedelta
|
| 10 |
from statistics import mean, median, stdev
|
| 11 |
+
from typing import Any, Dict, List, Optional
|
| 12 |
+
|
| 13 |
from ..core.exceptions import MonitoringError
|
| 14 |
+
from ..core.logger import SecurityLogger
|
| 15 |
|
| 16 |
|
| 17 |
@dataclass
|
src/llmguardian/monitors/threat_detector.py
CHANGED
|
@@ -2,14 +2,15 @@
|
|
| 2 |
monitors/threat_detector.py - Real-time threat detection for LLM applications
|
| 3 |
"""
|
| 4 |
|
| 5 |
-
|
|
|
|
| 6 |
from dataclasses import dataclass
|
| 7 |
from datetime import datetime, timedelta
|
| 8 |
from enum import Enum
|
| 9 |
-
import
|
| 10 |
-
|
| 11 |
-
from ..core.logger import SecurityLogger
|
| 12 |
from ..core.exceptions import MonitoringError
|
|
|
|
| 13 |
|
| 14 |
|
| 15 |
class ThreatLevel(Enum):
|
|
|
|
| 2 |
monitors/threat_detector.py - Real-time threat detection for LLM applications
|
| 3 |
"""
|
| 4 |
|
| 5 |
+
import threading
|
| 6 |
+
from collections import defaultdict
|
| 7 |
from dataclasses import dataclass
|
| 8 |
from datetime import datetime, timedelta
|
| 9 |
from enum import Enum
|
| 10 |
+
from typing import Any, Dict, List, Optional, Set
|
| 11 |
+
|
|
|
|
| 12 |
from ..core.exceptions import MonitoringError
|
| 13 |
+
from ..core.logger import SecurityLogger
|
| 14 |
|
| 15 |
|
| 16 |
class ThreatLevel(Enum):
|
src/llmguardian/monitors/usage_monitor.py
CHANGED
|
@@ -2,14 +2,16 @@
|
|
| 2 |
monitors/usage_monitor.py - Resource usage monitoring
|
| 3 |
"""
|
| 4 |
|
| 5 |
-
import time
|
| 6 |
-
import psutil
|
| 7 |
import threading
|
| 8 |
-
|
| 9 |
from dataclasses import dataclass
|
| 10 |
from datetime import datetime
|
| 11 |
-
from
|
|
|
|
|
|
|
|
|
|
| 12 |
from ..core.exceptions import MonitoringError
|
|
|
|
| 13 |
|
| 14 |
|
| 15 |
@dataclass
|
|
|
|
| 2 |
monitors/usage_monitor.py - Resource usage monitoring
|
| 3 |
"""
|
| 4 |
|
|
|
|
|
|
|
| 5 |
import threading
|
| 6 |
+
import time
|
| 7 |
from dataclasses import dataclass
|
| 8 |
from datetime import datetime
|
| 9 |
+
from typing import Dict, List, Optional
|
| 10 |
+
|
| 11 |
+
import psutil
|
| 12 |
+
|
| 13 |
from ..core.exceptions import MonitoringError
|
| 14 |
+
from ..core.logger import SecurityLogger
|
| 15 |
|
| 16 |
|
| 17 |
@dataclass
|
src/llmguardian/scanners/prompt_injection_scanner.py
CHANGED
|
@@ -3,12 +3,12 @@ LLMGuardian Prompt Injection Scanner
|
|
| 3 |
Core module for detecting and preventing prompt injection attacks in LLM applications.
|
| 4 |
"""
|
| 5 |
|
|
|
|
| 6 |
import re
|
|
|
|
| 7 |
from dataclasses import dataclass
|
| 8 |
from enum import Enum
|
| 9 |
-
from typing import List, Optional,
|
| 10 |
-
import logging
|
| 11 |
-
from abc import ABC, abstractmethod
|
| 12 |
|
| 13 |
# Configure logging
|
| 14 |
logging.basicConfig(level=logging.INFO)
|
|
|
|
| 3 |
Core module for detecting and preventing prompt injection attacks in LLM applications.
|
| 4 |
"""
|
| 5 |
|
| 6 |
+
import logging
|
| 7 |
import re
|
| 8 |
+
from abc import ABC, abstractmethod
|
| 9 |
from dataclasses import dataclass
|
| 10 |
from enum import Enum
|
| 11 |
+
from typing import Dict, List, Optional, Tuple
|
|
|
|
|
|
|
| 12 |
|
| 13 |
# Configure logging
|
| 14 |
logging.basicConfig(level=logging.INFO)
|
src/llmguardian/vectors/__init__.py
CHANGED
|
@@ -3,8 +3,8 @@ vectors/__init__.py - Vector security initialization
|
|
| 3 |
"""
|
| 4 |
|
| 5 |
from .embedding_validator import EmbeddingValidator
|
| 6 |
-
from .vector_scanner import VectorScanner
|
| 7 |
from .retrieval_guard import RetrievalGuard
|
| 8 |
from .storage_validator import StorageValidator
|
|
|
|
| 9 |
|
| 10 |
__all__ = ["EmbeddingValidator", "VectorScanner", "RetrievalGuard", "StorageValidator"]
|
|
|
|
| 3 |
"""
|
| 4 |
|
| 5 |
from .embedding_validator import EmbeddingValidator
|
|
|
|
| 6 |
from .retrieval_guard import RetrievalGuard
|
| 7 |
from .storage_validator import StorageValidator
|
| 8 |
+
from .vector_scanner import VectorScanner
|
| 9 |
|
| 10 |
__all__ = ["EmbeddingValidator", "VectorScanner", "RetrievalGuard", "StorageValidator"]
|