Secrets Management and Credential Security

The Day Our Database Password Went Public on GitHub

2:15 PM, Friday afternoon. I was about to head out early when a message from GitHub's secret scanning bot appeared: "AWS credentials detected in public repository."

My heart sank. I checked the commit. Someone had pushed a .env file containing:

  • AWS Access Keys (with admin permissions)

  • Database passwords

  • API keys for payment gateway

  • JWT signing secrets

  • Third-party service credentials

The commit had been public for 47 minutes. GitHub had already detected it and alerted us. But we had no idea who else had seen it.

Within 15 minutes, we detected unauthorized API calls from IP addresses in three countries. Someone had found the keys and was already probing our infrastructure. We spent the entire weekend in incident response:

  • Rotating every credential in our entire infrastructure

  • Investigating unauthorized access

  • Notifying customers

  • Filing security incident reports

The root cause? A developer running git add . without checking what was being committed. One careless commit cost us a weekend of work and nearly breached our entire production environment.

This article covers the zero-trust secrets management architecture I built to make sure this never happens again.

What You'll Learn

  • Secrets management fundamentals and zero-trust principles

  • HashiCorp Vault integration and best practices

  • Cloud provider secret managers (AWS, Azure, GCP)

  • Dynamic secrets and automatic rotation

  • Secrets in CI/CD pipelines

  • Git secret scanning and prevention

  • Certificate and credential lifecycle management

The Secrets Problem

Modern applications have secrets everywhere:

spinner

Common anti-patterns:

  • Hardcoded in source code

  • Stored in config files in Git

  • Baked into container images

  • Shared via Slack/email

  • Never rotated

  • Overly broad permissions

HashiCorp Vault: The Foundation

Vault is the industry standard for secrets management.

Vault Installation and Setup

Vault Initialization

Storing Secrets in Vault

Dynamic Secrets

The killer feature of Vault: secrets that are generated on-demand and automatically expire.

PostgreSQL Dynamic Secrets

AWS Dynamic Credentials

Application Integration

Node.js with Vault

Kubernetes Integration

External Secrets Operator

Vault Agent Sidecar

CI/CD Secrets Management

GitLab CI with Vault

Secret Rotation

Automate credential rotation to limit blast radius.

Git Secret Scanning

Prevent secrets from ever reaching Git.

Pre-commit Hook with Gitleaks

GitLab Secret Detection

GitHub Secret Scanning

GitHub automatically scans for leaked secrets, but add custom patterns:

Best Practices

1. Never Commit Secrets

2. Use Short-Lived Credentials

3. Principle of Least Privilege

4. Audit Everything

5. Rotate Regularly

Key Takeaways

βœ… Never commit secrets to Git - Use secret managers βœ… Use dynamic secrets - Auto-generated, auto-expired βœ… Rotate credentials regularly - Limit blast radius βœ… Audit secret access - Know who accessed what βœ… Least privilege always - Grant minimum necessary access βœ… Scan for leaked secrets - Pre-commit hooks and CI/CD

What's Next

Now that secrets are managed, let's enforce security policies across the entire infrastructure. Next: Security Policy as Code with Open Policy Agent.


Next Article: Security Policy as Code β†’


Part of the DevSecOps 101 Series

Last updated