Overview
Proper secret management is critical for maintaining the security of your infrastructure. The SGIVU Config Repository uses a combination of environment variable placeholders and external secret managers to keep sensitive data out of version control.Core Principles
Externalize Secrets
Use environment variable placeholders for all sensitive data
Provide Defaults
Include safe defaults for development environments
Separate by Environment
Use different secrets for dev, staging, and production
Private Repository
Maintain strict access control on the config repository
Environment Variable Placeholders
Syntax
Spring Cloud Config supports the placeholder syntax${VAR_NAME:default} where:
VAR_NAMEis the environment variable to readdefaultis an optional fallback value (can be omitted for required secrets)
Examples from the Repository
Database Credentials
Insgivu-auth-dev.yml:
Notice how
DEV_AUTH_DB_HOST and DEV_AUTH_DB_PORT have defaults for local Docker development, while DEV_AUTH_DB_NAME, DEV_AUTH_DB_USERNAME, and DEV_AUTH_DB_PASSWORD are required and have no defaults.OAuth2 Client Secrets
Insgivu-gateway.yml:
Internal Service Keys
Insgivu-auth.yml:
JWT Keystore Configuration
Insgivu-auth.yml:
Local Development with .env Files
For local development, create a.env file in your sgivu-docker-compose directory:
Separating Secrets by Environment
Use environment-specific variable names to prevent cross-environment contamination:External Secret Managers
For production environments, consider integrating with external secret management systems:AWS Secrets Manager
Store secrets in AWS and reference them via Spring Cloud AWS
HashiCorp Vault
Centralized secret storage with dynamic credentials
Azure Key Vault
Azure-native secret management solution
Kubernetes Secrets
Built-in Kubernetes secret management for containerized deployments
Integration Pattern
- Store secrets in your secret manager
- Configure the Config Server to read from the secret manager
- Use the same placeholder syntax in YAML files
- Let Spring Cloud Config resolve secrets at runtime
Common Mistakes to Avoid
Security Checklist
Before committing configuration changes:- All sensitive values use
${VAR_NAME}placeholders - No hardcoded passwords, tokens, or API keys
- Environment-specific variables use appropriate prefixes (
DEV_,PROD_) - Default values (if any) are safe for local development only
-
.envfiles are in.gitignore - Repository has appropriate access controls
- Secrets are documented in team password manager or secret system
Refreshing Secrets
When secrets change, services need to pick up new values:Using Docker Compose
Using Spring Boot Actuator
For services that support dynamic refresh:The
/actuator/refresh endpoint must be enabled in the service configuration and typically requires authentication in production.Best Practices Summary
- Never commit secrets - Use environment variables for all sensitive data
- Use descriptive names - Include environment and purpose in variable names
- Provide safe defaults - Only for local development, never for production
- Separate by environment - Use
DEV_,PROD_prefixes to prevent accidents - Use secret managers - Integrate with AWS Secrets Manager, Vault, etc. for production
- Document secrets - Keep a secure inventory of what secrets exist and where
- Rotate regularly - Establish a process for rotating credentials periodically
- Audit access - Monitor who accesses the config repository and secret systems