Where to Store JWT Secrets: Env Vars vs Vault vs KMS
Choosing where to store your JWT secrets is one of the most consequential security decisions in your application architecture.
Environment Variables
The simplest approach — store the secret in your deployment environment.
Pros:
- Zero infrastructure overhead
- Supported natively by every platform
- Easy local development setup
Cons:
- Secrets appear in process listings
- No automatic rotation
- Risk of accidental exposure in logs
Best for: Small projects, early-stage startups, simple deployments.
JWT_SECRET=your-256-bit-secret-hereHashiCorp Vault
A dedicated secrets management platform with dynamic secrets, fine-grained access control, and audit logging.
Pros:
- Centralized secret management
- Automatic rotation with lease TTLs
- Full audit trail
- Dynamic secret generation
Cons:
- Significant operational overhead
- Requires dedicated infrastructure
- Learning curve for teams
Best for: Medium to large teams with dedicated DevOps/platform engineering capacity.
const vault = require('node-vault')({ endpoint: 'https://vault.internal' });
const { data } = await vault.read('secret/jwt');
const secret = data.jwt_secret;Cloud KMS (AWS KMS, Google Cloud KMS, Azure Key Vault)
Managed key management services provided by cloud providers — keys never leave the HSM.
Pros:
- Hardware Security Module (HSM) backed
- No key material ever exposed
- Built-in rotation, auditing, and access control
- Compliance-ready (SOC2, HIPAA, PCI-DSS)
Cons:
- Latency on each signing operation
- Vendor lock-in
- Additional cost
Best for: Enterprise, regulated industries, high-security requirements.
Recommendation
| Stage | Recommendation |
|---|---|
| Development | Environment variables |
| Production (small) | Secrets manager (AWS Secrets Manager, Doppler) |
| Production (enterprise) | Cloud KMS with envelope encryption |