Skip to content

[18.0][IMP] auth_api_key: store keys hashed - #1087

Draft
simahawk wants to merge 2 commits into
OCA:18.0from
camptocamp:18-imp-auth_api_key-hashed-keys
Draft

simahawk wants to merge 2 commits into
OCA:18.0from
camptocamp:18-imp-auth_api_key-hashed-keys

Conversation

@simahawk

@simahawk simahawk commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Depends on/includes:

Store only the SHA-256 of an API key instead of the key itself, so that reading the table, a backup or a restored dump does not give usable keys. Keys are long random values: a fast hash is enough, and the lookup becomes an indexed search instead of a loop over all the keys.

  • Enabled by default, optional: "Store API keys hashed" in the general settings (debug mode). Enabling it also hashes the keys already stored.
  • Keys stored in plain text keep working, so a database can be switched progressively.
  • The upgrade disables it on databases that already have keys, because code reading auth.api.key.key would break. Administrators opt in.
  • auth_api_key_server_env never hashes: the key comes from the environment.
  • The neutralization clears the hash too.

Note: with hashing enabled, key reads back as a placeholder after creation, so tests that create a key and read it back must use the value they passed.

…rrors

* Clear the key cache on unlink and when a key is (un)archived, so a
  deleted or archived key stops working right away instead of when the
  cache happens to be cleared.
* The error for an unknown key no longer contains the submitted key
  (it ended up in logs and error pages) and the message is translatable.
* An unknown key now answers 401, like a missing one, instead of a user
  error, and the failure log reports the caller address.
Store only the SHA-256 of a key instead of the key itself, so that
reading the table, a backup or a restored dump does not give usable
keys. Keys are long random values: a fast hash is enough and the lookup
becomes an indexed search instead of a loop over all the keys.

* Enabled by default, optional ("Store API keys hashed" in the settings).
  Enabling it also hashes the keys already stored.
* Keys stored in plain text keep working, so a database can be switched
  progressively.
* The upgrade disables it on databases already having keys, as code
  reading the keys would break.
* auth_api_key_server_env never hashes: the key comes from the
  environment.
* The neutralization clears the hash too.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:auth_api_key_server_env Module auth_api_key_server_env mod:auth_api_key Module auth_api_key series:18.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants