🫙 Secrets in the Cloud: Leaky Buckets, Tokens, and What to Do About Them
By James K. Bishop, vCISO | Founder, Stage Four Security
Secrets—like API keys, access tokens, and database credentials—are the connective tissue of modern cloud applications. But they’re also one of the most frequent causes of cloud breaches.
Why? Because secrets aren’t just stored. They’re committed to repos, injected into containers, passed through CI/CD pipelines, and sometimes left in object storage buckets with public access.
⚠️ What Counts as a Secret (and Where They Linger)
- API keys (AWS, GCP, Stripe, Twilio, SendGrid, etc.)
- SSH private keys or known_hosts fingerprints
- Database connection strings and hardcoded credentials
- OAuth tokens, session cookies, JWTs
- Cloud access keys (e.g., AWS_ACCESS_KEY_ID, AZURE_CLIENT_SECRET)
Secrets often linger in:
- Git repositories (even after removal)
- Environment variables inside containers
- Object stores like S3, Blob Storage, or GCS
- Build logs, Terraform state files, and CI/CD artifacts
🔓 How Secrets Get Exposed
- Public GitHub commits—even temporarily—are scanned by bots in seconds
- Improper access controls on S3 buckets or storage accounts
- Leaky build pipelines that log environment variables or secrets in plaintext
- Shared Slack channels, Confluence pages, or email threads with embedded credentials
- Terraform state files with embedded cloud provider secrets not encrypted at rest
🛠️ How to Detect Secrets Before Attackers Do
- Pre-commit hooks: Use
pre-commit + detect-secretsorgitleaksto scan before pushing code - Secrets detection in CI/CD: Run TruffleHog, Gitleaks, or GitGuardian during pull requests and builds
- Monitor public repos: Use GitHub’s native secret scanning (or GitHub Advanced Security) for automatic key detection
- Entropy + regex-based scanning: Identify high-risk patterns even for custom tokens
🔐 How to Secure Secrets at Rest and in Transit
- Use a secrets manager: AWS Secrets Manager, HashiCorp Vault, Azure Key Vault, Doppler, or 1Password Developer
- Inject secrets at runtime: Never bake credentials into images or configs—inject them via environment variables, volume mounts, or service meshes
- Rotate secrets frequently: Automate TTL and key rotation using vault policies or lambda triggers
- Limit blast radius: Use IAM conditions to scope secrets (e.g., IP, region, or workload identity)
📦 Secrets in Object Storage: The “Leaky Bucket” Risk
Secrets don’t just leak in code—they leak in files. Credential exports, debug logs, and sensitive configs often end up in S3, Blob Storage, or GCS without tight access controls.
- Enforce bucket policies: Block public access at the org level and require encryption at rest
- Scan object stores: Use tools like Macie (AWS), Purview (Azure), or custom regex-based scans
- Monitor access patterns: Alert on external or unusual download behaviors
⏱️ If a Secret Leaks: What to Do Immediately
- Revoke it immediately: Disable the API key or credential—even if it’s not public anymore
- Audit logs: Look for unauthorized usage, downloads, or resource creation
- Rotate and re-issue: Create new secrets, with better constraints (TTL, IP, role)
- Scrub history: Use
git filter-repoto remove leaked data from Git history - Enable push protection: In GitHub or GitLab, prevent secrets from being committed again
📣 Final Thought
Secrets are high-value targets—and attackers know where to look. Securing the cloud means managing credentials like code: tightly scoped, monitored, and short-lived. Don’t leave secrets lying around where they don’t belong.
Need help implementing secure secret workflows, vaulting, or real-time scanning? Let’s talk.
