API key
A secret string that identifies and authorises a program calling an API, usually sent in a header.
Anyone holding the key can use the service as your application until it is revoked.
In more detail
Unlike a user token, an API key is often long-lived and tied to a set of permissions. Treat it as a secret: never commit it or log it, and rotate it if it leaks.
Examples
API_KEY = os.environ["API_KEY"] # III: secrets from envThe course's fake key sk-live-4d1f-demo travels through a committed file, an environment variable, a log line and a secret manager to show each route a key can leak by.Related terms
- secret — Any value that grants access, such as a password, access token or private key, and must be kept out of code and version control.
- config — Everything about an application that varies between deploys, such as database addresses, credentials and hostnames.
- open source test — The twelve-factor app's check for config: could this codebase be made open source right now without exposing any credential?
- key rotation — Replacing a password or key with a new one on a schedule or after a suspected leak, and re-encrypting what it protected.
- access token — A generated string that proves who you are to a service, used instead of a password and revocable on its own.
- redaction — Removing or hiding sensitive values, such as tokens or personal data, before data is logged, displayed or shared.
- authentication — Establishing who a request represents, for example by checking a password, a session cookie or a signed token.
- JSON Web Token — A compact signed token made of three base64url parts separated by dots: a header, a payload of claims and a signature.
Taught in
- Secrets, Keys And Certificates In Pipelines — Microsoft Azure DevOps Engineer Expert (AZ-400) Exam Prep
- Config And Backing Services — DevOps & Site Reliability Engineering
- Reusable Workflows: Inputs, Secrets And Outputs Across A Call — GitHub Actions (GH-200) Exam Prep
- Secrets And Variables By Scope: Precedence, Access And The REST API — GitHub Actions (GH-200) Exam Prep
- Full Mock And Review: Where Your Points Go — GitHub Actions (GH-200) Exam Prep
- Why Secrets Leak — Application Security & Threat Modeling for Engineers
- The Environment Variable Trap — Application Security & Threat Modeling for Engineers
- Moving To A Secret Manager — Application Security & Threat Modeling for Engineers
- The in Operator And Instanceof Narrowing — Production TypeScript
References
- Google Cloud: manage API keys
- OWASP API Security: API2 Broken Authentication
- OWASP Secrets Management Cheat Sheet
- OWASP REST Security Cheat Sheet