Repository navigation
Description
Context
The authserver is the most security-sensitive component in ToolHive (token issuance, client registration, upstream IDP interaction) yet has zero audit logging. The rest of the codebase has a mature NIST SP 800-53 compliant audit system in pkg/audit/ with structured event types, subjects, targets, and outcomes.
Scope
Define auth event types
New EventType constants in pkg/audit/ (new file authserver_events.go, following mcp_events.go pattern). Failures are NOT separate event types — they are captured via the existing Outcome field (success, failure, error, denied) on each event.
| Constant | Value | When emitted |
|---|---|---|
EventTypeOAuthAuthorizeRequest |
oauth_authorize_request |
Client initiates authorization. Outcome: success (redirect issued) / denied (invalid client/redirect) |
EventTypeOAuthAuthCodeIssued |
oauth_auth_code_issued |
Auth code generated after successful upstream callback |
EventTypeOAuthTokenIssued |
oauth_token_issued |
Access/refresh token issued via authorization_code grant |
EventTypeOAuthTokenRefreshed |
oauth_token_refreshed |
Token refreshed via refresh_token grant (distinct security properties from initial issuance) |
EventTypeOAuthSessionRevoked |
oauth_session_revoked |
Session forcibly revoked (e.g., upstream refresh permanently failed with invalid_grant) |
EventTypeOAuthClientRegistered |
oauth_client_registered |
DCR: new client registered (RFC 7591) |
EventTypeOAuthUpstreamAuthComplete |
oauth_upstream_auth_complete |
Upstream IDP callback received confirming user authentication |
EventTypeOAuthUpstreamTokenRefreshed |
oauth_upstream_token_refreshed |
ToolHive transparently refreshed an upstream IDP token on behalf of a session |
EventTypeOAuthUserCreated |
oauth_user_created |
New internal user provisioned on first login |
Plus supporting subject keys (oauth_client_id, upstream_issuer, upstream_subject), target keys (session_id, scope, resource, grant_type, revocation_reason), and component constant (toolhive-authserver).
NIST SP 800-53 AU-2 coverage
| AU-2 Category | Events covering it |
|---|---|
| Logon/logoff events | oauth_authorize_request, oauth_upstream_auth_complete |
| Privileged access | oauth_client_registered |
| Non-privileged access | oauth_token_issued, oauth_token_refreshed |
| Account management | oauth_user_created, oauth_session_revoked |
| Third-party interactions | oauth_upstream_auth_complete, oauth_upstream_token_refreshed |
Future events (oauth_token_introspected, oauth_mtls_auth_attempted, oauth_client_updated/deleted) should be added when their corresponding features land.
Create AuthServerAuditor and wire into handlers
Follow the WorkflowAuditor pattern (pkg/audit/workflow_auditor.go) — a direct auditor that handlers call, rather than generic HTTP middleware. This is preferred because auth operations have rich semantic context (client_id, grant_type, upstream_provider) that HTTP middleware can't capture, and different endpoints need very different audit data.
Wire into each handler:
- AuthorizeHandler:
oauth_authorize_requestwith subjects={client_id}, target={redirect_uri, scope, resource} - CallbackHandler success:
oauth_upstream_auth_complete+oauth_auth_code_issued+ optionallyoauth_user_created - CallbackHandler failure:
oauth_upstream_auth_completewith outcome=failure/error - TokenHandler authorization_code:
oauth_token_issuedwith subjects={client_id, user_id, session_id}, target={grant_type, scope} - TokenHandler refresh_token:
oauth_token_refreshedwith subjects={client_id, user_id}, target={grant_type} - TokenHandler failure: relevant event type with outcome=failure
- RegisterClientHandler:
oauth_client_registeredwith subjects={client_id, client_name} - Upstream token refresh (when implemented):
oauth_upstream_token_refreshedwith target={upstream_issuer, session_id} - Session revocation (when implemented):
oauth_session_revokedwith target={session_id, revocation_reason}
Acceptance criteria
- Auth event type constants defined in
pkg/audit/authserver_events.go -
AuthServerAuditorcreated followingWorkflowAuditorpattern - Auditor injected into
Handlervia constructor - Audit events emitted for all handler success and failure paths
- Sensitive data (tokens, PKCE verifiers, authorization codes) NEVER included in audit events
- Source information (client IP, user agent) included in events
- Configuration follows
pkg/audit.Configpatterns (enable/disable, event type filtering) - Unit tests verify correct event types, subjects, and outcomes per handler path
Dependencies
- Depends on Add HTTP middleware and logging cleanup to authserver #3918 (HTTP middleware — request IDs needed for audit event correlation)
Delegated access events (add with each feature)
Each feature in #6886 "Authorization server: grants and ID-JAG issuance for delegated agents" and #6887 "Delegated access: subject mapping and user approval" emits its events in the same change:
oauth_token_exchanged(RFC 8693): subjects = client, user, actor; target = grant type, requested token type, audienceoauth_session_refresh_token_issued: row ID, kind (session or schedule), session keyoauth_id_jag_issued:jti, audience, clientoauth_id_jag_redeemed:jti, source issuer, source subject, local user, approval record ID; outcome denied with a reason (no mapping, no approval, reuse refused, actor not allowed)oauth_delegated_approval_created/oauth_delegated_approval_revoked: source = user or administratoroauth_token_revoked: single token, or user-wide with the revocation time
Record identifiers only, never token values or assertion contents. The binding key is an identifier, not a secret. Operation and attempt IDs a client passes are recorded as client-reported values.
Activity
jhrozek commentedon Nov 14, 2026
Adding the exchange-grant events from #6886 here so they land with the rest of the authserver audit work. #7130 (ID-JAG issuance) defers its audit line to this issue on purpose.
Events, all emitted by the token endpoint's refresh-token exchange handler:
exchange_grant.id_jag_issuedexchange_grant.createdexchange_grant.derivedRefusals use the same event types with outcome
failureand the stable reason (grant_invalid,revoked,parent_revoked,not_issuable, ...), as the issue already describes for the OAuth events.exchange_grant.id_jag_issuedis the name #6898 asks for, so I'd keep it even though it doesn't follow theoauth_*scheme above.sub_idandupstream_subjectstay out of these events, like the WARN logs, because they carry the user's upstream identity.jhrozek commentedon Nov 29, 2026
Following up on the exchange-grant events in the comment above. To join the authorization server's records with a delegated client's records, and to check one against the other, these fields and events are still missing:
exchange_grant.createdandexchange_grant.derivedrecord the grant's own ID.derivedalready names the parent. Without the grant's own ID, a later event cannot say which grant it used.exchange_grant.createdrecords thejtiof the access token that was exchanged. The client records the samejtiwhen it opens its session, so the two records can be matched.oauth_token_issuedandoauth_token_refreshedrecord the issued access token'sjti. This lets a check confirm that a token later exchanged for a grant was issued by this server.exchange_grant.id_jag_issuedrecords the ID of the grant it was issued from (not onlyhas_parent) and the call entry it signed: theoperation_idfor a tool call, or the method for a listing. The actor is Audit the actor validator's input identity at ID-JAG issuance #7187.oauth_id_jag_redeemedalso records thejtiof the access token it issued. The client records thatjtiwith its decision, and the vMCP will record it with the call (vMCP: record the call-bound token's operation ID and jti, and the IDs a client reports #6979). It is the only exact link from the ID-JAG to the call.upstream_revoked,owner_action_required).parent_revoked), and a user-wide revocation (Per-user revocation time for grants issued by token exchange #6972), should name every grant they end, or name the parent so the children can be found.oauth_upstream_auth_completerecords the upstream authentication time (auth_time) when the IdP sends it.Two lines in the "Delegated access events" section are out of date:
oauth_session_refresh_token_issued(row ID, kind, session key) is replaced byexchange_grant.createdandexchange_grant.derived: the server knows grants, not the client's sessions.These delegated-agent events belong to "Authorization server: revocation and audit for delegated agents" (#6886), but this issue has another parent. I filed #7375 under #6886 for them. It depends on this issue, the same way #7187 does, so this issue keeps its current scope.