Overview
Security is paramount in a Spring Cloud Config repository. This guide covers best practices for managing sensitive data, authentication, and access control.Secret Management
Environment Variable Placeholders
All sensitive configuration values must use Spring’s${VAR_NAME} placeholder syntax, which resolves from environment variables at runtime:
You can provide default values using the colon syntax:
${VAR_NAME:default_value}. This is useful for non-sensitive values like hostnames or ports.Critical Secrets to Protect
The following secrets must never be committed in plain text:Database Credentials
DEV_AUTH_DB_USERNAMEDEV_AUTH_DB_PASSWORDDEV_USER_DB_PASSWORD
OAuth2 & JWT
SGIVU_GATEWAY_SECRETJWT_KEYSTORE_PASSWORDJWT_KEY_PASSWORD
Service Authentication
SERVICE_INTERNAL_SECRET_KEYREDIS_PASSWORD
Cloud Provider Keys
AWS_ACCESS_KEYAWS_SECRET_KEY
OAuth2 Client Security
Gateway OAuth2 Configuration
The API Gateway uses OAuth2 authorization code flow to authenticate users. The client secret must be stored securely:Generate a Strong Secret
Use a cryptographically secure random generator to create the client secret:
JWT Keystore Management
Thesgivu-auth service uses a Java KeyStore for JWT signing. All keystore credentials must be externalized:
Keystore Setup
Store Securely
Place the keystore file in a secure location outside the repository:
- Development:
/etc/sgivu/secrets/sgivu-jwt.jks - Docker: Mount as a volume
- Production: Use secret management service (AWS Secrets Manager, HashiCorp Vault)
Service-to-Service Authentication
Microservices use a shared secret key for internal API calls:- At least 32 characters long
- Randomly generated using a cryptographic generator
- Shared across all microservices via environment variables
- Rotated periodically (at least every 90 days)
Redis Session Security
The API Gateway stores sessions in Redis. Protect Redis with authentication:Redis passwords should be set in your Redis configuration and passed via environment variables. Never use Redis without authentication in production.
AWS Credentials
Services that integrate with AWS (likesgivu-vehicle for S3 storage) require AWS credentials:
Best Practices for AWS
Use IAM Roles
In production, prefer IAM roles over access keys. Assign roles to EC2 instances or ECS tasks.
Principle of Least Privilege
Grant only the minimum permissions required (e.g., S3 read/write to specific bucket).
Rotate Keys Regularly
If using access keys, rotate them every 30-90 days and invalidate old keys.
Never Commit Keys
Double-check that
.env files containing AWS keys are in .gitignore.Repository Access Control
Git Repository Permissions
Restrict Write Access
Only authorized team members should have write access. Use branch protection rules.
Config Server Authentication
The Spring Cloud Config Server should authenticate clients before serving configuration:Encryption at Rest and in Transit
In Transit (TLS)
In production, always use HTTPS/TLS for:
- Config Server endpoints
- Eureka Discovery Server
- All microservice communication
- OAuth2 authorization endpoints
At Rest (Spring Cloud Config Encryption)
Spring Cloud Config supports encrypting sensitive values in Git:Security Checklist
Before committing configuration changes:- All passwords use
${VAR_NAME}placeholders - No API keys or tokens in plain text
-
.envfiles are in.gitignore - OAuth2 client secrets are externalized
- JWT keystore credentials are not committed
- Service internal secret key is not exposed
- AWS credentials use IAM roles or are externalized
- Redis password is externalized
- Database credentials are externalized
- Production config has been reviewed by security team
Related Resources
Configuration Refresh
Learn how to refresh secrets without restarting services
Validation
Validate configuration before deploying
Monitoring
Monitor security-related metrics and health
Environment Profiles
Understand how profiles separate environments