Most secret leaks are not clever attacks but ordinary rules that nobody wrote down: a key pasted into a repository, a token that never expires, a CI variable every maintainer can read. This cheat sheet condenses secrets management into rule tables you can adopt as an engineering standard: where secrets may live, when they must rotate, who and what may read them, where to detect leaks, and what to do in the first hour after one. It is for developers, platform engineers and the security teams who set their guardrails. The rules draw on the OWASP Secrets Management Cheat Sheet, the OWASP Non-Human Identities Top 10 for 2025 and NIST key management guidance. For the programme view (operating model, tooling choices, maturity), see the Secrets Management Guide.
Key takeaways
- A secret has one home. Store it in a secrets manager or a platform identity, never in code, images, tickets or chat; everything else is a copy to find and remove.
- Short-lived beats rotated, rotated beats static. Prefer workload identity federation and dynamic credentials; where a static secret is unavoidable, give it an owner, an expiry and automated rotation.
- Rotation has triggers, not just a calendar. Exposure, a leaver with access, a vendor incident and a scope change all force rotation regardless of schedule.
- Detect at four points. The developer machine (pre-commit), the platform (push protection), the pipeline (CI scanning) and runtime (secret use and audit logs) each catch leaks the others miss.
- Revoke first, then clean up. Deleting a leaked secret from a file or history does nothing for the copy an attacker already holds; revocation and rotation come before history rewriting.
How to use this template
- Adopt the rules as a standard: copy the rule tables into your engineering standards, replace [Organisation], [secrets manager] and [owner] placeholders, and mark each rule Must, Should or Could for your environment.
- Classify secrets first: rotation and access rules depend on class. Use the classes in section 2 or your own, and record the class as metadata on every secret.
- Turn rules into controls: each rule has a detection or enforcement point in section 4. A rule without a check will drift.
- Scope: machine secrets (API keys, tokens, database credentials, private keys, certificates, webhook URLs). User passwords follow different rules: OWASP notes that user credentials are excluded from regular rotation and should be rotated on suspicion or evidence of compromise, in line with NIST.
1. Storage rules
| # | Rule | Why | Check |
|---|---|---|---|
| S1 | Store every machine secret in [secrets manager] or replace it with a platform identity (managed identity, IAM role, Kubernetes service account with federation). | One audited home; OWASP recommends centralising and standardising | Inventory of secrets outside the manager trends to zero |
| S2 | No secrets in source code, configuration files committed to version control, scripts, infrastructure as code variables or container images. | OWASP NHI2:2025 lists hard-coding and plain text configuration as primary leak paths | Pre-commit and CI scanning (section 4) |
| S3 | Do not pass runtime application secrets through CI/CD; deploy with a platform identity and let the service fetch its own secrets at runtime. | OWASP calls this the recommended approach; it decouples build systems from production secrets | Pipeline variable review |
| S4 | If a secret must live in CI/CD tooling, keep it low-value and narrowly scoped, document it, and confirm forks and copied jobs cannot read it. | CI variables are exposed to jobs and maintainers | Quarterly CI secret review; see How to Audit CI/CD Secrets Scope |
| S5 | Prefer files or in-memory injection over environment variables for sensitive secrets, and never print secrets to logs. | Environment variables leak through crash dumps, debug output and child processes | Log scanning; see Environment Variables vs Secrets Manager |
| S6 | Encrypt secrets at rest with keys held in a KMS or HSM, and use TLS for every retrieval. | Protects the store and the path to it | Configuration baseline |
| S7 | GitOps: commit only secrets encrypted to an environment-specific key (for example a Sealed Secrets resource), never plain Kubernetes Secret manifests. | Only the target environment's controller can decrypt | Repository policy check |
| S8 | Record metadata for every secret: owner, consuming systems, class, created date, expiry, rotation method and dependencies. | OWASP: prepare to move the secret; without metadata, rotation breaks things | Metadata completeness metric |
| S9 | Plan for availability: back up the secrets manager, test restore and keep a documented break-glass path. | A secrets outage is a production outage | Restore test record |
Bootstrapping the first credential that unlocks the store is its own problem; see the Secrets Zero Problem Guide.
2. Rotation rules
OWASP's guidance is that secrets should be rotated regularly so a stolen credential works only for a short time, and that lifetimes range from minutes to years depending on function. NIST SP 800-57 Part 1 Rev. 5 frames this as the cryptoperiod: the time span a key is authorised for use. OWASP NHI7:2025 Long-Lived Secrets warns against credentials with distant or no expiry dates. The periods below are a starting template to set by policy, not values from those sources.
Rotation by secret class
| Class | Examples | Preferred model | Maximum lifetime (set by [Organisation]) |
|---|---|---|---|
| Cloud and CI access | Cloud access keys, deployment credentials | Federation (OIDC) with short-lived tokens; no static keys | [Hours for issued tokens] |
| Database credentials | Application database users | Dynamic credentials with lease TTLs | [Lease TTL; static fallback in days] |
| Third-party API keys | SaaS and AI model provider keys | Automated rotation through provider API where offered | [Days] |
| Signing and encryption keys | Token signing keys, data keys | KMS-managed rotation with versioning | [Per cryptoperiod policy] |
| Certificates | TLS and client certificates | ACME or internal CA automation | [Days] |
| Hard-to-rotate tokens | Legacy integration tokens, webhook URLs | Scoped down, monitored, scheduled for replacement | [Documented exception with expiry] |
Rotation triggers (rotate now, regardless of schedule)
| Trigger | Action |
|---|---|
| Secret found in code, logs, tickets, chat or an image | Revoke and rotate immediately (section 5) |
| A person with read access leaves or changes role | Rotate every secret they could read in plain text |
| Vendor, CI platform or dependency security incident | Rotate secrets held by or exposed to that party |
| Scope or privilege change for the consuming workload | Issue a new secret with the new scope; retire the old one |
| Secret past its expiry or cryptoperiod | Rotate automatically; alert if automation fails |
| Decommissioned service or integration | Revoke, not just delete; see Deleted but Not Revoked |
Rotation without downtime: create the new version, deploy consumers that accept both, switch, verify, then revoke the old version. Rotation that needs a manual change window will be skipped. See Credential Rotation at Scale.
3. Access rules
| # | Rule | Check |
|---|---|---|
| A1 | One secret per workload per environment; no sharing a secret between services, environments or people (OWASP NHI9:2025 NHI Reuse, NHI8:2025 Environment Isolation). | Duplicate value detection in the store |
| A2 | Grant read access per secret path to the consuming workload identity only; humans get write or rotate rights, not read, wherever possible. | Policy review; human read events |
| A3 | Separate the right to exchange an OIDC token or assume an identity from the right to read specific secrets. | Federation trust review |
| A4 | Preserve caller attribution: secret requests from pipelines must trace to the job, trigger or commit. | Audit log sampling |
| A5 | Minimum privilege on the secret itself: the key or token should carry only the scopes the workload needs. | Scope review against usage |
| A6 | No human use of machine credentials (OWASP NHI10:2025 Human Use of NHI). | Interactive use of service credentials alerts |
| A7 | Administrative access to the secrets manager is privileged access: MFA, just-in-time elevation, logged sessions. | PAM coverage of store admins |
To remove static cloud keys from pipelines entirely, see Workload Identity Federation vs Static Cloud Keys.
4. Detection rules
Detection points
| Point | What it catches | Mechanism | Notes |
|---|---|---|---|
| IDE and pre-commit | Secrets before they enter history | Pre-commit hook running an open-source scanner (for example Gitleaks or detect-secrets) | Developers can skip hooks, so treat as a convenience layer; see the Git Hooks and Pre-commit Security Guide |
| Push protection on the code platform | Secrets in pushes, web edits, uploads and API commits | Platform feature such as GitHub push protection | Bypasses create alerts and audit entries; restrict who can bypass with delegated bypass |
| CI scanning | Secrets in branches, pull requests, build logs and artefacts | Scanner step on every pull request plus full-history scans on a schedule | Fail the build on verified secrets; see How to find secrets in CI logs and build artefacts |
| Images and artefacts | Secrets baked into containers and packages | Image layer scanning in the registry | See How to find hard-coded secrets in container images |
| Collaboration tools | Secrets in chat, tickets and wikis | Scanning connectors and DLP rules | OWASP NHI2:2025 names public chat and file shares as leak paths |
| Runtime and audit | Misuse of a valid secret | Secrets manager audit logs, cloud and SaaS logs | The only point that sees a secret already stolen |
Runtime audit events to alert on
The OWASP cheat sheet lists what to audit at a minimum. Turn these into alerts:
- Use of an expired or revoked secret: a strong compromise signal; log every attempt.
- Retrieval by an unexpected identity or location: a workload reading a secret it has never read, or a human reading a machine secret.
- Authentication and authorisation errors: bursts against the store or against the service the secret unlocks, which may indicate attackers validating leaked secrets; see Leaked Secret Validation Detection.
- Bulk retrieval or listing: enumeration of many paths in a short window.
- Administrative changes: policy edits, audit log changes, new auth methods on the store.
- Clock problems: OWASP notes audit trails depend on correct timestamps, so monitor time sync on the store's infrastructure.
5. Leak response
The OWASP cheat sheet orders containment as revocation, rotation, deletion and logging. In practice:
- Revoke: de-authorise the exposed secret at the issuer immediately. Treat any secret that reached a public repository as compromised, even if it was removed minutes later.
- Rotate: issue a replacement through automation, with least privilege, and deploy it to consumers.
- Investigate use: pull the issuer's logs for the exposure window: who used the secret, from where, and what it touched.
- Remove copies: delete the secret from code, logs, tickets and images. Rewriting Git history is optional and has side effects (it breaks commit links); do it only after revocation. See How to Remove Secrets From Git History.
- Fix the cause: move the secret to [secrets manager] or replace it with federation, and add the missing detection point.
- Record: owner, exposure path, time to revoke, time to rotate and evidence of use, for metrics and lessons learned.
For full playbooks, see the API Key Leak Response Playbook and the Cloud Access Key Leak Playbook.
6. Metrics and framework mapping
| Metric | Target direction |
|---|---|
| Secrets stored outside the approved manager | Down to zero |
| Share of secrets with automated rotation or replaced by federation | Up |
| Secrets past maximum lifetime | Down; see How to measure secret age and rotation coverage |
| Median time from detection to revocation | Down (hours, not days) |
| Push protection bypasses per month and share reviewed | Bypasses down, review at 100% |
| Secrets with complete metadata (owner, expiry, consumers) | Up |
| Framework | Reference |
|---|---|
| NIST SP 800-53 Rev 5 | IA-5 Authenticator Management; IA-5(7) No Embedded Unencrypted Static Authenticators; SC-12 Cryptographic Key Establishment and Management; SC-28 Protection of Information at Rest; AC-6 Least Privilege; AU-6 Audit Record Review, Analysis, and Reporting |
| NIST CSF 2.0 | PR.AA-01 identities and credentials managed; PR.DS-01 data at rest protected; DE.CM-09 runtime environments monitored |
| OWASP NHI Top 10 2025 | NHI2 Secret Leakage; NHI7 Long-Lived Secrets; NHI8 Environment Isolation; NHI9 NHI Reuse; NHI10 Human Use of NHI |
| MITRE ATT&CK v20 | T1552.001 Credentials In Files; T1552.004 Private Keys; T1528 Steal Application Access Token; T1078.004 Cloud Accounts |
Practitioner checklist
- Publish the storage, rotation and access rules as an engineering standard with an owner.
- Inventory secrets and record owner, class, expiry, consumers and rotation method for each.
- Replace static cloud and CI keys with workload identity federation.
- Automate rotation for every class that supports it and document exceptions with an expiry date.
- Enable pre-commit scanning, platform push protection with restricted bypass, and CI scanning on every pull request.
- Alert on use of revoked or expired secrets, unexpected retrieval and bulk listing in the secrets manager.
- Rehearse the leak response: revoke, rotate, investigate use, remove copies, fix the cause.
- Report the six metrics monthly and review exceptions quarterly.
Standards and references
- OWASP: Secrets Management Cheat Sheet
- OWASP: Non-Human Identities Top 10 2025, NHI2 Secret Leakage
- OWASP: Non-Human Identities Top 10 2025, NHI7 Long-Lived Secrets
- NIST: SP 800-57 Part 1 Rev. 5, Recommendation for Key Management
- NIST: SP 800-53 Rev 5 Security and Privacy Controls
- GitHub Docs: About push protection
- Gitleaks: project documentation
Related NHI Mgmt Group resources: Secrets Management Guide · Dynamic Secrets and Ephemeral Credentials Guide · OWASP NHI Top 10 NHI2 Secret Leakage Guide · OWASP NHI Top 10 NHI7 Long-Lived Secrets Guide · Workload Identity Federation Guide