feat(auth-server): audit logging - #22086
Open
sfoster1 wants to merge 6 commits into
Open
Conversation
We can't do this with the normal fastapi dependencies because the work of the endpoint functions, including request and response handling, is delegated to oauthlib and I've never wanted anything more than to not inspect the raw results. Instead, we can poke a callback into the request validator and with a little source reading in oauthlib, - Anywhere we return False, that's a failed login, so log that - The last login check is the scope validity check, so if that returns true then we're going to log in, so log that Also, we might as well do this to log logins to the auth server logs, since that seems like a pretty helpful thing to have. We're logging "login expired" if a refresh token isn't found, but I don't want to log every refresh token login because it would be a million of them and it means somebody already provided the right credentials.
nothing uses this, my oath upon it
sfoster1
force-pushed
the
exec-2874-auth-server-audit-logging
branch
from
July 28, 2026 21:09
54b17e4 to
66cf0a2
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.
Overview
Add audit logging to the auth server.
We log the settings endpoints straightforwardly with little customization. User creation and editing needs custom request body handling to make sure we don't log passwords.
Oauth stuff takes a little more annoying insight. We could log in the endpoints, but then we'd have to look at the token responses that come from oauthlib, and by the time they get back to the endpoint the token responses are already serialized to form-data responses and we'd have to reparse them, which would be annoying. Instead, we can integrate logging into the oauth backend with a little callback that creates tasks to send the audit log messages.
The audit log messages are also a little annoying; they have to be done in a way that eventually bypasses user-notes requirements, since a user can set user-note minimum length requirements and we don't want to have to emit 50,000 letters "a" or whatever. For now, I'm just not sending them, since those requirements aren't correctly enforced. When we do enforce it, we'll either have to add a special thing to the messages you send on the unix domain socket to be logged that indicates these are system messages, or reserve the username
systemfor things like this.Test Plan and Hands on Testing
Changelog
Review requests
Risk assessment
low; the code here is in execution pretty simple.