IICTPIICTP

Blog / Guides

Answers3 November 20264 min read

What is a secret in software, and how should you manage secrets?

A secret is any value that grants access, such as an API key, a database password, a token or a private key. Manage secrets by keeping them out of source code, storing them in a secrets manager or protected environment, limiting who and what can read them, and rotating them regularly.

In this post
  1. Why is putting a key in the code a problem?
  2. Where should secrets live instead?
  3. What should you do if a secret leaks?
  4. How do you stop leaks before they happen?
  5. Why rotate secrets?
  6. Sources and further reading

Why is putting a key in the code a problem?

Code is copied, shared and kept in version history forever. A key committed even once can be found by anyone who sees the repository, including automated scanners that look for exactly this. Deleting it in a later commit does not remove it from history.

Where should secrets live instead?

The twelve-factor method says configuration that varies between environments belongs in the environment, not in code. For anything sensitive, use a dedicated secrets manager or your platform’s secret store, which encrypts the value, controls who can read it and records access.

What should you do if a secret leaks?

  1. Revoke or rotate the secret immediately, before anything else.
  2. Check logs for any use of it you did not expect.
  3. Remove it from the code and, where practical, from history.
  4. Find out how it leaked and close that path.

How do you stop leaks before they happen?

Add secret scanning to the repository and to the pre-commit and pipeline checks, keep local configuration files in the ignore list, and give each service its own credentials so one leak has a small reach. This applies least privilege.

Why rotate secrets?

A secret that never changes stays valuable to an attacker forever. Regular rotation, and short-lived credentials where the platform supports them, limit how long a stolen value remains useful.

Sources and further reading

  1. Wiggins, A. The Twelve-Factor App, III. Config. 12factor.net/config.
  2. OWASP. Secrets Management Cheat Sheet. cheatsheetseries.owasp.org.

Go deeper: CTP™ credential · the TPBOK™ standard · Check your experience

IICTP is an independent technical credentialing body.

Keep reading

← All posts

New guides in your inbox

Plain-language guides on technical practice, now and then. You confirm your address first, and you can unsubscribe at any time.

Where do you stand?

Find the credential that fits the work you do.