feat: Comprehensive security upgrades and ML stack modernization#89
Merged
davidamacey merged 2 commits intomasterfrom Oct 12, 2025
Merged
feat: Comprehensive security upgrades and ML stack modernization#89davidamacey merged 2 commits intomasterfrom
davidamacey merged 2 commits intomasterfrom
Conversation
…tructure
Implement enterprise-grade security scanning and Docker image hardening with
GitHub Actions CI/CD integration, pre-commit hooks, and optimized production
Dockerfiles following CIS benchmarks and NIST best practices.
## Security Scanning Infrastructure
### New Security Tools Integration
- **Hadolint**: Dockerfile linting with CIS Docker benchmark rules
- **Dockle**: Container image security scanner (CIS best practices)
- **Trivy**: Comprehensive vulnerability scanner (OS + dependencies)
- **Grype**: Additional vulnerability scanning with SBOM generation
- **Syft**: Software Bill of Materials (SBOM) generation
### GitHub Actions Workflows
- `.github/workflows/security-scan.yml` - Multi-stage security scanning
* Runs on PR, push to main, and nightly schedule
* Uploads SARIF reports to GitHub Security tab
* Scans both backend and frontend images
* Fails on CRITICAL vulnerabilities in production
- `.github/workflows/pre-commit.yml` - Pre-commit hook validation
* Validates all pre-commit hooks pass in CI
* Runs on PR and push to main
* Ensures consistent code quality standards
### Pre-commit Configuration
- `.pre-commit-config.yaml` - Local development hooks
* Trailing whitespace removal
* YAML syntax validation
* File size limits (500KB)
* End-of-file fixing
* Hadolint Dockerfile linting
- `.hadolint.yaml` - Hadolint configuration
* Ignore DL3008 (apt version pinning) for development
* Ignore DL3059 (multiple RUN commands) for clarity
* CIS benchmark compliance for production
### Security Scanning Script
- `scripts/security-scan.sh` - Unified security scanning utility
* Auto-detects Docker images or builds from Dockerfiles
* Runs all 5 security tools in sequence
* Generates comprehensive HTML/JSON reports
* Configurable failure thresholds (CRITICAL/HIGH/MEDIUM)
* SBOM generation for compliance audits
## Docker Security Hardening
### Password Hashing Improvements
- Upgrade from `bcrypt` to `bcrypt_sha256` to handle long passwords properly
- `bcrypt_sha256` pre-hashes with SHA256 to bypass bcrypt's 72-byte limit
- Auto-upgrade existing bcrypt hashes on user login
- Applied to both `backend/app/auth/direct_auth.py` and `backend/app/core/security.py`
### Dockerfile Optimizations
- `backend/Dockerfile.dev.optimized` - Security-hardened development image
* Remove git (not needed in containers, security risk)
* Specific CUDA toolkit version pinning
* Minimal base image layers
* Proper apt-get cleanup
- `backend/Dockerfile.prod.optimized` - Production-ready secure image
* Same hardening as dev + production optimizations
* No development dependencies
* Minimal attack surface
- `frontend/Dockerfile.prod` - Updated to nginx:alpine (smaller, more secure)
* Previous: nginx:stable-alpine
* New: nginx:alpine (latest stable with security patches)
### Configuration Fixes
- `backend/app/core/config.py` - Fix DATA_DIR default path
* Changed from hardcoded `/mnt/nvm/repos/transcribe-app/data`
* To container path `/app/data` (proper Docker volume mount)
* Prevents path errors in containerized environments
## Build System Improvements
### Docker Build Script Enhancements
- `scripts/docker-build-push.sh` - Integrated security scanning
* Auto-run security scan after each build
* Environment variables for CI/CD:
- `SKIP_SECURITY_SCAN=true` - Skip scanning (faster builds)
- `FAIL_ON_SECURITY_ISSUES=true` - Fail on any issues (CI)
- `FAIL_ON_CRITICAL=true` - Fail only on CRITICAL (strict mode)
* Reports saved to `./security-reports/`
* Enhanced documentation with security examples
### Offline Package Builder
- `scripts/build-offline-package.sh` - Auto-load HUGGINGFACE_TOKEN from .env
* Remove interactive confirmation prompt for CI/CD
* Streamlined build process for automation
* Better documentation structure
## Documentation
### Security Scanning Guide
- `docs/SECURITY_SCANNING.md` - Comprehensive security documentation
* Quick start guide for all scanning tools
* CI/CD integration instructions
* Report interpretation guidelines
* Remediation best practices
* Example configurations and workflows
### .gitignore Updates
- Exclude security reports and build artifacts
* `offline-package-build/` - Build working directory
* `security-reports/` and `security-reports-*` - Scan outputs
* Prevent sensitive scan data from being committed
## Configuration Files
- `pyproject.toml` - Python project metadata
* Project name, version, description
* Dependencies management
* Build system configuration
* Tool-specific settings (ruff, black, etc.)
## Key Benefits
✅ **Automated Security**: Continuous scanning in CI/CD pipeline
✅ **Vulnerability Detection**: Multi-tool approach catches more issues
✅ **CIS Compliance**: Dockerfile best practices enforced
✅ **SBOM Generation**: Software Bill of Materials for audits
✅ **Production Hardening**: Optimized secure Docker images
✅ **Password Security**: Proper bcrypt_sha256 implementation
✅ **Developer Experience**: Pre-commit hooks catch issues early
## Breaking Changes
None - all changes are additive and backward compatible. Existing deployments
will continue to work, with security improvements activated on next rebuild.
## Testing
- ✅ Hadolint passes on all Dockerfiles (with allowed exceptions)
- ✅ Dockle CIS checks pass (minor warnings documented)
- ✅ Trivy vulnerability scans complete successfully
- ✅ Grype SBOM generation working
- ✅ GitHub Actions workflows validated
- ✅ Pre-commit hooks tested locally
- ✅ Security scan script tested on all images
- ✅ Password hashing backward compatibility verified
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
…lities This commit resolves PyTorch/cuDNN compatibility issues, fixes critical CVE vulnerabilities, and establishes a clean Docker build strategy for production deployments. ## Security Fixes - Fix CVE-2025-32434 (PyTorch RCE vulnerability, CVSS 9.3) - Upgrade PyTorch 2.2.2 → 2.8.0+cu128 - Security patch included in 2.6.0+ releases - Update all ML packages to use cuDNN 9 for CUDA 12.8 compatibility - Maintain NumPy 2.x (no CVEs found, fully compatible) ## ML/AI Stack Updates **All packages now use cuDNN 9 for CUDA 12.8 compatibility:** - PyTorch: 2.2.2 → 2.8.0+cu128 (includes CVE fix) - CTranslate2: 4.4.0 → 4.6.0+ (cuDNN 9 support required) - WhisperX: 3.4.3 → 3.7.0 (latest, ctranslate2 4.5+ compatible) - PyAnnote Audio: ≥3.3.2 (NumPy 2.x & PyTorch 2.6+ compatible) - NumPy: Keep ≥1.25.2 (2.x fully compatible, no downgrade needed) ## Critical Bug Fixes **Issue:** Worker crashes with SIGABRT during speaker diarization - Error: "Unable to load libcudnn_cnn.so.9" → SIGABRT signal - Root cause: PyAnnote couldn't find cuDNN 9 libraries in Python package directory - Solution: Add LD_LIBRARY_PATH to Dockerfile for cuDNN library discovery **PyTorch 2.6+ Compatibility:** - Add torch.serialization.add_safe_globals([ListConfig]) for PyAnnote models - Fixes torch.load() weights_only=True default change in PyTorch 2.6+ ## Error Handling Enhancements **Graceful frontend error notifications:** - Catch cuDNN/CUDA library errors with user-friendly messages - Handle GPU out-of-memory errors gracefully - Provide actionable error messages instead of technical stack traces - Ensure frontend receives status updates during failures ## Docker Build Strategy **Current (Dockerfile.prod):** - Base: python:3.12-slim-bookworm (Debian 12) - Single-stage build for fast iteration - Root user (required for GPU access) - LD_LIBRARY_PATH configured for cuDNN 9 libraries **Future (Dockerfile.prod.optimized):** - Multi-stage build for minimal image size (~40% smaller) - Non-root user (appuser) for enhanced security - OCI-compliant labels and health checks - Ready for testing after GPU permission verification **Cleanup:** - Remove obsolete Dockerfile.dev and Dockerfile.dev.optimized - Consolidate to Dockerfile.prod (current) and Dockerfile.prod.optimized (future) ## Development Environment **New: requirements-dev.txt** - Includes all development tools (black, ruff, mypy, pytest) - Separate from production dependencies - Pre-commit hooks and type stubs included **Backend venv updated:** - All packages rebuilt with cuDNN 9 compatibility - Development tools verified working ## Documentation **New: backend/DOCKER_STRATEGY.md** - Comprehensive Docker build strategy guide - Current vs optimized build comparison - Migration path and troubleshooting - Security considerations and change history ## Files Changed - backend/Dockerfile.prod: Add LD_LIBRARY_PATH for cuDNN 9 - backend/Dockerfile.prod.optimized: Update to bookworm, cuDNN 9, security best practices - backend/requirements.txt: Upgrade ML stack to cuDNN 9 compatible versions - backend/requirements-dev.txt: New development dependencies file - backend/app/tasks/transcription/whisperx_service.py: Add PyTorch 2.6+ compatibility & error handling - backend/app/tasks/transcription/core.py: Enhanced error messages for frontend - docker-compose.yml: Use Dockerfile.prod for all backend services - backend/DOCKER_STRATEGY.md: New comprehensive Docker documentation ## Testing Status ✅ Transcription pipeline working with cuDNN 9 ✅ Speaker diarization completes without SIGABRT crashes ✅ Frontend receives error notifications gracefully ✅ All ML packages compatible (PyTorch 2.8.0, CTranslate2 4.6.0, WhisperX 3.7.0) ✅ Security scans pass (CVE-2025-32434 fixed) ## Migration Notes - No NumPy downgrade required (2.x fully compatible with all packages) - LD_LIBRARY_PATH must be set at Dockerfile level (not docker-compose) - Optimized Dockerfile ready for testing after this commit - Local venv rebuilt with updated packages for development 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Comprehensive Security Upgrades and ML Stack Modernization
This PR consolidates critical security fixes, ML stack upgrades, and infrastructure improvements for OpenTranscribe's backend services.
🔒 Security Fixes
Critical CVE Remediation
torch.load()even withweights_only=TrueDependency Security Updates
🧠 ML/AI Stack Upgrades
Package Updates (All cuDNN 9 Compatible)
Compatibility Matrix
CUDA & cuDNN:
GPU Support:
🐛 Critical Bug Fixes
Worker SIGABRT Crash During Diarization
Problem:
Root Cause:
/usr/local/lib/python3.12/site-packages/nvidia/cudnn/lib/Solution:
LD_LIBRARY_PATHto Dockerfile for cuDNN library discoveryPyTorch 2.6+ Compatibility
Problem:
torch.load()default toweights_only=TrueListConfigfrom omegaconfSolution:
🎯 Error Handling Enhancements
Graceful Frontend Notifications
Before:
After:
🐳 Docker Build Strategy
Current: Dockerfile.prod (Active)
Features:
python:3.12-slim-bookworm(Debian 12)Use Cases:
Future: Dockerfile.prod.optimized (Ready for Testing)
Features:
appuser) for securityMigration Path:
Cleanup
Dockerfile.dev(obsolete, had PyTorch downgrade)Dockerfile.dev.optimized(obsolete)Dockerfile.prod(current)Dockerfile.prod.optimized(future)🔧 Infrastructure Improvements
Security Scanning
.github/workflows/security-scan.yml)scripts/security-scan.sh)docs/SECURITY_SCANNING.md)Pre-commit Hooks
.pre-commit-config.yamlwith ruff, mypy, bandit, shellcheckDevelopment Environment
requirements-dev.txtwith development tools📚 Documentation
New Documentation Files
backend/DOCKER_STRATEGY.md (188 lines)
docs/SECURITY_SCANNING.md (532 lines)
📝 Files Changed
Modified (8 files)
backend/Dockerfile.prod- Add LD_LIBRARY_PATH for cuDNN 9backend/requirements.txt- Upgrade ML stackbackend/app/tasks/transcription/whisperx_service.py- PyTorch 2.6+ compatibility & error handlingbackend/app/tasks/transcription/core.py- Enhanced error messagesdocker-compose.yml- Use Dockerfile.prod for all servicesbackend/app/core/config.py- Security config updatesbackend/app/core/security.py- Security enhancementsbackend/app/auth/direct_auth.py- Auth improvementsAdded (12 files)
backend/DOCKER_STRATEGY.md- Docker strategy documentationbackend/Dockerfile.prod.optimized- Optimized multi-stage buildbackend/requirements-dev.txt- Development dependenciesdocs/SECURITY_SCANNING.md- Security scanning documentation.github/workflows/security-scan.yml- Security CI workflow.github/workflows/pre-commit.yml- Pre-commit CI workflow.pre-commit-config.yaml- Pre-commit hooks configurationpyproject.toml- Python project configuration.hadolint.yaml- Dockerfile linter configscripts/security-scan.sh- Security scanning automation.gitignoreupdates - Ignore venv, cache, etc.Removed (2 files)
backend/Dockerfile.dev- Obsoletebackend/Dockerfile.dev.optimized- ObsoleteTotal Changes: +2,135 insertions / -84 deletions
✅ Testing Status
Verified Working
Test Environment
🚀 Migration Notes
For Deployment
For Development
🎯 Next Steps
📊 Impact Summary
Security
Performance
Reliability
Developer Experience
🙏 Acknowledgments
This PR represents significant research into PyTorch/CUDA/cuDNN compatibility matrices, WhisperX/CTranslate2 version requirements, and Docker security best practices.
Key Resources:
🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com