Repository navigation
feat: store API keys as hashes - #161
Merged
Merged
Conversation
API keys were stored, held in memory and sent between nodes as the keys
themselves, so anyone who could read parseable.json could use every key.
Keep the SHA-256 of each key and its last four characters instead. Keys
are generated by the server from 122 random bits, so an unsalted fast
hash is enough, and it is computed once per request.
The key is returned by the request that creates it and cannot be read
back: GET /api/prism/v1/apikeys/{id} now returns it masked, as the list
does. Validation and request authentication compare hashes.
Records stored with the key are still read, and are written back hashed:
for the default tenant by the write every query or standalone node makes
at start, for other tenants by a write added to the tenant loader.
Existing keys keep working. Older versions cannot read the hashed
records, so this is a one-way change.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The server no longer keeps API keys, so the key list cannot copy one later. Remove the copy action and the client call behind it, and say on the creation sheet that the key is shown this once. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This was referenced Nov 24, 2026
…rmed stored hash Review follow-ups to storing API keys as hashes. - The rewrite of a tenant's metadata in the tenant loader updated storage but not this node's staging copy, which kept the key until the tenant's next change. Write both. - A stored hash in another form (uppercase, wrong length) loaded and never matched, without a word. Read it in any case, and warn when it is not a SHA-256 in hex. It still loads: refusing it would fail the whole metadata. - Say in the loader that it runs only where validate_multi_tenancy is called at start, which this repository's own main does not do. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Quest, upstream's integration suite, checks that GET
/api/prism/v1/apikeys/{id} returns the key itself. This server now keeps
only a hash and returns the mask, so that one assertion fails in the smoke
and the full runs. Patch the assertion in the pinned Quest source before
the test image is built, so the test still covers get, with this server's
contract. The patch step fails if the pinned source stops matching.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
API keys were stored, held in memory and sent between nodes as the keys themselves, and compared as plain strings. Anyone who could read
parseable.jsonin the object store or the staging directory could use every key.The server now keeps the SHA-256 of each key and its last four characters.
GET /api/prism/v1/apikeys/{id}returns the key masked (****abcd), as the list does. It used to return the full key.getApiKeyis removed from the client.Existing keys
Existing keys keep working. A record stored with the key itself is still read, and is written back hashed:
validate_multi_tenancyis called at start, which this repository's ownmaindoes not do. In this build a non-default tenant's keys are hashed in storage at that tenant's next metadata write.So the first start of a query or standalone node on this version removes the default tenant's keys from storage and from the staging copy.
Hashing does not reach copies made earlier: object-store versions, backups, and the bucket's
parseable.jsonafter an import into the Postgres metastore still hold the old keys. If any of those may have been read, rotate the keys.A stored hash that is not a SHA-256 in hex (a hand-edited record) loads, never matches, and is logged as a warning.
Difference from upstream
Upstream Parseable returns the key itself from
GET /api/prism/v1/apikeys/{id}, and its integration suite (Quest) asserts that. This server cannot, so that one assertion failed in CI. The workflow now patches it in the pinned Quest source to expect the mask (scripts/ci/quest-api-key-hash.patch), which keeps the test and covers both the PR smoke run and the full runs onmain. Any other client written against upstream that reads the key from this endpoint will get the mask.One-way change
Older versions cannot read the hashed records: they fail to parse the whole metadata as soon as one API key exists.
parseable.jsonby hand, and those keys are then gone.Verified
cargo test --lib: 1,431 passed, 0 failed. Clippy and rustfmt add no warnings tomain's.Frontend: type check, 2,428 unit tests, and the 51 team and API-key-expiration browser tests pass.
Against a running server with a local store:
X-API-Keyand byAuthorization: Bearer; a wrong key, the stored hash and the masked value each get 401;apiKey) is hashed in both files by the next start, and that key still authenticates;With all six PRs of this set merged together (feat: accept OTLP/HTTP protobuf on the logs, metrics and traces endpoints #156–feat: store API keys as hashes #161):
cargo test --lib1,515 passed, 0 failed, and on a running server every one of 17 protobuf requests (15 realistic shapes filling the 10 MiB payload limit, 2 crafted) returned 200 and stored the expected number of rows, authenticated with an API key.Reviewed
Two independent read-only reviews (Claude Opus 5.5 and GLM 5.3) found the hashing, the comparison, the serde handling and every response and sync payload sound. Their findings are addressed in the last commit (the tenant staging copy, the malformed-hash warning) and in the notes above (upgrade order, earlier copies, where the tenant loader runs).
Not verified
This PR has:
🤖 Generated with Claude Code