Most breaches involving credentials trace back to a boring cause: a secret sitting somewhere it should not be - a repo, a CI log, an image layer. Fixing this is a progression, not a single switch.
Stop committing secrets
Add scanning so secrets never reach the repo in the first place.
- uses: gitguardian/ggshield-action@v1 # or trufflehog
env: { GITGUARDIAN_API_KEY: ${{ secrets.GITGUARDIAN_API_KEY }} }Move to a real store, then to dynamic secrets
Centralize secrets in a store like Vault, then graduate from static secrets to short-lived dynamic credentials that expire on their own.
# static (better): read at deploy time
vault kv get -field=password secret/app/db
# dynamic (best): a credential that self-destructs after its TTL
vault read database/creds/app-role- Never bake secrets into images (ENV/COPY) - they persist in history
- Prefer workload identity (OIDC, Kubernetes auth) over static tokens
- Rotate on a schedule and enable audit logging
The best secret is one that expired ten minutes ago and no longer works.
Start by stopping the leaks, centralize next, and aim for dynamic, short-lived credentials wherever your platform supports them.