The easiest way to set up your environment is to use the automated setup script:
chmod +x setup_env.sh
./setup_env.shThis script will:
- Create
.envfrom.env.example - Generate secure random secrets for:
SECRET_KEY(API secret key)REDIS_PASSWORD(Redis authentication)JWT_SECRET(JWT token signing)
- Update the
.envfile with these secrets
If you prefer to set up manually:
cp .env.example .envGenerate secure random secrets using OpenSSL:
# Generate SECRET_KEY (64 characters)
openssl rand -base64 48
# Generate REDIS_PASSWORD (32 characters)
openssl rand -base64 24
# Generate JWT_SECRET (64 characters)
openssl rand -base64 48Edit .env and replace the placeholder values:
# Security - CHANGE THESE IN PRODUCTION!
SECRET_KEY=<your-generated-secret-key>
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=30
REFRESH_TOKEN_EXPIRE_DAYS=7
# Redis
REDIS_URL=redis://localhost:6379/0
REDIS_PASSWORD=<your-generated-redis-password>| Variable | Default | Description |
|---|---|---|
API_HOST |
0.0.0.0 |
Host to bind the API server |
API_PORT |
8528 |
Port for the API server |
API_WORKERS |
4 |
Number of Gunicorn workers |
| Variable | Required | Description |
|---|---|---|
SECRET_KEY |
Yes | Secret key for signing tokens (min 32 chars) |
ALGORITHM |
No | JWT algorithm (default: HS256) |
ACCESS_TOKEN_EXPIRE_MINUTES |
No | Access token lifetime (default: 30) |
REFRESH_TOKEN_EXPIRE_DAYS |
No | Refresh token lifetime (default: 7) |
| Variable | Default | Description |
|---|---|---|
CORS_ORIGINS |
["http://localhost:3000","http://localhost:8528"] |
Allowed origins |
CORS_ALLOW_CREDENTIALS |
true |
Allow credentials |
CORS_ALLOW_METHODS |
["GET","POST","PUT","DELETE"] |
Allowed methods |
CORS_ALLOW_HEADERS |
["*"] |
Allowed headers |
| Variable | Default | Description |
|---|---|---|
RATE_LIMIT_DEFAULT |
100/minute |
Default rate limit |
RATE_LIMIT_AUTH |
5/minute |
Auth endpoint rate limit |
| Variable | Required | Description |
|---|---|---|
REDIS_URL |
No | Redis connection URL |
REDIS_PASSWORD |
Yes | Redis authentication password |
| Variable | Default | Description |
|---|---|---|
TLS_ENABLED |
false |
Enable TLS/HTTPS |
TLS_CERT_PATH |
- | Path to TLS certificate |
TLS_KEY_PATH |
- | Path to TLS private key |
| Variable | Default | Description |
|---|---|---|
ENVIRONMENT |
development |
Environment name (development/staging/production) |
DEBUG |
true |
Enable debug mode |
For production deployments, ensure you:
# Use at least 64 characters for SECRET_KEY
openssl rand -base64 64
# Use at least 32 characters for REDIS_PASSWORD
openssl rand -base64 32ENVIRONMENT=production
DEBUG=false
TLS_ENABLED=true
TLS_CERT_PATH=/etc/ssl/certs/sovereigncore.crt
TLS_KEY_PATH=/etc/ssl/private/sovereigncore.key# Replace with your actual frontend URLs
CORS_ORIGINS=["https://app.yourdomain.com","https://api.yourdomain.com"]# Stricter limits for production
RATE_LIMIT_DEFAULT=50/minute
RATE_LIMIT_AUTH=3/minuteAfter setting REDIS_PASSWORD, update Redis configuration:
# Update redis.conf
sed -i "s/requirepass .*/requirepass YOUR_REDIS_PASSWORD/" redis.conf
# Update users.acl
sed -i "s/>.*/>YOUR_REDIS_PASSWORD/" users.acl
# Restart Redis
./scripts/setup_redis.shThe .env file is already in .gitignore, but double-check:
grep -q "^\.env$" .gitignore || echo ".env" >> .gitignoreIn production, rotate secrets every 90 days:
# Generate new secrets
./setup_env.sh
# Update Redis
./scripts/setup_redis.sh
# Restart services
docker compose restartFor multiple environments:
.env.development
.env.staging
.env.productionLoad the appropriate file:
cp .env.production .envchmod 600 .envFor production, consider using:
- AWS Secrets Manager
- HashiCorp Vault
- Azure Key Vault
- Google Secret Manager
After setup, verify your configuration:
# Check .env exists and has correct permissions
ls -la .env
# Verify secrets are set (without revealing them)
grep -q "SECRET_KEY=your-secret-key" .env && echo "⚠️ SECRET_KEY not changed!" || echo "✓ SECRET_KEY set"
grep -q "REDIS_PASSWORD=your-redis-password" .env && echo "⚠️ REDIS_PASSWORD not changed!" || echo "✓ REDIS_PASSWORD set"
# Test Redis connection
redis-cli -a $(grep REDIS_PASSWORD .env | cut -d'=' -f2) pingSolution: Ensure .env file exists and SECRET_KEY is set:
grep SECRET_KEY .envSolution: Ensure Redis password matches in .env and redis.conf:
# Check .env
grep REDIS_PASSWORD .env
# Check redis.conf
grep requirepass redis.conf
# Update if needed
./scripts/setup_redis.shSolution: Update CORS_ORIGINS with your frontend URL:
CORS_ORIGINS=["https://your-frontend-url.com"]After setting up your environment:
-
Initialize Database:
python init_db.py
-
Generate TLS Certificates (if needed):
./scripts/generate_certs.sh
-
Start Services:
docker compose up -d
-
Verify Deployment:
curl http://localhost:8528/health