Skip to content

[18.0][IMP] auth_api_key: last use date - #1088

Draft
simahawk wants to merge 3 commits into
OCA:18.0from
camptocamp:18-imp-auth_api_key-last-used
Draft

simahawk wants to merge 3 commits into
OCA:18.0from
camptocamp:18-imp-auth_api_key-last-used

Conversation

@simahawk

@simahawk simahawk commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Depends on/includes:

…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.
* Last use date of the key, shown in the keys list and updated at most
  once an hour with a plain SQL update to avoid a write on each request.
* Search view with filters for the keys never used or not used for
  10, 30 or 60 days, to find the keys that are not used anymore, and for
  the archived keys.
* `_retrieve_uid_from_api_key` is no longer cached: it would bypass the
  checks other modules add to `_retrieve_api_key` that depend on time. The
  id lookup below it still is.
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