How you would manage externalized configuration and secure sensitive configuration properties in a microservices architecture?

In a microservices architecture, externalized configuration means storing application settings outside the application code so they can be changed without rebuilding or redeploying services. Sensitive properties such as passwords, API keys, database credentials, and tokens should be secured using encryption, secret management tools, and controlled access mechanisms.

Key Points: • Externalized configuration centralizes configuration management across multiple microservices. • Sensitive properties should never be hardcoded in source code or configuration files. • Spring Cloud Config, Vault, Kubernetes Secrets, and cloud secret managers are commonly used to secure configurations.

Example: Consider an e-commerce platform with multiple microservices:

• User Service • Order Service • Payment Service • Inventory Service

Instead of storing database credentials separately in each service, all configurations are managed centrally and securely distributed to the services.

Architecture:

Microservices ↓ Config Server ↓ Git Repository ↓ Encrypted Properties

Configuration Flow:

1. Configurations are stored in a central repository. 2. Spring Cloud Config Server exposes configurations. 3. Microservices fetch configurations during startup. 4. Sensitive values are decrypted securely before use.

Sample Configuration:

application-prod.yml

database: url: jdbc:mysql://prod-db username: app_user password: ENC(xyz123abc)

The encrypted password is decrypted at runtime.

Common Solutions:

1. Spring Cloud Config

• Centralized configuration management. • Supports multiple environments. • Allows dynamic configuration updates.

2. HashiCorp Vault

• Secure secret storage. • Dynamic credentials. • Encryption support.

3. Kubernetes Secrets

• Stores sensitive data securely in Kubernetes environments.

4. Cloud Secret Managers

Examples: • AWS Secrets Manager • Azure Key Vault • Google Secret Manager

Best Practices for Securing Sensitive Properties:

• Never hardcode passwords in source code. • Encrypt sensitive configuration values. • Use environment variables for secrets. • Restrict access using role-based permissions. • Rotate credentials regularly. • Enable audit logging for secret access.

Using Environment Variables:

spring.datasource.password=
${DB_PASSWORD}

The actual password is stored outside the application.

Benefits:

• Centralized configuration management. • Improved security. • Easier environment management. • Reduced configuration duplication. • Faster configuration updates without code changes.

Real-World Example:

A payment microservice requires:

• Database Credentials • API Keys • JWT Secret Keys

Instead of storing them in application.properties:

• Store secrets in Vault or AWS Secrets Manager. • Retrieve them securely at runtime. • Restrict access to authorized services only.

Production Architecture:

Microservice ↓ Spring Cloud Config ↓ HashiCorp Vault ↓ Encrypted Secrets

This approach provides centralized management and enterprise-grade security.

Interview Tip: A concise interview answer is: In a microservices architecture, I would use Spring Cloud Config to externalize configuration and maintain centralized configuration management. For sensitive properties such as passwords, API keys, and tokens, I would use secure solutions like HashiCorp Vault, Kubernetes Secrets, or cloud secret managers. Additionally, I would encrypt sensitive values, use environment variables where appropriate, and avoid storing secrets directly in source code or configuration files.