A production-ready secrets management API built with FastAPI, PostgreSQL, and Fernet encryption. Designed for enterprise deployments with comprehensive DevOps tooling, CI/CD integration, and security-first architecture.
- Overview
- Key Features
- Tech Stack
- Project Structure
- Getting Started
- Testing
- CI/CD Pipeline
- API Endpoints
- Security Considerations
- Monitoring & Logging
- Contributing
SecureVault is a self-hosted secrets management service for teams and applications. It provides a secure REST API to store, retrieve, rotate, and audit sensitive credentials (API keys, database passwords, tokens, certificates, etc.) with:
- End-to-end encryption using Fernet (symmetric encryption)
- JWT-based authentication with configurable token expiry
- Audit logging for all secret operations
- Secret versioning & rotation capabilities
- TTL support for time-limited secrets
- Rate limiting to prevent abuse
- Container-ready with Docker & Docker Compose
Perfect for microservices, CI/CD pipelines, and distributed systems where secrets need centralized, auditable management.
| Feature | Details |
|---|---|
| π Encryption at Rest | Fernet symmetric encryption (AES-128 in CBC mode) |
| π JWT Authentication | HS256 signed tokens with configurable expiry |
| ποΈ Database | PostgreSQL with SQLAlchemy ORM |
| π Migrations | Alembic for schema versioning |
| π Audit Logging | Complete action trails for compliance |
| π Secret Rotation | Built-in versioning and rotation support |
| β±οΈ TTL Support | Time-to-live for temporary secrets |
| π¦ Rate Limiting | Configurable request throttling (slowapi) |
| π‘ Monitoring | Sentry integration ready, structured JSON logging |
| π³ Containerization | Docker & Docker Compose configs included |
| β Test Coverage | Pytest suite with unit & integration tests |
| π CI/CD Ready | GitHub Actions pipeline configured |
| Component | Technology | Version |
|---|---|---|
| Framework | FastAPI | 0.104.1 |
| Web Server | Uvicorn | 0.24.0 |
| Database | PostgreSQL | 13+ |
| ORM | SQLAlchemy | 2.0.23 |
| Migrations | Alembic | 1.12.1 |
| Encryption | cryptography (Fernet) | 41.0.7 |
| Authentication | PyJWT / bcrypt | 2.9.0 / 4.1.1 |
| Rate Limiting | slowapi | 0.1.9 |
| Testing | pytest | 7.4.3 |
| Code Quality | black, flake8, mypy, bandit | Latest |
| Container | Docker / Docker Compose | Latest |
| Logging | python-json-logger | 2.0.7 |
| Monitoring | Sentry SDK | 1.38.0 |
SecureVault/
βββ .github/workflows/ # GitHub Actions CI/CD pipelines
β βββ ci.yml # (default) Test, lint, build workflow
β
βββ alembic/ # Database migration scripts
β βββ versions/ # Individual migration files
β βββ env.py # Alembic environment configuration
β βββ script.py.mako # Migration template
β
βββ app/ # Application source code
β βββ __init__.py
β βββ main.py # FastAPI app initialization
β βββ models.py # SQLAlchemy ORM models
β βββ schemas.py # Pydantic request/response schemas
β βββ routes.py # API endpoint definitions
β βββ database.py # Database connection & session management
β βββ auth.py # JWT authentication logic
β βββ config.py # Settings from environment
β βββ utils.py # Helper utilities
β
βββ docker/ # Docker configurations
β βββ Dockerfile # Production image
β βββ Dockerfile.dev # Development image
β βββ docker-compose.yml # Multi-container orchestration
β
βββ docs/ # Documentation
β βββ API.md # API reference
β βββ DEPLOYMENT.md # Deployment guides
β βββ ARCHITECTURE.md # System design
β
βββ tests/ # Test suite
β βββ conftest.py # Pytest fixtures & configuration
β βββ test_auth.py # Authentication tests
β βββ test_secrets.py # Secret management tests
β βββ test_api.py # API endpoint tests
β
βββ .env.example # Template environment file
βββ .env # Actual config (git-ignored)
βββ .gitignore # Git exclusions
βββ alembic.ini # Alembic settings
βββ pytest.ini # Pytest configuration
βββ requirements.txt # Python dependencies
βββ secrets_manager.py # Core secrets encryption & storage logic
βββ __init__.py # Package metadata (v0.1.0)
βββ README.md # This file
- Python 3.10+ (3.11+ recommended)
- PostgreSQL 13+ (locally or Docker)
- Docker & Docker Compose (optional, but recommended)
- git
# Clone repository
git clone https://github.com/Jawahir01/SecureVault.git
cd SecureVault
# Create Python virtual environment
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install --upgrade pip
pip install -r requirements.txt
# Install pre-commit hooks (optional but recommended)
pre-commit installCopy the example .env file and customize for your environment:
cp .env.example .envKey variables to configure:
# Database (default: Docker Compose service)
DATABASE_URL=postgresql://securevault_user:securevault_pass@postgres:5432/securevault_db
DATABASE_ECHO=False # Set True for SQL debug logging
# Security - CHANGE THESE IN PRODUCTION!
SECRET_KEY=your-super-secret-key-change-this-in-production
ENCRYPTION_KEY=your-encryption-key-change-this-in-production
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=30
REFRESH_TOKEN_EXPIRE_DAYS=7
# Environment
ENVIRONMENT=development # development | production | staging
DEBUG=True # False in production
# API Configuration
API_TITLE=SecureVault
API_VERSION=1.0.0
ALLOWED_ORIGINS=["http://localhost:3000", "http://localhost:8000"]
# Rate Limiting
RATE_LIMIT_ENABLED=True
RATE_LIMIT_REQUESTS=5 # Requests per period
RATE_LIMIT_PERIOD=60 # Seconds
# Monitoring (optional)
LOG_LEVEL=INFO # DEBUG | INFO | WARNING | ERROR
SENTRY_DSN= # Leave empty to disable Sentry- Generate strong
SECRET_KEYandENCRYPTION_KEY:openssl rand -hex 32 - Use environment variables or secrets manager (AWS Secrets Manager, HashiCorp Vault, etc.)
- Never commit
.envfiles to git (already in.gitignore)
Initialize the PostgreSQL database with Alembic migrations:
# Create initial migration (if needed)
alembic revision --autogenerate -m "Initial schema"
# Apply migrations to database
alembic upgrade head
# Verify migration status
alembic current
alembic historyFor rollback:
alembic downgrade -1 # Rollback one migration
alembic downgrade base # Rollback all migrationsQuickstart with Docker Compose:
docker-compose up --buildThis starts:
- FastAPI app on
http://localhost:8000 - PostgreSQL database on
localhost:5432 - Interactive API docs at
http://localhost:8000/docs
Check logs:
docker-compose logs -f app
docker-compose logs -f postgresStop services:
docker-compose down
docker-compose down -v # Also remove volumes/dataProduction Docker build:
docker build -f docker/Dockerfile -t securevault:latest .
docker run -d \
--name securevault \
-p 8000:8000 \
--env-file .env.production \
securevault:latestThe project includes a comprehensive test suite (all passing β ).
# Run all tests
pytest
# Run with verbose output
pytest -v
# Run specific test file
pytest tests/test_secrets.py
# Run specific test function
pytest tests/test_secrets.py::test_encrypt_decrypt
# Run with coverage report
pytest --cov=app --cov-report=html tests/
# Run only unit tests
pytest -m unit
# Run only integration tests
pytest -m integration
# Run tests in parallel (faster)
pytest -n autoTest markers (defined in pytest.ini):
@pytest.mark.unit # Fast, isolated tests
@pytest.mark.integration # Tests requiring DB/external servicesOutput location:
- Coverage report:
htmlcov/index.html - Pytest cache:
.pytest_cache/
The project includes a GitHub Actions workflow (.github/workflows/ci.yml) that runs on every push and pull request:
- Dependency Installation β Install
requirements.txt - Linting & Code Quality β Run flake8, black, isort, mypy, bandit
- Unit Tests β pytest with coverage
- Integration Tests β Database-dependent tests
- Security Scanning β bandit for security issues, pip-audit for dependencies
- Build Docker Image β Build and tag container image
- Push to Registry (Optional) β Push to Docker Hub / ECR on
mainbranch
Status Badge:
View pipeline results: https://github.com/Jawahir01/SecureVault/actions
Full interactive API documentation available at
http://localhost:8000/docs(Swagger UI)
POST /api/secrets # Store a new secret
GET /api/secrets/:key # Retrieve a secret
PUT /api/secrets/:key # Update/rotate secret
DELETE /api/secrets/:key # Delete a secret
GET /api/secrets # List all secret keys
POST /api/auth/login # Get JWT token (username + password)
POST /api/auth/refresh # Refresh expired token
POST /api/auth/logout # Invalidate token
GET /api/secrets/:key/audit # Get audit log for secret
GET /api/secrets/:key/history # Get version history
GET /api/health # Health check
Example: Store a secret
curl -X POST "http://localhost:8000/api/secrets" \
-H "Authorization: Bearer <JWT_TOKEN>" \
-H "Content-Type: application/json" \
-d '{
"key": "db_password",
"value": "super-secret-pw",
"ttl": 86400,
"metadata": {"environment": "production"}
}'Example: Retrieve a secret
curl -X GET "http://localhost:8000/api/secrets/db_password" \
-H "Authorization: Bearer <JWT_TOKEN>"- Fernet (symmetric) β AES-128 in CBC mode with HMAC authentication
- At-rest encryption β All secrets encrypted before database storage
- In-transit encryption β Use HTTPS in production (reverse proxy recommended)
- JWT tokens β HS256 signed, configurable expiry
- Access tokens β Default 30 minutes (set via
ACCESS_TOKEN_EXPIRE_MINUTES) - Refresh tokens β Default 7 days (set via
REFRESH_TOKEN_EXPIRE_DAYS) - Password hashing β bcrypt with salt rounds
- Secret Masking β Sensitive values never logged
- Rate Limiting β Prevent brute-force attacks (configurable)
- CORS β Restrict origin access (configured in
.env) - Audit Logging β Complete access trail for compliance
- Security Scanning β CI/CD includes bandit & pip-audit
- β
Rotate
SECRET_KEYandENCRYPTION_KEYquarterly - β Use strong, randomly-generated keys (32+ bytes)
- β Deploy behind HTTPS-enabled reverse proxy (nginx, Traefik)
- β Run in isolated network namespace (Kubernetes NetworkPolicy)
- β Implement secrets backup & disaster recovery
- β Monitor with Sentry for error tracking
- β Use strong database passwords (alphanumeric + special chars)
- β Enable database SSL connections in production
- β Never hardcode secrets
- β Never commit
.envto git
Logs are output as JSON for easy parsing by log aggregators:
{
"timestamp": "2024-01-15T10:30:45.123Z",
"level": "INFO",
"action": "secret_retrieved",
"secret_key": "db_password",
"user": "app_service",
"duration_ms": 42
}Enable error tracking by setting SENTRY_DSN:
SENTRY_DSN=https://key@sentry.io/project-idSet via LOG_LEVEL environment variable:
DEBUG β Detailed diagnostic info
INFO β General informational messages
WARNING β Warning messages (default for production)
ERROR β Error conditions
- API response times
- Database connection pool utilization
- Cache hit rate (if caching layer added)
- Failed authentication attempts
- Rate limit rejections
- Secret rotation frequency
We welcome contributions! Follow these steps:
- Fork the repository
- Create feature branch β
git checkout -b feature/awesome-feature - Code with test coverage
- Run linting & tests β
pytest,black,flake8,mypy - Commit clearly β
git commit -m "Add awesome feature" - Push β
git push origin feature/awesome-feature - Open Pull Request with description
- Follow PEP 8 (enforced by black/flake8)
- Write tests for all new features
- Update docs for API changes
- Run full test suite before pushing:
pytest && black . && flake8 app/
- Issues β https://github.com/Jawahir01/SecureVault/issues
- Discussions β https://github.com/Jawahir01/SecureVault/discussions
- Docs β See
/docsdirectory for detailed guides
π Build secure, scalable secret management with SecureVault
Enterprise-grade secrets vault for DevSecOps teams