DevSecOps

Secrets management: getting credentials out of your repositories

How to centralise credentials, replace long-lived secrets with short-lived ones, rotate without breaking consumers, and respond when a secret leaks.

DevOpsArk SecuritySecurity engineering, DevOpsArkPublished 10 June 2026 · Updated 16 August 20267 min read
TL;DR

The aim is to reduce the number of long-lived credentials to as close to zero as possible. Centralise what exists, replace static credentials with short-lived or dynamically issued ones wherever the backend supports it, coordinate rotation so consumers do not break, and audit every read. Deleting a committed secret from a repository does not remove it from history or invalidate it.

Short answer

What is secrets management?

Secrets management is the practice of storing, scoping, distributing, rotating and auditing credentials such as passwords, API keys, tokens and certificates, so they are not embedded in code, configuration files or CI settings. The goal is that credentials are short-lived, narrowly scoped and their use is recorded.

Where secrets actually live

Before improving anything, find the copies. In most organisations they are in more places than expected: CI variables, Kubernetes Secret objects, environment files on servers, Terraform state, a shared password manager, container image layers, and Git history from a commit three years ago that someone reverted but did not rotate.

The last one deserves emphasis because it is consistently misunderstood: deleting a file containing a credential in a later commit does not remove it from history, and it certainly does not invalidate the credential.

The hierarchy, from worst to best

ApproachAssessment
Hard-coded in sourceUnacceptable. In history forever, distributed with every clone
CI variablesCommon and weak. Long-lived, broadly scoped, rarely rotated, no read audit
Kubernetes Secret objectsBetter with encryption at rest and tight RBAC, but still long-lived with no rotation or audit
Central store with scoped accessGood. One current copy, scoped, audited, rotatable
Short-lived tokens per runBetter. Nothing durable is handed out
Dynamically issued credentialsBest. Created per lease and revoked automatically, so there is nothing to rotate

Rotation without an outage

Rotation gets deferred because it breaks things, and it breaks things because it is usually done as a single atomic swap while consumers are still holding the old value.

  1. Create the new credential while the old one remains valid: both work during the overlap.
  2. Update consumers, tracking which have picked up the new value.
  3. Verify no consumer is still authenticating with the old credential, using the access audit.
  4. Revoke the old credential.
  5. Confirm nothing broke, and only then close the rotation.

The step teams skip is the third, which is precisely the one that turns rotation from risky into routine. Being able to see who last used a credential is what makes revocation safe.

When a secret leaks

Assume compromise. A credential in a repository (even a private one) has been on developer laptops, in CI caches and in clones. Rewriting history is useful housekeeping but it is not remediation.

  1. Rotate immediately. This is the only step that actually removes the exposure.
  2. Check the access audit for use from unexpected sources or at unexpected times.
  3. Determine the exposure window: when it was committed, when it was found.
  4. Find every consumer, so rotation does not break something you forgot.
  5. Then clean history, and add a pre-commit check so the same class of mistake is caught earlier next time.
Verify whether it still works. A leaked credential that has already been revoked is a housekeeping task. One that is still valid is an incident. Checking which it is should be the first thing after detection, not an afterthought.

Key takeaways

  • Find every copy first: CI variables, Secret objects, state files, image layers and Git history.
  • Deleting a committed secret does not remove it from history or invalidate it.
  • Prefer short-lived tokens, and dynamic credentials where the backend supports them.
  • Rotate with an overlap window and verify no consumer is still using the old value before revoking.
  • On a leak, rotate first and clean history afterwards.

Frequently asked questions

SecretsSecurityDevSecOps

See this working on your own infrastructure

A 30-minute walkthrough with a platform engineer. Bring the problem this article describes.