Secrets management basics: API keys, passwords and rotation, from OWASP's cheat sheet
Plan controlled storage, access, rotation and revocation for application credentials while keeping secrets out of code and logs.
- Centralise and standardise
- Use a managed way to store, provision, audit and rotate secrets; it should be clear what a secret is for and where to find it.
- Automate, least privilege
- Manual handling raises leak and error risk, and engineers should not have access to all secrets - anyone who can read a secret can leak it.
- Rotate so theft expires fast
- Regular rotation means a stolen credential works only briefly; per NIST, user credentials rotate when compromise is suspected, not on a schedule.
All wording checked against the OWASP Secrets Management Cheat Sheet linked in Sources.
Secrets include API keys, database credentials and private SSH or signing keys. IAM permissions describe access policy, not a secret value; certificates may be public while their private keys must be protected. OWASP's Secrets Management Cheat Sheet, read on 15 November 2026, describes how to handle them. We read it except the cloud-provider detail (section 4.1 onwards) and the encryption section (7). This is one source's checklist and does not certify any setup. The sheet notes many organisations hard-code secrets in plain text in source code and configuration, and that services often share the same secret, which makes the source of a leak hard to find.
Core practices
- Centralise and standardise. Use a managed way to store, provision, audit and rotate secrets. It should be clear what a secret is used for and where to find it. More tools mean more documentation.
- Least privilege. Engineers should not have access to all secrets, since anyone who can read a secret can leak it.
- Automate. Manual handling raises leak and error risk. Options: a secrets pipeline, dynamic secrets (an app requests database credentials at startup, with a short lease, revoked when done) and automated rotation of static secrets.
- High availability. Both people (in incident response) and applications (at start-up) depend on the secrets service being fast and reliable.
- TLS everywhere. Never send secrets in plain text.
- Auditing. At minimum record who requested a secret and for what, whether it was approved, when it was used, when it expired, attempts to reuse expired secrets, authentication errors, updates and admin actions. Audit logs must resist tampering, and clocks must be synchronised.
- Metadata. Record creation, rotation and deletion times, owner contact, purpose and type, so you can move the secret later. The sheet says skipping this raises vendor lock-in.
- Break-glass and backups. Plan for the secrets service being down: test restores, encrypt backups and limit access, and keep emergency credentials backed up in a second system.
Lifecycle
- Creation: generate securely and strongly enough for the purpose, with minimum privileges; do not send the password with the username when provisioning accounts.
- Rotation: rotate regularly so a stolen credential works only briefly. Lifetimes range from minutes to years depending on function. The sheet excludes user credentials from regular rotation, per NIST: rotate those when compromise is suspected. Rotating encryption keys may need data re-encryption, with strategies such as writing with new keys while keeping old keys for reading.
- Revocation: revoke when no longer needed or possibly compromised.
- Expiration: set an expiry where possible so rotation is triggered.
Rotation patterns described: a Kubernetes sidecar that fetches secrets into an in-memory shared volume, and a cloud secrets manager invoking a rotation function in steps (create, set, test, finish).
Creation
Generate securely and strongly enough for the purpose, with minimum privileges.
Rotation
Rotate regularly so a stolen credential works only briefly; lifetimes range from minutes to years depending on function.
Revocation
Revoke when no longer needed or possibly compromised.
Expiration
Set an expiry where possible so rotation is triggered.
Secrets in memory
The sheet says to start with a threat model; protecting memory is often overkill, but may be worth it in sensitive settings. Measures it lists: avoid immutable strings in .NET and Java (use byte or char arrays you can overwrite), zero memory after use, and memory encryption where available.
Identity providers
OpenID Connect delegates user login but does not require passwordless authentication and does not remove phishing or weak passwords at the identity provider. Choose one that enforces strong controls, such as WebAuthn. Tokens and client credentials still need protecting, and OIDC does not replace database credentials or API keys.
CI/CD
- Secrets stored in CI/CD tools (such as GitHub or GitLab secrets) are exposed to pipeline jobs and project maintainers. Avoid high-value, long-lived or widely scoped credentials there, review who can view or change them, check that forks do not copy them, rotate on a schedule and document them.
- Fetching from a secrets manager at run time is better: authenticate runners with short-lived OIDC tokens (workload identity federation) instead of static cloud keys, grant secret access separately from token exchange, use short-lease credentials, and keep requests attributable to the user, trigger or commit.
- The sheet's recommended approach keeps runtime secrets out of the pipeline entirely: the pipeline deploys with a platform identity and the service fetches its own secrets.
- CI/CD service accounts get least privilege.
Containers
Build-time secrets are not recommended. Three ways to get secrets into a container: mounted volumes (mounted by the orchestrator, never built in), fetching from a secret store through a sidecar (in memory), and environment variables overwritten by the orchestrator. Never hard-code secrets with Docker ENV or ARG, since they leak with the container definition. Expose secrets only to intended containers. A deliberately restricted in-memory volume shared with a secrets sidecar is different from an unrestricted shared volume; keep that access narrow, and encrypt the orchestrator's secret storage.
Dynamic or static
Dynamic secrets suit short-lived credentials for connecting services, session-length keys and deployment-time credentials. The sheet notes they often need long-term static secrets to create them, and some uses stay static (storage encryption keys, TLS PKI keys, services that cannot issue temporary credentials). Limit who and what can read secrets; if a tool cannot restrict access, consider separate secrets managers for production and development. Monitor who accesses a secret and from where; the sheet says to alert and assume compromise if CI/CD credentials are used from an unexpected IP. Define alerts for anomalous retrieval and attempts to write secrets to logs.
Detection
Approaches listed: shared test secrets to cut false positives, detection in the IDE or a pre-commit hook, treating secrets as part of the threat model, more than one detection tool with de-duplicated results, and a balance between easy-to-detect formats and not missing human-created passwords. Types to detect include tokens that are hard to rotate, configuration files, connection strings, API keys, passwords, 2FA keys, private keys, session tokens and platform-specific secrets. Secrets must never be logged. Document who has access, how it rotates, dependencies that rotation could break, and the incident contact.
For a small team, as questions
- Is any secret in your source repository or chat history?
- Who can read production secrets today?
- What would you rotate first after a leak, and do you know how?
- Do two services share one key?
Limits
We did not read the sheet's cloud provider selection, envelope encryption and IAM detail (section 4) or its encryption section (7), and we recommend no specific product. We quote no breach statistics.
By Omnistu.