← All Dispatches

Storing provider API keys in an internal tool

The rule that prevents most key leaks is small: a key goes in and never comes back out. If an administrator can open a settings page and read a full provider key, then anyone who reaches that page can too — a compromised admin session, someone borrowing an unlocked laptop, a screenshot in a support thread, a screen share in a meeting. Write-only storage removes an entire class of exposure for the cost of one inconvenience: replacing a key you have lost rather than looking it up.

What a provider key actually is

It is a bearer credential that spends money. Whoever holds the string can call the provider as you, with your quota, billed to your account, until it is revoked. There is no second factor on an API call and usually no source restriction unless you configured one.

That makes it different from a password in one important way: passwords are attached to a person who notices when something is wrong. A key is attached to nobody. A leaked key can be used for weeks, and the only signal is a bill or a rate limit you did not expect.

Server-side, always

The key must live on the server and be used by the server. If the browser ever holds it — in a form field that renders the current value, in local storage, in a config the front end fetches — then it is in a place you do not control, on a machine you do not manage, exposed to every extension the user has installed.

The architectural consequence is that provider calls are made by your backend. The client asks your server for an answer; your server calls the provider. This is also what makes per-user limits, usage records and model allowlists enforceable, since all of them live on the path the request actually takes.

Write-only in the interface

Write-only means the form accepts a new value and never displays the old one. Show enough to identify which key is set — the provider, when it was last updated, perhaps a masked fragment — and nothing that can be reassembled into a working credential.

People push back on this, because they want to verify the right key is installed. The answer to that is a connection test rather than a readback: the server makes a cheap call and reports whether it worked. That answers the real question — is this key valid — without putting the string on a screen. Nodus Veritatis stores provider keys server-side and write-only, never showing them back in full, which is the behaviour to look for in any tool that holds credentials on your behalf.

Encrypt at rest, and know what that buys

Keys should be encrypted in the database with a key held outside it, so a database dump alone is not enough. Be clear-eyed about the scope: this protects against backup copies, misdirected exports and a stolen database file. It does not protect against an attacker who has code execution on the application server, because that process must be able to decrypt in order to work.

Which means the surrounding controls matter as much as the encryption. Restrict who can reach the server, keep the encryption key out of the same store and out of source control, and treat application compromise as the scenario where you rotate everything rather than the one your encryption was supposed to survive.

Scope narrowly at the provider

Most providers let you create multiple keys per account, and some support restricted keys. Use that. A separate key per application means revoking one does not break the others, and it tells you which system leaked when a key turns up somewhere it should not.

Where the provider offers per-key spending caps, project scoping or source restrictions, apply them. A cap is the difference between an unnoticed leak costing a rounding error and costing a month of budget. These are the cheapest controls available and the most commonly skipped.

Make rotation boring

Rotation only happens if it is uneventful. That means: adding a new key does not require downtime, the switch is a single action, and the old key is revoked at the provider afterwards rather than left dormant. If rotation requires a maintenance window, it will be deferred until an incident forces it, which is the worst possible time to do it for the first time.

Rotate on a schedule you will actually keep, and unconditionally on three triggers: someone with access leaves, a key appeared somewhere it should not have, or spend looks wrong. Revocation at the provider is the step that matters — removing a key from your tool while leaving it valid upstream changes nothing about what an attacker holding it can do.

Log the handling, not the key

Record who set or replaced a key and when. That is an audit question reviewers ask, and it is the record that tells you whether an unexpected change was legitimate.

What must never be recorded is the value. Keys leak into logs through error messages that dump request headers, debug output that prints a config object, and exception trackers that capture local variables. Redact at the logging layer rather than trusting every call site to be careful, and check your error reporting specifically, since that is the path that captures the most context at the worst moment.

The short version

Server-side only. Write-only in the interface, with a connection test instead of a readback. Encrypted at rest with the encryption key held elsewhere. One key per application, scoped and capped at the provider where possible. Rotation that takes a minute and no downtime. Revoke upstream, not just locally. Log the change, never the value.

None of this is difficult. It is mostly a matter of deciding it before the first key is pasted in, because retrofitting write-only storage means every key currently in the system has already been readable and should be replaced.