mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-06 02:48:13 -05:00
[PR #10436] [MERGED] feat: add audit logging feature #22535
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/10436
Author: @victorstevansuse
Created: 2/20/2025
Status: ✅ Merged
Merged: 2/27/2025
Merged by: @tjbck
Base:
audit-log-dev← Head:feat/audits📝 Commits (1)
39c6ecbfeat: add audit logger middleware and custom logger using loguru📊 Changes
5 files changed (+434 additions, -0 deletions)
View changed files
📝
backend/open_webui/env.py(+22 -0)📝
backend/open_webui/main.py(+20 -0)➕
backend/open_webui/utils/audit.py(+249 -0)➕
backend/open_webui/utils/logger.py(+140 -0)📝
backend/requirements.txt(+3 -0)📄 Description
Pull Request Checklist
devbranch.Changelog Entry
Description
This feature introduces audit trails to enhance security auditing, debugging, and traceability within the OI API. It adds an ASGI middleware that intercepts HTTP metadata—including user details and, optionally, request/response payloads—and logs this information in a structured JSON format. The feature is configurable via several audit levels:
METADATA: Logs only metadata related to the request (e.g., user, timestamp, resource, HTTP verb).REQUEST: Logs metadata and the request body.REQUEST_RESPONSE: Logs metadata, the request body, and the response body.Important: Enabling audit logging may impact performance and increase memory consumption.
This update also introduces new environment variables to control audit logging behavior:
AUDIT_LOGS_FILE_PATH: Specifies the file path where audit logs will be stored (defaults to/data/audit.log).AUDIT_LOG_FILE_ROTATION_SIZE: Defines the maximum size of a log file before it is rotated.AUDIT_LOG_LEVEL: Sets the audit level. Acceptable values areMETADATA,REQUEST,REQUEST_RESPONSE, orNONE(default isNONE).MAX_BODY_LOG_SIZE: Specifies the maximum size of a request or response body to capture, preventing excessive memory usage.AUDIT_EXCLUDED_PATHS: A comma-separated list of paths to exclude from audit logging (default excluded paths:/chats,/chat,/folders).Added
stdout_formatfor enhanced general log output.AUDIT_LOG_LEVEL,AUDIT_LOGS_FILE_PATH, andAUDIT_LOG_FILE_ROTATION_SIZEto dynamically control logging behavior.logurulibrary for improved logging features.asgireffor rigorous ASGI type hints (see https://www.starlette.io/middleware/#type-annotations)Changed
Deprecated
Removed
Fixed
Security
Breaking Changes
Additional Information
As mentioned, this could impact the API performance negatively depending on the configuration.
Previous implementations streaming issues should be fixed.
Previous related PR
Screenshots or Videos
https://github.com/user-attachments/assets/ed4983f2-293f-49aa-9b38-54484f959cde
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.