diff --git a/backend/open_webui/config.py b/backend/open_webui/config.py index 2f0d99261..32307dec2 100644 --- a/backend/open_webui/config.py +++ b/backend/open_webui/config.py @@ -2876,6 +2876,12 @@ LDAP_CA_CERT_FILE = PersistentConfig( os.environ.get("LDAP_CA_CERT_FILE", ""), ) +LDAP_VALIDATE_CERT = PersistentConfig( + "LDAP_VALIDATE_CERT", + "ldap.server.validate_cert", + os.environ.get("LDAP_USE_TLS", "True").lower() == "true", +) + LDAP_CIPHERS = PersistentConfig( "LDAP_CIPHERS", "ldap.server.ciphers", os.environ.get("LDAP_CIPHERS", "ALL") ) diff --git a/backend/open_webui/main.py b/backend/open_webui/main.py index 46f72a111..f148040b0 100644 --- a/backend/open_webui/main.py +++ b/backend/open_webui/main.py @@ -323,6 +323,7 @@ from open_webui.config import ( LDAP_APP_PASSWORD, LDAP_USE_TLS, LDAP_CA_CERT_FILE, + LDAP_VALIDATE_CERT, LDAP_CIPHERS, # Misc ENV, @@ -617,6 +618,7 @@ app.state.config.LDAP_SEARCH_BASE = LDAP_SEARCH_BASE app.state.config.LDAP_SEARCH_FILTERS = LDAP_SEARCH_FILTERS app.state.config.LDAP_USE_TLS = LDAP_USE_TLS app.state.config.LDAP_CA_CERT_FILE = LDAP_CA_CERT_FILE +app.state.config.LDAP_VALIDATE_CERT = LDAP_VALIDATE_CERT app.state.config.LDAP_CIPHERS = LDAP_CIPHERS diff --git a/backend/open_webui/routers/auths.py b/backend/open_webui/routers/auths.py index 420ae0c19..34a646427 100644 --- a/backend/open_webui/routers/auths.py +++ b/backend/open_webui/routers/auths.py @@ -51,7 +51,7 @@ from open_webui.utils.access_control import get_permissions from typing import Optional, List -from ssl import CERT_REQUIRED, PROTOCOL_TLS +from ssl import CERT_NONE, CERT_REQUIRED, PROTOCOL_TLS if ENABLE_LDAP.value: from ldap3 import Server, Connection, NONE, Tls @@ -186,6 +186,11 @@ async def ldap_auth(request: Request, response: Response, form_data: LdapForm): LDAP_APP_PASSWORD = request.app.state.config.LDAP_APP_PASSWORD LDAP_USE_TLS = request.app.state.config.LDAP_USE_TLS LDAP_CA_CERT_FILE = request.app.state.config.LDAP_CA_CERT_FILE + LDAP_VALIDATE_CERT = ( + CERT_REQUIRED + if request.app.state.config.LDAP_VALIDATE_CERT + else CERT_NONE + ) LDAP_CIPHERS = ( request.app.state.config.LDAP_CIPHERS if request.app.state.config.LDAP_CIPHERS @@ -197,7 +202,7 @@ async def ldap_auth(request: Request, response: Response, form_data: LdapForm): try: tls = Tls( - validate=CERT_REQUIRED, + validate=LDAP_VALIDATE_CERT, version=PROTOCOL_TLS, ca_certs_file=LDAP_CA_CERT_FILE, ciphers=LDAP_CIPHERS, @@ -792,6 +797,7 @@ class LdapServerConfig(BaseModel): search_filters: str = "" use_tls: bool = True certificate_path: Optional[str] = None + validate_cert: bool = True ciphers: Optional[str] = "ALL" @@ -809,6 +815,7 @@ async def get_ldap_server(request: Request, user=Depends(get_admin_user)): "search_filters": request.app.state.config.LDAP_SEARCH_FILTERS, "use_tls": request.app.state.config.LDAP_USE_TLS, "certificate_path": request.app.state.config.LDAP_CA_CERT_FILE, + "validate_cert": request.app.state.config.LDAP_VALIDATE_CERT, "ciphers": request.app.state.config.LDAP_CIPHERS, } @@ -844,6 +851,7 @@ async def update_ldap_server( request.app.state.config.LDAP_SEARCH_FILTERS = form_data.search_filters request.app.state.config.LDAP_USE_TLS = form_data.use_tls request.app.state.config.LDAP_CA_CERT_FILE = form_data.certificate_path + request.app.state.config.LDAP_VALIDATE_CERT = form_data.validate_cert request.app.state.config.LDAP_CIPHERS = form_data.ciphers return { @@ -858,6 +866,7 @@ async def update_ldap_server( "search_filters": request.app.state.config.LDAP_SEARCH_FILTERS, "use_tls": request.app.state.config.LDAP_USE_TLS, "certificate_path": request.app.state.config.LDAP_CA_CERT_FILE, + "validate_cert": request.app.state.config.LDAP_VALIDATE_CERT, "ciphers": request.app.state.config.LDAP_CIPHERS, } diff --git a/src/lib/components/admin/Settings/General.svelte b/src/lib/components/admin/Settings/General.svelte index f03be5f3b..850303b90 100644 --- a/src/lib/components/admin/Settings/General.svelte +++ b/src/lib/components/admin/Settings/General.svelte @@ -585,6 +585,13 @@ /> +
+
Validate certificate
+ +
+ +
+