7/9 - Released
|See Changelog
Skip to main content

Environment Variables Configuration

Complete guide to configuring OpenLift service environment variables, including required settings, conditional dependencies, and production recommendations.

Overview​

OpenLift uses environment variables for all configuration. Copy default.env to .env and update values for your deployment.

cp default.env .env
# Edit .env with your actual configuration

Required Environment Variables​

Core Application Settings​

VariableRequiredDefaultDescription
NODE_ENVYeslocalApplication environment (local, development, staging, production)
PORTNo8000HTTP server port
HOSTNo0.0.0.0HTTP server bind address

Database Configuration​

VariableRequiredDefaultDescription
MONGO_DATABASE_URLYesNoneMongoDB connection string with authentication

Example MongoDB URLs:

# Local MongoDB
MONGO_DATABASE_URL=mongodb://username:password@localhost:27017/openfit-dev?authSource=admin

# MongoDB Atlas
MONGO_DATABASE_URL=mongodb+srv://username:password@cluster.mongodb.net/openfit?retryWrites=true&w=majority

# MongoDB with replica set
MONGO_DATABASE_URL=mongodb://user:pass@host1:27017,host2:27017,host3:27017/openfit?replicaSet=myReplicaSet&authSource=admin

Security Configuration​

VariableRequiredDefaultDescription
COOKIE_SECRETProductionNoneSecret for signing cookies (32+ characters)
JWT_PRIVATE_KEY_PATHYes./private.pemPath to RSA private key for JWT signing
JWT_PUBLIC_KEY_PATHYes./public.pemPath to RSA public key for JWT verification
JWT_ACCESS_TOKEN_EXPIRES_INNo15mJWT token expiration (15 minutes recommended)
JWT_ISSUERNoopen-fit-devJWT issuer identifier
JWT_AUDIENCENoopen-fit-users-devJWT audience identifier
CORS_ORIGINNo^$CORS origin pattern (regex)

Generate JWT Keys:

# Generate RSA private key
ssh-keygen -t rsa -b 4096 -m PEM -f private.pem

# Extract public key
ssh-keygen -f private.pem -e -m PEM > public.pem

Security Requirements by Environment:

  • Development: COOKIE_SECRET optional (warning shown)
  • Production: COOKIE_SECRET mandatory (application fails without it)

Object Storage Configuration​

OpenLift supports two object storage providers: Cloudflare R2 (recommended) or MinIO (self-hosted).

Provider Selection​

VariableRequiredDefaultOptionsDescription
OBJECT_STORAGE_PROVIDERYesR2R2, MINIOObject storage provider

Cloudflare R2 Configuration​

Required when OBJECT_STORAGE_PROVIDER=R2:

VariableRequiredDefaultDescription
R2_ACCOUNT_IDYesNoneCloudflare R2 account ID
R2_ACCESS_KEY_IDYesNoneR2 API access key
R2_SECRET_ACCESS_KEYYesNoneR2 API secret key
R2_USER_ASSETS_BUCKET_NAMEYesNoneBucket for user-uploaded content
R2_EXERCISE_ASSETS_BUCKET_NAMEYesNoneBucket for exercise images/videos
R2_APP_ASSETS_BUCKET_NAMENoNoneBucket for application assets (optional)
R2_ENDPOINT_OVERRIDENoNoneCustom R2 endpoint (optional)

Example R2 Configuration:

OBJECT_STORAGE_PROVIDER=R2
R2_ACCOUNT_ID=a1b2c3d4e5f6789012345678
R2_ACCESS_KEY_ID=a1b2c3d4e5f67890123456789abc123456789abc
R2_SECRET_ACCESS_KEY=def123456789abc123456789def123456789abc123456789def1234567890
R2_USER_ASSETS_BUCKET_NAME=openfit-prod-user-assets
R2_EXERCISE_ASSETS_BUCKET_NAME=openfit-prod-exercise-assets
R2_APP_ASSETS_BUCKET_NAME=openfit-prod-app-assets

MinIO Configuration​

Required when OBJECT_STORAGE_PROVIDER=MINIO:

VariableRequiredDefaultDescription
MINIO_ENDPOINTYesNoneMinIO server hostname/IP
MINIO_PORTNo9000MinIO server port
MINIO_ACCESS_KEYYesNoneMinIO access key
MINIO_SECRET_KEYYesNoneMinIO secret key
MINIO_USE_SSLNofalseEnable SSL/TLS connection
MINIO_USER_ASSETS_BUCKET_NAMEYesNoneBucket for user-uploaded content
MINIO_EXERCISE_ASSETS_BUCKET_NAMEYesNoneBucket for exercise images/videos
MINIO_APP_ASSETS_BUCKET_NAMENoNoneBucket for application assets (optional)

Example MinIO Configuration:

OBJECT_STORAGE_PROVIDER=MINIO
MINIO_ENDPOINT=minio.yourdomain.com
MINIO_PORT=9000
MINIO_ACCESS_KEY=your-minio-access-key
MINIO_SECRET_KEY=your-minio-secret-key-32chars-min
MINIO_USE_SSL=true
MINIO_USER_ASSETS_BUCKET_NAME=openfit-user-assets
MINIO_EXERCISE_ASSETS_BUCKET_NAME=openfit-exercise-assets

Object Storage General Settings​

VariableRequiredDefaultDescription
SIGNED_URL_DEFAULT_EXPIRATION_SECONDSNo604800Signed URL expiration (7 days)
MAX_SERVER_UPLOAD_FILE_SIZE_BYTESNo10485760Max upload size (10MB)
ALLOWED_SERVER_UPLOAD_MIME_TYPESNoSee belowComma-separated allowed MIME types

Default Allowed MIME Types:

ALLOWED_SERVER_UPLOAD_MIME_TYPES=image/jpeg,image/png,image/gif,image/webp,image/heic,image/heif

Asset Retention Configuration​

Configure automatic cleanup of old user assets:

VariableRequiredDefaultDescription
PROGRESS_PHOTOS_RETENTION_COUNTNo10Keep last N progress photos per type
PROGRESS_PHOTOS_AUTO_CLEANUPNotrueAuto-archive old progress photos
PROFILE_PICTURES_RETENTION_COUNTNo5Keep last N profile pictures
PROFILE_PICTURES_AUTO_CLEANUPNotrueAuto-archive old profile pictures
WORKOUT_TEMPLATE_IMAGES_RETENTION_COUNTNo10Keep last N workout template images
WORKOUT_TEMPLATE_IMAGES_AUTO_CLEANUPNotrueAuto-archive old template images
WORKOUT_PROGRAM_IMAGES_RETENTION_COUNTNo10Keep last N program images
WORKOUT_PROGRAM_IMAGES_AUTO_CLEANUPNotrueAuto-archive old program images
APP_IMAGES_RETENTION_COUNTNo20Keep last N app images per category
APP_IMAGES_AUTO_CLEANUPNotrueAuto-archive old app images

Enterprise Observability Configuration​

Advanced logging, metrics, and monitoring for production deployments.

Core Observability Features​

VariableRequiredDefaultDescription
OBSERVABILITY_ENABLEDNofalseEnable enterprise observability system
METRICS_ENABLEDNotrueEnable metrics collection
LOGS_ENABLEDNotrueEnable logging system

Advanced Feature Flags​

VariableRequiredDefaultDescription
ENABLE_LOKI_SHIPPINGNotrueShip logs to Grafana Loki
ENABLE_LOCAL_FALLBACKNotrueLocal file fallback when Loki unavailable
ENABLE_CIRCUIT_BREAKERNotrueCircuit breaker for logging reliability
ENABLE_CORRELATION_IDNotrueRequest correlation tracking
ENABLE_DATA_SANITIZATIONNotruePII sanitization (always enabled in production)
ENABLE_COMPRESSIONNotrueCompress log payloads
ENABLE_ADAPTIVE_BATCHINGNotrueAdaptive batch sizing
ENABLE_PERFORMANCE_MONITORINGNotruePerformance metrics collection

Grafana Cloud Configuration​

Required when observability is enabled in production:

VariableRequiredDefaultDescription
LOKI_ENDPOINTProdNoneGrafana Loki push endpoint URL
LOKI_USERNAMEProdNoneGrafana Loki username
LOKI_PASSWORDProdNoneGrafana Loki API key
PROMETHEUS_ENDPOINTProdNoneGrafana Prometheus push endpoint URL
PROMETHEUS_USERNAMEProdNoneGrafana Prometheus username
PROMETHEUS_PASSWORDProdNoneGrafana Prometheus API key

Example Grafana Cloud Configuration:

OBSERVABILITY_ENABLED=true
LOKI_ENDPOINT=https://logs-prod-012.grafana.net/loki/api/v1/push
LOKI_USERNAME=123456
LOKI_PASSWORD=glc_eyJrIjoiabcd1234567890...
PROMETHEUS_ENDPOINT=https://prometheus-prod-12-abc.grafana.net/api/prom/push
PROMETHEUS_USERNAME=123456
PROMETHEUS_PASSWORD=glc_eyJrIjoixyz9876543210...

Performance Configuration​

VariableRequiredDefaultDescription
LOKI_BATCH_SIZENo1000Log entries per batch
LOKI_BATCH_INTERVALNo5000Batch flush interval (ms)
LOKI_MAX_BATCH_SIZENo5000Maximum batch size
LOKI_MIN_BATCH_SIZENo100Minimum batch size

Connection Configuration​

VariableRequiredDefaultDescription
LOKI_CONNECTION_TIMEOUTNo30000Connection timeout (ms)
LOKI_REQUEST_TIMEOUTNo60000Request timeout (ms)
LOKI_KEEPALIVE_TIMEOUTNo120000Keep-alive timeout (ms)

Retry Configuration​

VariableRequiredDefaultDescription
LOKI_RETRY_ATTEMPTSNo3Maximum retry attempts
LOKI_RETRY_DELAYNo1000Initial retry delay (ms)
LOKI_RETRY_BACKOFF_FACTORNo2.0Exponential backoff factor
LOKI_RETRY_MAX_DELAYNo30000Maximum retry delay (ms)

Circuit Breaker Configuration​

VariableRequiredDefaultDescription
CIRCUIT_BREAKER_ERROR_THRESHOLDNo50Error percentage threshold (1-100)
CIRCUIT_BREAKER_MIN_REQUESTSNo20Minimum requests before triggering
CIRCUIT_BREAKER_TIMEOUTNo60000Circuit breaker timeout (ms)
CIRCUIT_BREAKER_RESET_TIMEOUTNo120000Circuit breaker reset timeout (ms)

Buffer Management​

VariableRequiredDefaultDescription
LOG_BUFFER_SIZENo100000Log buffer size (entries)
LOG_BUFFER_MEMORY_LIMITNo50MBMemory limit for log buffer
LOG_BUFFER_HIGH_WATER_MARKNo80High water mark percentage
LOG_BUFFER_LOW_WATER_MARKNo60Low water mark percentage

Local Fallback Configuration​

VariableRequiredDefaultDescription
FALLBACK_LOG_DIRECTORYNo./logsLocal fallback log directory
FALLBACK_MAX_FILE_SIZENo100MBMaximum log file size
FALLBACK_MAX_FILESNo5Maximum number of log files
FALLBACK_COMPRESS_FILESNotrueCompress rotated log files

Service Identification​

VariableRequiredDefaultDescription
SERVICE_NAMENoopenlift-serviceService name for logs/metrics
SERVICE_VERSIONNo1.0.0Service version
DEPLOYMENT_ENVIRONMENTNodevelopmentDeployment environment label
CLUSTER_NAMENolocal-devCluster/deployment identifier
INSTANCE_IDNoAuto-generatedUnique instance identifier

Data Sanitization​

VariableRequiredDefaultDescription
PII_DETECTION_ENABLEDNotrueEnable PII detection (always on in prod)
REDACT_SENSITIVE_FIELDSNotrueRedact sensitive fields (always on in prod)
SENSITIVE_FIELD_PATTERNSNoSee belowComma-separated sensitive field patterns

Default Sensitive Field Patterns:

SENSITIVE_FIELD_PATTERNS=email,password,token,secret,key,authorization

Production automatically adds: user_id,session_id,correlation_id,request_id,ip_address,user_agent

Adaptive Batching Performance Tuning​

VariableRequiredDefaultDescription
ADAPTIVE_BATCH_MIN_LATENCYNo100Minimum target latency (ms)
ADAPTIVE_BATCH_MAX_LATENCYNo10000Maximum target latency (ms)
ADAPTIVE_BATCH_TARGET_LATENCYNo2000Target latency for optimization (ms)
ADAPTIVE_BATCH_ADJUSTMENT_FACTORNo0.1Batch size adjustment factor

Optional Configuration Variables​

Development Tools​

VariableRequiredDefaultDescription
ENABLE_GRAPHQL_PLAYGROUNDNotrueEnable GraphQL Playground UI
ENABLE_METRICS_ENDPOINTNotrueExpose metrics endpoint
ENABLE_DEBUG_LOGGINGNotrueEnable debug-level logging
ENABLE_GRAPHQL_ERROR_LOGGINGNotrueLog GraphQL errors

Rate Limiting​

VariableRequiredDefaultDescription
RATE_LIMIT_MAX_REQUESTSNoProduction: 100
Dev: 500000000
Requests per minute limit

Logging​

VariableRequiredDefaultDescription
LOG_LEVELNoinfoLog level (trace, debug, info, warn, error, fatal)

Legacy/Compatibility​

VariableRequiredDefaultDescription
IMAGE_STORAGE_TYPENolocalLegacy image storage type
LOG_BATCH_SIZENo1000Legacy log batch size
LOG_FLUSH_INTERVALNo5000Legacy log flush interval
METRICS_PUSH_INTERVALNo15000Legacy metrics push interval
ENVIRONMENTNodevelopmentLegacy environment variable

Configuration Logic & Dependencies​

Object Storage Provider Logic​

if OBJECT_STORAGE_PROVIDER=R2 then
# R2 variables are required
R2_ACCOUNT_ID=required
R2_ACCESS_KEY_ID=required
R2_SECRET_ACCESS_KEY=required
R2_USER_ASSETS_BUCKET_NAME=required
R2_EXERCISE_ASSETS_BUCKET_NAME=required
# R2_APP_ASSETS_BUCKET_NAME=optional
# R2_ENDPOINT_OVERRIDE=optional

# MinIO variables are ignored
MINIO_*=ignored

elif OBJECT_STORAGE_PROVIDER=MINIO then
# MinIO variables are required
MINIO_ENDPOINT=required
MINIO_ACCESS_KEY=required
MINIO_SECRET_KEY=required
MINIO_USER_ASSETS_BUCKET_NAME=required
MINIO_EXERCISE_ASSETS_BUCKET_NAME=required
# MINIO_PORT=optional (default: 9000)
# MINIO_USE_SSL=optional (default: false)
# MINIO_APP_ASSETS_BUCKET_NAME=optional

# R2 variables are ignored
R2_*=ignored

Environment-Based Security Requirements​

if NODE_ENV=production then
COOKIE_SECRET=required (application fails without it)

if OBSERVABILITY_ENABLED=true then
LOKI_ENDPOINT=required
LOKI_USERNAME=required
LOKI_PASSWORD=required
PROMETHEUS_ENDPOINT=required
PROMETHEUS_USERNAME=required
PROMETHEUS_PASSWORD=required
fi

# Privacy settings always enabled regardless of flags
PII_DETECTION_ENABLED=true (forced)
REDACT_SENSITIVE_FIELDS=true (forced)

else
COOKIE_SECRET=optional (warning shown if missing)
fi

Observability Batch Configuration Validation​

# These must maintain proper relationships
LOKI_MIN_BATCH_SIZE ≤ LOKI_BATCH_SIZE ≤ LOKI_MAX_BATCH_SIZE

# Buffer water marks must be sensible
10 ≤ LOG_BUFFER_LOW_WATER_MARK < LOG_BUFFER_HIGH_WATER_MARK ≤ 95

# Timeouts must be ordered correctly
LOKI_CONNECTION_TIMEOUT < LOKI_REQUEST_TIMEOUT

# Retry configuration must be reasonable
LOKI_RETRY_DELAY ≤ LOKI_RETRY_MAX_DELAY
LOKI_RETRY_ATTEMPTS ≤ 10

# Circuit breaker thresholds
1 ≤ CIRCUIT_BREAKER_ERROR_THRESHOLD ≤ 100

# Adaptive batching latency ordering
ADAPTIVE_BATCH_MIN_LATENCY < ADAPTIVE_BATCH_MAX_LATENCY

Environment-Specific Configuration Examples​

Development (.env.development)​

NODE_ENV=development
PORT=8000
MONGO_DATABASE_URL=mongodb://localhost:27017/openfit-dev
COOKIE_SECRET=dev-cookie-secret-minimum-32-characters

# Development JWT keys
JWT_PRIVATE_KEY_PATH=./dev-private.pem
JWT_PUBLIC_KEY_PATH=./dev-public.pem
CORS_ORIGIN=^http://localhost

# Local MinIO for development
OBJECT_STORAGE_PROVIDER=MINIO
MINIO_ENDPOINT=localhost
MINIO_PORT=9000
MINIO_ACCESS_KEY=minioadmin
MINIO_SECRET_KEY=minioadmin
MINIO_USE_SSL=false
MINIO_USER_ASSETS_BUCKET_NAME=dev-user-assets
MINIO_EXERCISE_ASSETS_BUCKET_NAME=dev-exercise-assets

# Development tools
ENABLE_GRAPHQL_PLAYGROUND=true
ENABLE_DEBUG_LOGGING=true
LOG_LEVEL=debug

# Relaxed rate limiting
RATE_LIMIT_MAX_REQUESTS=500000000

# Simple observability
OBSERVABILITY_ENABLED=false
ENABLE_LOCAL_FALLBACK=true

Production (.env.production)​

NODE_ENV=production
PORT=8000
MONGO_DATABASE_URL=mongodb+srv://user:pass@cluster.mongodb.net/openfit-prod?retryWrites=true&w=majority
COOKIE_SECRET=super-secure-production-cookie-secret-64-characters-minimum

# Production JWT keys (secure file permissions)
JWT_PRIVATE_KEY_PATH=/app/secrets/jwt-private.pem
JWT_PUBLIC_KEY_PATH=/app/secrets/jwt-public.pem
CORS_ORIGIN=^https://yourdomain\.com$

# Cloudflare R2 for production
OBJECT_STORAGE_PROVIDER=R2
R2_ACCOUNT_ID=your-production-account-id
R2_ACCESS_KEY_ID=your-production-access-key
R2_SECRET_ACCESS_KEY=your-production-secret-key
R2_USER_ASSETS_BUCKET_NAME=openfit-prod-user-assets
R2_EXERCISE_ASSETS_BUCKET_NAME=openfit-prod-exercise-assets
R2_APP_ASSETS_BUCKET_NAME=openfit-prod-app-assets

# Production security
ENABLE_GRAPHQL_PLAYGROUND=false
ENABLE_DEBUG_LOGGING=false
LOG_LEVEL=warn
RATE_LIMIT_MAX_REQUESTS=100

# Enterprise observability
OBSERVABILITY_ENABLED=true
LOKI_ENDPOINT=https://logs-prod-012.grafana.net/loki/api/v1/push
LOKI_USERNAME=123456
LOKI_PASSWORD=your-loki-api-key
PROMETHEUS_ENDPOINT=https://prometheus-prod-12-abc.grafana.net/api/prom/push
PROMETHEUS_USERNAME=123456
PROMETHEUS_PASSWORD=your-prometheus-api-key

# Production performance tuning
LOKI_BATCH_SIZE=1000
LOKI_BATCH_INTERVAL=5000
ENABLE_CIRCUIT_BREAKER=true
ENABLE_DATA_SANITIZATION=true
ENABLE_ADAPTIVE_BATCHING=true

# Service identification
SERVICE_NAME=openlift-service
SERVICE_VERSION=1.2.0
DEPLOYMENT_ENVIRONMENT=production
CLUSTER_NAME=prod-cluster-us-east

Configuration Validation​

The service validates configuration on startup and will fail with clear error messages for:

  • Missing Required Variables: Database URL, JWT keys, object storage credentials
  • Invalid Combinations: Conflicting object storage provider settings
  • Production Security: Missing cookie secret in production
  • Observability Logic: Invalid batch sizes, timeout ordering, threshold ranges
  • File Permissions: JWT key files not readable
  • Network Configuration: Invalid MongoDB connection strings

Health Monitoring Endpoints​

When observability is enabled, these endpoints are available:

  • Health Check: GET /health/logging - Service health status
  • Metrics: GET /metrics/logging - Performance metrics
  • Manual Flush: POST /admin/logging/flush - Force log flush

Best Practices​

Security​

  • Use strong, unique secrets (32+ characters for COOKIE_SECRET)
  • Secure JWT key file permissions (600 or 400)
  • Enable HTTPS in production
  • Use proper CORS origin patterns
  • Never commit secrets to version control

Performance​

  • Use appropriate batch sizes for your log volume
  • Enable compression for high-volume deployments
  • Configure circuit breakers for reliability
  • Monitor buffer usage and adjust water marks
  • Use R2 for better global performance

Reliability​

  • Always enable local fallback for logging
  • Configure appropriate retry policies
  • Set reasonable timeout values
  • Use correlation IDs for request tracing
  • Enable health checks in load balancers

Privacy​

  • Data sanitization is always enabled in production
  • Configure additional sensitive field patterns as needed
  • Review log retention policies
  • Use secure MongoDB connections with authentication
  • Regularly rotate access keys and secrets

For additional configuration help, see the Installation Overview or check the default.env file in the service repository.