[PR #20903] feat: Add Active Directory SID support for LDAP authentication #96856

Open
opened 2026-05-15 23:13:11 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/20903
Author: @MiXaiLL76
Created: 1/23/2026
Status: 🔄 Open

Base: dev ← Head: ldap-features


📝 Commits (10+)

📊 Changes

4 files changed (+139 additions, -12 deletions)

View changed files

📝 backend/open_webui/config.py (+4 -0)
📝 backend/open_webui/main.py (+2 -0)
📝 backend/open_webui/models/auths.py (+51 -11)
📝 backend/open_webui/routers/auths.py (+82 -1)

📄 Description

Changelog Entry

Description

This pull request adds support for using Active Directory Security Identifier (AD SID) as the user ID in LDAP authentication. This feature allows organizations to maintain consistent user identifiers across systems when using Active Directory, as the AD SID is a unique and immutable identifier for each user object in Active Directory.

When enabled, the LDAP authentication will extract the objectSid attribute from AD, convert it to string format (e.g., S-1-5-21-3396494274-2626632863-120886085-599475), and use it as the user's ID in Open WebUI instead of generating a random UUID. This provides better integration with AD-based environments and ensures user identity consistency.

Integration with External Systems:
This feature is particularly critical when ENABLE_FORWARD_USER_INFO_HEADERS is enabled. Open WebUI forwards user information headers (including X-OpenWebUI-User-Id) to external services such as:

  • TTS/STT providers (for personalization and rate limiting)
  • Web search engines
  • Document loaders
  • LLM backends (Ollama, OpenAI, etc.)

With this feature, external systems will receive the user's AD SID in the X-OpenWebUI-User-Id header instead of a random UUID. This enables external systems to:

  • Implement user-specific rate limiting based on AD identity
  • Track usage and costs per AD user across multiple systems
  • Maintain audit logs with consistent AD-based user identifiers
  • Integrate with existing enterprise identity management and billing systems
  • Correlate user activity across Open WebUI and other corporate applications

Added

  • New configuration parameter LDAP_USE_AD_SID to enable/disable AD SID usage for user IDs
  • Function convert_ad_sid_to_string() to convert binary AD SID to string representation
  • Support for objectSid attribute in LDAP search queries when AD SID usage is enabled
  • Logging for AD SID extraction and conversion process

Changed

  • Modified AuthsTable.insert_new_auth() to accept optional id parameter instead of always generating UUID
  • Updated LDAP authentication flow to extract and use AD SID when LDAP_USE_AD_SID is enabled
  • Extended LDAP search attributes to include objectSid when AD SID feature is enabled

Deprecated

  • None

Removed

  • None

Fixed

  • None

Security

  • None

Breaking Changes

  • None (feature is opt-in via configuration parameter, defaults to disabled)

Additional Information

Configuration:

  • The feature is controlled by the LDAP_USE_AD_SID environment variable (defaults to False)
  • Can be set via environment variable: LDAP_USE_AD_SID=true
  • Persisted in config as ldap.server.use_ad_sid

Technical Details:

  • If AD SID extraction fails or is not available, the system falls back to UUID generation with appropriate warning logs
  • The AD SID conversion follows the standard Microsoft format: S-Revision-IdentifierAuthority-SubAuthority1-SubAuthority2-...
  • Extracts the objectSid binary attribute from Active Directory
  • Converts binary SID using correct byte order: revision (1 byte), sub-authority count (1 byte), identifier authority (6 bytes, big-endian), sub-authorities (4 bytes each, little-endian)

Use Cases:

  • Organizations using ENABLE_FORWARD_USER_INFO_HEADERS=True for external service integration
  • Enterprise environments requiring consistent user identification across multiple systems
  • Cost tracking and billing per AD user
  • Audit and compliance requirements with AD-based user identity
  • Integration with existing identity management systems

Documentation Updates Required:

  • Environment variables documentation: add LDAP_USE_AD_SID parameter
  • LDAP authentication tutorial: explain when and why to use AD SID
  • External service integration guide: explain the relationship with ENABLE_FORWARD_USER_INFO_HEADERS

Contributor License Agreement

By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/open-webui/open-webui/pull/20903 **Author:** [@MiXaiLL76](https://github.com/MiXaiLL76) **Created:** 1/23/2026 **Status:** 🔄 Open **Base:** `dev` ← **Head:** `ldap-features` --- ### 📝 Commits (10+) - [`2c7df30`](https://github.com/open-webui/open-webui/commit/2c7df302419bbca1a14ff84e023cda9743d5bf5b) ldap.server.use_ad_sid - [`8a53f64`](https://github.com/open-webui/open-webui/commit/8a53f64ea3bcd98e05d1f2b48c674396556446ed) fix uuid4 - [`9c078fa`](https://github.com/open-webui/open-webui/commit/9c078fa5daf8d4a951a18fc8b465698b59668b35) fix user_id & log level - [`11cebdf`](https://github.com/open-webui/open-webui/commit/11cebdf90409bee8725f31dd5715aa4dcaa935e8) update code with format - [`f1199eb`](https://github.com/open-webui/open-webui/commit/f1199eb6ca90a26f299efe139bc49f7ff1be62a8) back to format - [`8da8f62`](https://github.com/open-webui/open-webui/commit/8da8f62036ddd5122586f07f99b78fefcfebb293) add sid validate - [`8fa5dc9`](https://github.com/open-webui/open-webui/commit/8fa5dc9c63632ff3de03c93e73c9cb25e94d7c72) fix 4. Missing Newline at EOF (Nit) - [`53316f5`](https://github.com/open-webui/open-webui/commit/53316f5496e890aaf7ecb5a7f0b31e5103518854) fix LdapServerConfig - [`4e37023`](https://github.com/open-webui/open-webui/commit/4e37023ef1f500e74f2603f43dad4a7e80d8a50d) Merge branch 'dev' into ldap-features - [`9677a27`](https://github.com/open-webui/open-webui/commit/9677a27e382737e38a1caa3117fcb7a95ce61551) update async feature with 0.9.2 ### 📊 Changes **4 files changed** (+139 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/config.py` (+4 -0) 📝 `backend/open_webui/main.py` (+2 -0) 📝 `backend/open_webui/models/auths.py` (+51 -11) 📝 `backend/open_webui/routers/auths.py` (+82 -1) </details> ### 📄 Description # Changelog Entry ### Description This pull request adds support for using Active Directory Security Identifier (AD SID) as the user ID in LDAP authentication. This feature allows organizations to maintain consistent user identifiers across systems when using Active Directory, as the AD SID is a unique and immutable identifier for each user object in Active Directory. When enabled, the LDAP authentication will extract the `objectSid` attribute from AD, convert it to string format (e.g., `S-1-5-21-3396494274-2626632863-120886085-599475`), and use it as the user's ID in Open WebUI instead of generating a random UUID. This provides better integration with AD-based environments and ensures user identity consistency. **Integration with External Systems:** This feature is particularly critical when `ENABLE_FORWARD_USER_INFO_HEADERS` is enabled. Open WebUI forwards user information headers (including `X-OpenWebUI-User-Id`) to external services such as: - TTS/STT providers (for personalization and rate limiting) - Web search engines - Document loaders - LLM backends (Ollama, OpenAI, etc.) With this feature, external systems will receive the user's AD SID in the `X-OpenWebUI-User-Id` header instead of a random UUID. This enables external systems to: - Implement user-specific rate limiting based on AD identity - Track usage and costs per AD user across multiple systems - Maintain audit logs with consistent AD-based user identifiers - Integrate with existing enterprise identity management and billing systems - Correlate user activity across Open WebUI and other corporate applications ### Added - New configuration parameter `LDAP_USE_AD_SID` to enable/disable AD SID usage for user IDs - Function `convert_ad_sid_to_string()` to convert binary AD SID to string representation - Support for `objectSid` attribute in LDAP search queries when AD SID usage is enabled - Logging for AD SID extraction and conversion process ### Changed - Modified `AuthsTable.insert_new_auth()` to accept optional `id` parameter instead of always generating UUID - Updated LDAP authentication flow to extract and use AD SID when `LDAP_USE_AD_SID` is enabled - Extended LDAP search attributes to include `objectSid` when AD SID feature is enabled ### Deprecated - None ### Removed - None ### Fixed - None ### Security - None ### Breaking Changes - None (feature is opt-in via configuration parameter, defaults to disabled) --- ### Additional Information **Configuration:** - The feature is controlled by the `LDAP_USE_AD_SID` environment variable (defaults to `False`) - Can be set via environment variable: `LDAP_USE_AD_SID=true` - Persisted in config as `ldap.server.use_ad_sid` **Technical Details:** - If AD SID extraction fails or is not available, the system falls back to UUID generation with appropriate warning logs - The AD SID conversion follows the standard Microsoft format: `S-Revision-IdentifierAuthority-SubAuthority1-SubAuthority2-...` - Extracts the `objectSid` binary attribute from Active Directory - Converts binary SID using correct byte order: revision (1 byte), sub-authority count (1 byte), identifier authority (6 bytes, big-endian), sub-authorities (4 bytes each, little-endian) **Use Cases:** - Organizations using `ENABLE_FORWARD_USER_INFO_HEADERS=True` for external service integration - Enterprise environments requiring consistent user identification across multiple systems - Cost tracking and billing per AD user - Audit and compliance requirements with AD-based user identity - Integration with existing identity management systems **Documentation Updates Required:** - Environment variables documentation: add `LDAP_USE_AD_SID` parameter - LDAP authentication tutorial: explain when and why to use AD SID - External service integration guide: explain the relationship with `ENABLE_FORWARD_USER_INFO_HEADERS` ### Contributor License Agreement By submitting this pull request, I confirm that I have read and fully agree to the [Contributor License Agreement (CLA)](https://github.com/open-webui/open-webui/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT), and I am providing my contributions under its terms. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-05-15 23:13:11 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#96856