Skip to content

feat(Audit logs): Emit authentication audit logs - #8931

Merged
emyller merged 46 commits into
mainfrom
feat/auth-audit-logs
Nov 17, 2026
Merged

emyller merged 46 commits into
mainfrom
feat/auth-audit-logs

Conversation

@emyller

@emyller emyller commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for submitting a PR! Please check the boxes below:

  • I have read the Contributing Guide.
  • I have added information to docs/ if required so people know about the feature.
  • I have filled in the "Changes" section below.
  • I have filled in the "How did you test this code" section below.

Changes

Closes #7569

Introduces audit logging for authentication events.

We expand further from the original scope, and also add audit logs for:

  • Getting locked out
  • Attempting to authenticate while locked out
  • Login via OAuth — e.g. MCP, CLI
  • Logout via OAuth — i.e. revoke a token

Review effort: 4/5

How did you test this code?

Functional tests.

@emyller emyller self-assigned this Nov 10, 2026
@vercel

vercel Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
docs Ready Ready Preview Nov 17, 2026 5:16pm UTC
2 Skipped Deployments
Project Deployment Actions Updated
flagsmith-frontend-preview Ignored Ignored Preview Nov 17, 2026 5:16pm UTC
flagsmith-frontend-staging Ignored Ignored Preview Nov 17, 2026 5:16pm UTC

Request Review

@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Explain Change →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • Resume reviews
  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

The change adds authentication audit events for password and 2FA outcomes, SSO, OAuth application login and logout, account lockouts, user logout, password changes, and 2FA setting changes. Receivers create audit records for each organisation associated with a user. Authentication workflows emit the corresponding signals. OAuth token revocation uses a custom view that emits a signal after confirming that a refresh token was revoked. Integration tests and audit-log documentation cover the events.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Merge Risk: Moderate · previous review 84174

Authentication audit logging is mostly in place. Several gaps remain: lockout and incorrect-password events can be missed for LDAP username logins, access-token revocation records no logout, and a null failure count in the lockout receiver can raise an error. The declared OAuth toolkit minimum also admits a version that would break token revocation. These should be addressed or explicitly accepted before merging.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 5ffc355e-41e3-48c9-97c0-6fc0ceae3c92
Commits

Reviewing files that changed from the base of the PR and between c9ec50a and 84174c5.

Files selected for processing: 2

  • docs/docs/deployment-self-hosting/observability/_events-catalogue.md
  • openapi.yaml

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

@emyller
emyller changed the base branch from main to feat/org-level-audit-logs-pt1 November 10, 2026 20:44
@github-actions github-actions Bot added api Issue related to the REST API feature New feature or request labels Nov 10, 2026
@github-actions github-actions Bot added docs Documentation updates feature New feature or request and removed feature New feature or request docs Documentation updates labels Nov 10, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 2 files (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Requires human review: Auto-approval blocked by 2 unresolved issues from previous reviews.

Turn on auto-fix | Re-trigger cubic

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 27f6fdf3-9ad8-409b-8465-946ae7911d4e
Commits

Reviewing files that changed from the base of the PR and between 3a87c78 and c9ec50a.

Files selected for processing: 20

  • api/app/urls.py
  • api/audit/apps.py
  • api/audit/constants.py
  • api/audit/signals/__init__.py
  • api/audit/signals/authentication.py
  • api/audit/types.py
  • api/custom_auth/mfa/trench/command/authenticate_second_factor.py
  • api/custom_auth/mfa/trench/views/base.py
  • api/custom_auth/oauth/serializers.py
  • api/custom_auth/serializers.py
  • api/custom_auth/signals.py
  • api/custom_auth/views.py
  • api/oauth2_metadata/signals.py
  • api/oauth2_metadata/views.py
  • api/tests/integration/audit/events/test_authentication_logs.py
  • api/tests/integration/audit/test_project_audit_logs.py
  • api/tests/unit/audit/test_unit_audit_signals.py
  • api/tests/unit/custom_auth/oauth/test_unit_oauth_serializers.py
  • api/users/auth_type.py
  • docs/docs/administration-and-security/governance-and-compliance/audit-logs.md
Files with no reviewable changes: 2

  • api/audit/signals/init.py
  • api/tests/integration/audit/test_project_audit_logs.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

Comment thread api/audit/signals/authentication.py Resolved
Comment thread api/audit/signals/authentication.py Resolved
Comment thread api/custom_auth/serializers.py Resolved
Comment thread api/oauth2_metadata/views.py Resolved
Comment thread api/oauth2_metadata/views.py Resolved
Comment thread api/oauth2_metadata/views.py Resolved

@khvn26 khvn26 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ready to approve once CR's threads are resolved.

@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request docs Documentation updates labels Nov 17, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 4 files (changes from recent commits).

Requires human review: Auto-approval skipped because cubic reviewed only this push, not the earlier force-push. Comment @cubic review to review the whole pull request.

Turn on auto-fix | Re-trigger cubic

@emyller
emyller force-pushed the feat/auth-audit-logs branch from dd26a69 to cf2c835 Compare November 17, 2026 15:12
@github-actions github-actions Bot added docs Documentation updates feature New feature or request and removed feature New feature or request docs Documentation updates labels Nov 17, 2026
@emyller
emyller marked this pull request as draft November 17, 2026 15:32
@github-actions github-actions Bot added docs Documentation updates feature New feature or request and removed feature New feature or request docs Documentation updates labels Nov 17, 2026
khvn26
khvn26 previously approved these changes Nov 17, 2026

@khvn26 khvn26 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 25 files

Reply with feedback, questions, or to request a fix.

Turn on auto-fix | Re-trigger cubic

Comment thread api/oauth2_metadata/views.py Resolved

This branch was successfully deployed

3 active (2 outdated) deployments
Preview – docs — 17cccbc7 Deployed Nov 17, 2026 by vercel[bot]
Preview – flagsmith-frontend-staging — 090696c5 Deployed Nov 11, 2026 by vercel[bot]
Preview – flagsmith-frontend-preview — 090696c5 Deployed Nov 11, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Issue related to the REST API feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Organisation-Level Audit Log Records - User Authentication Events

4 participants