Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
4b6a102
docker: harden Cloud Run Dockerfiles; add security guide; update chan…
cursoragent Aug 16, 2025
4af601a
chore: add lint-fix script; minor code quality improvements in db che…
cursoragent Aug 16, 2025
9f4f697
tests: refresh core unit/integration/e2e tests; training: add minimal…
cursoragent Aug 16, 2025
dd52a4d
docker: include root Dockerfiles (hardened variants)
cursoragent Aug 16, 2025
fe0a8b3
docker: align entrypoints and deps; fix curl in healthchecks; pin deb…
cursoragent Aug 16, 2025
e40b223
Enhance linting script with improved file processing and backup options
cursoragent Aug 16, 2025
f35dbef
fix(lint-tool,db): address review feedback\n\n- lint fixer: remove un…
cursoragent Aug 16, 2025
814ce9b
docs,chore,lint: apply nitpicks\n\n- CHANGELOG: split Code Quality in…
cursoragent Aug 16, 2025
3731da0
nit: refine lint tool and config per feedback\n\n- lint fixer: genera…
cursoragent Aug 16, 2025
1735d87
style: address DeepSource notes\n\n- fix_linting_issues: built-in gen…
cursoragent Aug 16, 2025
1e90ed2
nit(db,lint): context managers, exception logging; pathlib-safe temp …
cursoragent Aug 16, 2025
9a5ad46
style(rate_limiter): fix hanging indent (E131) in UA analysis conditi…
cursoragent Aug 16, 2025
a0fb988
style(lint fixer): satisfy E302/E305 by ensuring two blank lines betw…
cursoragent Aug 16, 2025
f717dc0
style(lint fixer): wrap long lines (E501) and ensure 2 blank lines af…
cursoragent Aug 16, 2025
fdb1d07
style(db): replace tabs with spaces in check_pgvector.py (fix W191)
cursoragent Aug 16, 2025
3fa50a7
docs(style): wrap long docstring and shorten overlong comment (fix W505)
cursoragent Aug 16, 2025
6a2a7c7
sec(lint fixer): validate file paths under project root to address PT…
cursoragent Aug 16, 2025
852482a
style(db): use lazy logging formatting for DB_NAME (fix PYL-W1203)
cursoragent Aug 16, 2025
9b22f95
refactor(rate_limiter): use sum comprehensions and tighten scope in _…
cursoragent Aug 16, 2025
b4c74af
style(db): wrap long strings and SQL for E501 in check_pgvector.py
cursoragent Aug 16, 2025
da86746
Add emotion detection module with BERT-based classifier
cursoragent Aug 16, 2025
84d9a8a
style(db): final E501 wrap for apt hint in check_pgvector.py
cursoragent Aug 16, 2025
cc57b4e
Merge pull request #85 from uelkerd/fix/code-quality-only
d-ulker Aug 16, 2025
7d3a500
docker(Dockerfile.new): install Flask before USER to avoid permission…
cursoragent Aug 16, 2025
d403e20
docker: use 8000 in healthcheck; remove placeholder digests to unbloc…
cursoragent Aug 16, 2025
057c348
docker: harden Cloud Run Dockerfiles; add security guide; update chan…
cursoragent Aug 16, 2025
976624f
docker: include root Dockerfiles (hardened variants)
cursoragent Aug 16, 2025
8ea0a02
docker: align entrypoints and deps; fix curl in healthchecks; pin deb…
cursoragent Aug 16, 2025
9fbadba
docker: convert top-level Dockerfile to multi-stage; align unified Cl…
cursoragent Aug 16, 2025
60ae3c0
Merge remote-tracking branch 'origin/fix/docker-vulnerabilities-only'…
d-ulker Aug 16, 2025
4a71dc0
Merge remote-tracking branch 'origin/fix/docker-vulnerabilities-only'…
d-ulker Aug 16, 2025
62a37b8
docker: add WORKDIR in builder stage before relative COPY to satisfy …
cursoragent Aug 16, 2025
e85d49a
scripts/testing: import requests to fix PYL-E0602 undefined name in t…
cursoragent Aug 16, 2025
bd0e75f
style: wrap long lines to satisfy FLK-E501 in api_rate_limiter and te…
cursoragent Aug 16, 2025
58c64b8
docker: harden Cloud Run Dockerfiles; add security guide; update chan…
deepsource-autofix[bot] Aug 16, 2025
05d27e4
refactor(api_rate_limiter): reduce cyclomatic complexity of _analyze_…
cursoragent Aug 16, 2025
3407550
nit: harden Dockerfile.new (pin OS pkgs, drop upgrade, use system nol…
cursoragent Aug 16, 2025
1e03437
style(api_rate_limiter): replace tabs with spaces; fix logging f-stri…
cursoragent Aug 16, 2025
9c64e46
docker: harden Cloud Run Dockerfiles; add security guide; update chan…
deepsource-autofix[bot] Aug 16, 2025
ff36126
docker(cloud-run): enforce pinned Python deps via constraints; docs: …
cursoragent Aug 16, 2025
b34c8b4
chore(deploy): replace requirements.txt with requirements-api.txt acr…
cursoragent Aug 16, 2025
743adc0
Implement multi-stage Dockerfile for optimized Cloud Run deployment
cursoragent Aug 16, 2025
25f4b3c
style: wrap remaining long lines in rate limiter to satisfy FLK-E501
cursoragent Aug 16, 2025
2769e79
style: wrap _detect_abuse signature to satisfy FLK-E501
cursoragent Aug 16, 2025
c588bc1
deps: bump psycopg2-binary to 2.9.10 to fix CI install error
cursoragent Aug 16, 2025
2f96137
docker: apply constraints.txt in builder pip install; scripts: guard …
cursoragent Aug 16, 2025
ca623fa
Merge pull request #83 from uelkerd/fix/docker-vulnerabilities-only
d-ulker Aug 16, 2025
2a8d88d
Fix Docker builds: remove architecture-specific package pinning and r…
d-ulker Aug 16, 2025
70ef9c6
Implement proper Docker solution: pin package versions + use bookworm…
d-ulker Aug 16, 2025
62505d8
Address code review feedback: move gcc/g++ to builder stages, remove …
d-ulker Aug 16, 2025
0de2ac8
Fix DOK-DL3008: Add version pinning for all apt-get install packages …
d-ulker Aug 16, 2025
46ba003
Fix multi-arch builds and version consistency: remove hard gcc/g++ ve…
d-ulker Aug 16, 2025
7217790
Fix DOK-DL3008: Add version pinning for gcc/g++ using Debian release …
d-ulker Aug 16, 2025
0bc888a
Fix Dockerfile.minimal: remove Debian-specific curl version pin, add …
d-ulker Aug 16, 2025
e0d062b
Complete version consistency: update all remaining prometheus-client …
d-ulker Aug 16, 2025
de0f2a3
Comprehensive requirements alignment: fix nitpick comments, add httpx…
d-ulker Aug 16, 2025
74d4272
Fix Dockerfile.unified paths for building from deployment/cloud-run d…
d-ulker Aug 16, 2025
ce664a3
Revert Dockerfile.unified paths to work from project root directory
d-ulker Aug 16, 2025
7dbb13a
Add consolidated Dockerfile: single file with build args for all vari…
d-ulker Aug 16, 2025
d59adef
Improve emotion model loading: better logging, less alarming warnings…
d-ulker Aug 16, 2025
8c4df99
🎉 Consolidate all Dockerfiles into single consolidated version
d-ulker Aug 16, 2025
713fb32
Fix Docker builds: remove architecture-specific package pinning and r…
deepsource-autofix[bot] Aug 16, 2025
526c21c
🔧 Fix code review issues: standardize Flask/Gunicorn versions and rem…
d-ulker Aug 16, 2025
ece1ccc
🔀 Resolve merge conflict in unified_ai_api.py
d-ulker Aug 16, 2025
1a5be03
🔧 Fix Dockerfile issues: remove arch-specific pinning, fix paths, and…
d-ulker Aug 16, 2025
e2c7001
🔧 Address all nitpick comments: fix httpx constraints, remove emojis,…
d-ulker Aug 16, 2025
4a0105a
🔧 Fix final nitpick comments: remove redundant gunicorn and python-do…
d-ulker Aug 16, 2025
0160b7a
🔧 Fix linting issues: continuation line indentation, long lines, and …
d-ulker Aug 16, 2025
9116499
🔧 Fix Dockerfile architecture pinning and standardize prometheus-clie…
d-ulker Aug 16, 2025
f469b66
🔧 Fix DeepSource PYL-W1203: Convert all f-string logging to parameter…
d-ulker Aug 16, 2025
693d1b1
Fix Docker builds: remove architecture-specific package pinning and r…
deepsource-autofix[bot] Aug 16, 2025
1174fb5
🔧 Standardize prometheus-client and requests versions: pin to exact v…
d-ulker Aug 16, 2025
7350385
Merge branch 'fix/docker-build-issues' of https://github.com/uelkerd/…
d-ulker Aug 16, 2025
05c5484
🔧 Fix remaining f-string logging calls and continuation line indentat…
d-ulker Aug 16, 2025
b280032
🔧 Fix remaining FLK-E501 line length issues in unified_ai_api.py
d-ulker Aug 16, 2025
937156b
Merge pull request #87 from uelkerd/fix/docker-build-issues
d-ulker Aug 17, 2025
2a1da4a
🧪 Address code review comments: implement comprehensive test coverage…
d-ulker Aug 17, 2025
80d979a
🔧 Fix FLK-E127: correct continuation line indentation in config.py an…
d-ulker Aug 17, 2025
f352a22
🚀 Fix CUDA performance: make CUDA_LAUNCH_BLOCKING conditional on debu…
d-ulker Aug 17, 2025
6d42736
🧪 Address code review comments: implement comprehensive test coverage…
d-ulker Aug 17, 2025
86f296e
🔧 Fix FLK-E127: correct continuation line indentation in config.py an…
d-ulker Aug 17, 2025
0e332e2
🔧 Resolve merge conflicts and complete CUDA performance fixes
d-ulker Aug 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ All notable changes to this project will be documented in this file.

## [Unreleased] - 2025-08-07

### Docker Security Hardening
- Hardened `deployment/cloud-run/Dockerfile` and `deployment/cloud-run/Dockerfile.unified` (non-root user, pinned OS packages, healthchecks, explicit EXPOSE, clarified uvicorn entrypoint).
- Added `deployment/DOCKERFILE_SECURITY_GUIDE.md`.

### Added
- `scripts/fix_linting_issues.py` to automate PEP8-style fixes.

### Changed
- Improve logging and formatting in `scripts/database/check_pgvector.py`.
- Tidy API rate limiter and testing config for readability.

### Tests & Training
- Refresh core tests (unit, integration, e2e) and minimal training helpers.
- Keep scope small to validate core flows and CI signal without large refactors.
### 🚀 **Priority 1 Features Implementation - Complete API Enhancement**

#### **JWT-based Authentication System**
Expand Down
52 changes: 0 additions & 52 deletions Dockerfile

This file was deleted.

10 changes: 6 additions & 4 deletions constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
############################################

# Core problematic packages - pin to exact versions
psycopg2-binary==2.9.9
psycopg2-binary==2.9.10
pgvector==0.3.6
prometheus-client==0.21.0
prometheus-client==0.20.0 # NOTE: pinned lower than 0.21.0 due to compatibility issues with exporter libraries

# Google Cloud packages - often cause conflicts
google-auth==2.35.0
Expand All @@ -17,9 +17,11 @@ google-api-core==2.21.0
googleapis-common-protos==1.65.0

# Common transitive dependencies that cause backtracking
certifi>=2024.12.14,<2026.0.0
# NOTE: certifi pinned to exact version for CI determinism; security updates handled via base image updates
certifi==2024.12.14
urllib3==2.2.3
requests==2.32.3
requests==2.32.4
httpx>=0.25.0,<0.29.0 # Ensures compatibility with AnyIO 4.x and prevents breaking changes
charset-normalizer==3.4.0
idna==3.10

Expand Down
141 changes: 141 additions & 0 deletions deployment/DOCKERFILE_SECURITY_GUIDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
# Dockerfile Security Guide

## Overview

This document explains the security considerations and design decisions for different Dockerfile configurations in the SAMO project. Each Dockerfile is designed for a specific deployment environment with appropriate security measures.

## Dockerfile Configurations

### 1. Main Production Dockerfile (`/Dockerfile`)

**Purpose**: Production deployment with maximum security
**Server**: Gunicorn with Uvicorn workers
**Security Features**:
- ✅ Non-root user execution
- ✅ Pinned package versions (OS packages pinned; Python deps pinned in `requirements-api.txt` and enforced with `constraints.txt`)
- ✅ Minimal attack surface
- ✅ Health checks
- ✅ Environment variable configuration

**CMD**:
```dockerfile
CMD ["sh", "-c", "gunicorn --bind ${HOST}:${PORT} --workers 2 --worker-class uvicorn.workers.UvicornWorker --access-logfile - --error-logfile - src.unified_ai_api:app"]
```

**Why Gunicorn?**
- Process management and monitoring
- Worker process isolation
- Better security posture
- Production-grade reliability

### 2. Cloud Run Dockerfile (`/deployment/cloud-run/Dockerfile`)

**Purpose**: Google Cloud Run deployment
**Server**: Uvicorn directly
**Security Features**:
- ✅ Non-root user execution
- ✅ Pinned package versions
- OS packages pinned to Debian bookworm security releases
- Python dependencies pinned in `requirements-api.txt` and additionally constrained with `constraints.txt` during install
- ✅ Health checks
- ✅ Environment variable configuration

**CMD**:
```dockerfile
CMD ["sh", "-c", "exec uvicorn src.unified_ai_api:app --host 0.0.0.0 --port ${PORT}"]
```

**Why Uvicorn for Cloud Run?**
- Cloud Run manages process lifecycle
- No need for Gunicorn process management
- Lighter weight for serverless environment
- Cloud Run provides security isolation

### 3. Unified API Dockerfile (`/deployment/cloud-run/Dockerfile.unified`)

**Purpose**: Unified API service for Cloud Run
**Server**: Uvicorn directly
**Security Features**:
- ✅ Non-root user execution
- ✅ Pinned package versions
- OS packages pinned to Debian bookworm security releases
- Python dependencies pinned via `requirements_unified.txt` and additionally constrained with `constraints.txt`
- ✅ Health checks
- ✅ Model pre-bundling for security

**CMD**:
```dockerfile
CMD ["sh", "-c", "exec uvicorn src.unified_ai_api:app --host 0.0.0.0 --port ${PORT}"]
```

## Security Analysis (Concise)

Some scanners may raise false positives in these Dockerfiles:
- Import path flagged as a key: `src.unified_ai_api:app` is a Python module path, not a secret.
- Subprocess usage in tests: arguments are static lists without `shell=True`, minimizing risk.
- Bindings/security headers: `0.0.0.0` exposure is intentional for containers; actual binding is controlled via environment variables and platform ingress.

These are documented to avoid unnecessary policy exceptions while keeping configurations secure and clear.

## Security Best Practices Implemented

### 1. User Management
- All Dockerfiles create non-root users
- Proper ownership of application files
- Minimal privileges for runtime

### 2. Package Security
- Pinned OS package versions
- Python packages pinned in requirements and enforced with constraints to ensure reproducibility
- Regular security updates
- Vulnerability scanning in CI/CD

### 3. Network Security
- Environment variable configuration
- No hardcoded bindings
- Proper EXPOSE directives

### 4. Process Security
- Health checks with timeouts
- Proper signal handling
- Resource limits where applicable

## Deployment Environment Considerations

### Production (Main Dockerfile)
- **Use Case**: Traditional server deployment
- **Server**: Gunicorn + Uvicorn workers
- **Security**: Maximum isolation and monitoring
- **Monitoring**: Process-level health checks

### Cloud Run (Cloud Run Dockerfiles)
- **Use Case**: Serverless deployment
- **Server**: Uvicorn directly
- **Security**: Platform-provided isolation
- **Monitoring**: Cloud Run health checks

## Security Recommendations

### 1. For Production Deployments
- Use the main Dockerfile with Gunicorn
- Implement proper logging and monitoring
- Use environment variables for configuration
- Regular security updates

### 2. For Cloud Run Deployments
- Use the cloud-run specific Dockerfiles
- Leverage Cloud Run security features
- Use Secret Manager for sensitive data
- Monitor Cloud Run logs and metrics

### 3. General Security
- Never commit secrets to version control
- Use environment variables for configuration
- Regular vulnerability scanning
- Keep dependencies updated

## Appendix: False Positive References

- Generic API key detection: the string `src.unified_ai_api:app` is an import path (FastAPI app instance), not a credential.
- Subprocess warnings: tests use argument lists with no `shell=True`, and file paths are programmatically controlled.
- Hardcoded bindings: `0.0.0.0` is a container best practice for network ingress; actual external exposure is managed by the orchestrator (e.g., Cloud Run).
4 changes: 2 additions & 2 deletions deployment/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
## 📦 What's Included
- `model/` - Trained model files
- `inference.py` - Standalone inference script
- `requirements.txt` - Dependencies
- `requirements-api.txt` - API/runtime dependencies (pinned)
- `test_examples.py` - Test the model
- `api_server.py` - REST API server

## 🚀 Quick Start

### 1. Install Dependencies
```bash
pip install -r requirements.txt
pip install -r requirements-api.txt
```

### 2. Test the Model
Expand Down
39 changes: 0 additions & 39 deletions deployment/cloud-run/Dockerfile

This file was deleted.

Loading
Loading