[18.0][ADD] auth_api_key_provisioning: mint scoped API keys for other users#947
Draft
manana2520 wants to merge 1 commit into
Draft
[18.0][ADD] auth_api_key_provisioning: mint scoped API keys for other users#947manana2520 wants to merge 1 commit into
manana2520 wants to merge 1 commit into
Conversation
8a13bc4 to
f6e0dc5
Compare
Admin-gated, least-privilege module that mints short-lived, rpc-scoped API keys on behalf of another internal user, for delegated per-user identity (MCP servers, AI agents, backend services acting as the user with that user's own ACLs and correct create_uid). Security model: - caller gated on a dedicated provisioning group (not group_system) - targets restricted to an explicit mintable allowlist group - superuser / group_system / group_erp_manager always refused - portal/share and archived users refused - keys are rpc-scoped with a TTL clamped to a configurable maximum - privilege-drift protection: provisioned keys are auto-revoked when a target is promoted into an elevated group (user-side or group-side) or archived, with a daily cron backstop - every mint is recorded in an auditable provisioning log; revocation is by stored provenance, never by name matching
f6e0dc5 to
f2013c3
Compare
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.
New module:
auth_api_key_provisioningHardened, OCA-packaged follow-up to the proposal in #946 (closed without comment).
Rather than re-asking in an issue, here is the actual code for review.
A trusted, least-privilege provisioning/service account can mint a short-lived,
rpc-scoped API key on behalf of another internal user, over RPC. This enablesdelegated per-user identity: an integration (MCP server, AI agent, backend service)
acts as the end user — with that user's own record rules and correct
create_uid/write_uid— instead of as one shared service account.Stock Odoo has no supported way to mint an API key for another user over RPC
(
res.users.apikeys.generateis not an RPC method;_generateis private). This moduleadds two narrow, group-gated methods on
res.usersplus an auditable log.Public API
res.users.mint_apikey(name=None, ttl_days=None) -> str(called on the target recordset)res.users.revoke_provisioned_apikeys() -> intSecurity model (please scrutinise)
base.group_system.because custom modules add their own high-privilege groups a blocklist can't enumerate).
group_system,group_erp_manager;also portal/share and archived users.
authenticates with the user's current groups. So if a target with provisioned keys is
later promoted into an elevated group (user-side or group-side) or archived, its
provisioned keys are revoked immediately, with a daily cron as a backstop for paths that
bypass the ORM hooks.
rpc-scoped and expiring; TTL defaults to 30 days,clamped to a configurable max (90), with an absolute code ceiling.
revocation is by stored link, never by name matching.
Non-goals / residual risks (documented)
impersonate_login) — this is a programmaticcredential, no session.
use revoke or archive on suspected compromise.
keep that group minimal and monitor the log.
Tests
mint happy-path; default + clamped TTL; caller-group gate; refusal of non-mintable /
elevated / superuser / portal / archived targets; manual revoke; revoke gate; and the
privilege-drift cases (user-side promotion, group-side promotion, archive, cron backstop).
Open questions for maintainers
server-auth? (Re: [18.0] New module proposal: mint a scoped API key for another user (agent/MCP per-user identity) #946.)auth_api_keyfamily; happy to switch toAGPL-3 if you prefer.
auth_api_key_provisioning; open to your preference.Draft until the CLA is confirmed and runbot is green. CLA will be signed (entity-level)
before this is marked ready.