Skip to main content

Secret Management ๐Ÿ”‘

This document explains how sensitive configuration and secrets are managed securely in ShopVerse.

Secret management is critical for protecting credentials, tokens, and third-party integrations in a production-ready microservices system.


๐ŸŽฏ Why Secret Management Mattersโ€‹

Secrets include:

  • JWT signing keys
  • Database passwords
  • Kafka credentials
  • Razorpay API keys
  • OAuth / third-party tokens

If exposed, they can lead to:

  • Account compromise
  • Data breaches
  • Financial loss
  • Full system takeover

ShopVerse follows industry best practices to mitigate these risks.


๐Ÿง  Core Principlesโ€‹

ShopVerse secret management follows these principles:

  1. Secrets never live in source code
  2. Secrets are environment-specific
  3. Secrets are injected at runtime
  4. Least privilege access
  5. Easy rotation without code changes

๐Ÿ“ฆ Types of Secrets in ShopVerseโ€‹

Secret TypeExamples
AuthenticationJWT secret key
DatabasePostgreSQL, MongoDB passwords
MessagingKafka credentials
PaymentsRazorpay key & secret
InfrastructureService registry credentials

๐Ÿ” How Secrets Are Storedโ€‹

โœ… Environment Variables (Primary)โ€‹

All secrets are injected via environment variables.

Example:

JWT_SECRET=shopverse_jwt_secret_key
DB_PASSWORD=strong_db_password
RAZORPAY_KEY=rzp_test_xxxxx
RAZORPAY_SECRET=xxxxxx

Spring Boot automatically resolves these values.


๐Ÿงพ Spring Configuration Exampleโ€‹

jwt:
secret: ${JWT_SECRET}

spring:
datasource:
password: ${DB_PASSWORD}

razorpay:
key: ${RAZORPAY_KEY}
secret: ${RAZORPAY_SECRET}

No secret values appear in application.yml.


๐Ÿณ Docker & Docker Composeโ€‹

Secrets are passed to containers via environment variables.

services:
payment-service:
environment:
- RAZORPAY_KEY=${RAZORPAY_KEY}
- RAZORPAY_SECRET=${RAZORPAY_SECRET}

Secrets remain outside the image.


๐Ÿ”„ Environment Separationโ€‹

ShopVerse maintains separate secrets per environment:

EnvironmentPurpose
localDevelopment
testTesting
prodProduction

Each environment uses different credentials.


๐Ÿ” JWT Secret Handlingโ€‹

  • JWT secret is stored as an environment variable
  • Only Auth Service & API Gateway require access
  • Services never expose or log the secret
  • JWT secret rotation supported via redeploy

๐Ÿ’ณ Razorpay Secret Handlingโ€‹

  • Razorpay secret is never sent to frontend
  • Used only in Payment Service
  • Webhook signatures are verified using the secret
  • Secrets differ for test & production modes

๐Ÿ›ก๏ธ What NOT to Do (Avoided in ShopVerse)โ€‹

โŒ Commit secrets to GitHub โŒ Hardcode secrets in code โŒ Share secrets between services unnecessarily โŒ Log secret values โŒ Use same secret across environments


๐Ÿ” Secret Rotation Strategyโ€‹

ShopVerse supports safe secret rotation:

  1. Update secret in environment
  2. Restart affected service
  3. Old tokens naturally expire
  4. No code changes required

This ensures zero downtime rotation.


๐Ÿง  Future-Ready Improvementsโ€‹

For advanced setups, ShopVerse can integrate with:

  • HashiCorp Vault
  • AWS Secrets Manager
  • Azure Key Vault
  • Kubernetes Secrets

The current design allows plug-and-play migration.


๐Ÿ” Security Auditing & Debuggingโ€‹

  • Secrets are masked in logs
  • Configuration files are reviewed before commits
  • .env files are ignored via .gitignore
  • CI/CD pipelines inject secrets securely

๐Ÿง  Interview Explanation (One-Liner)โ€‹

โ€œWe manage all secrets using environment variables, never commit them to source control, and inject them at runtime to support secure rotation and environment isolation.โ€


๐Ÿ“Œ Summaryโ€‹

ShopVerse secret management ensures:

  • Strong protection of sensitive data
  • Clean separation between code and configuration
  • Environment-specific security
  • Production-ready operational practices

Secret management is treated as a first-class security concern.