How to share API keys securely
Updated
Give the person the narrowest key that does the job, send it as a one-time encrypted link, and revoke it when the work is done. Each step limits the damage if the key ends up somewhere it shouldn't.
Where API keys usually leak
- Chat messages, which are searchable and kept for months or years.
- Tickets, wikis and email threads that many people can read.
.envfiles and config committed to a repository, where they stay in the history even after the file is fixed.- Screenshots and screen shares.
A key pasted into any of these keeps working for as long as the key does, long after the conversation is over.
Share a key in four steps
- Make a key for this person. Most providers let you create several keys and limit each one, for example to read-only access, one project or a test environment. Name it after the person or project, so you can revoke it later without breaking anything else.
- Send it as a one-time link. Paste the key into Your secret on AccountProxy Secrets, pick the shortest expiry that works (1 hour if they are waiting for it), leave One-time read on and press Create secret link. Post the link in chat or email. The message history then holds a dead link, not the key.
- Store it properly. The recipient puts the key in a secret manager or an environment variable, and keeps
.envin.gitignore. - Revoke it when you are done. When the project or the contract ends, delete that key in the provider's dashboard. Because it was only ever this person's key, nothing else stops working.
Sharing several values at once
Secrets are text, not file uploads. To hand over a set of variables, paste the contents of the .env file into one secret:
API_BASE_URL=https://api.example.com
API_KEY=sk_test_...
WEBHOOK_SECRET=whsec_...Your browser encrypts the text before it leaves your computer, and the key that decrypts it is the part of the link after the #, which browsers never send to a server.
If the link was already used
If your colleague opens the link and is told the secret is no longer available, someone pressed Reveal first. You cannot know who, so revoke that key and send a new one. This is the reason to give each person their own key: replacing it is a minute's work.