mirror of
				https://github.com/open-webui/open-webui
				synced 2025-06-26 18:26:48 +00:00 
			
		
		
		
	Merge pull request #13852 from fizyr-forks/self-signed-cert
feat: Add option to disable certificate validation for LDAP certificates.
This commit is contained in:
		
						commit
						e358a66fb1
					
				@ -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")
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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,
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -585,6 +585,13 @@
 | 
			
		||||
													/>
 | 
			
		||||
												</div>
 | 
			
		||||
											</div>
 | 
			
		||||
											<div class="flex justify-between items-center text-xs">
 | 
			
		||||
												<div class=" font-medium">Validate certificate</div>
 | 
			
		||||
 | 
			
		||||
												<div class="mt-1">
 | 
			
		||||
													<Switch bind:state={LDAP_SERVER.validate_cert} />
 | 
			
		||||
												</div>
 | 
			
		||||
											</div>
 | 
			
		||||
											<div class="flex w-full gap-2">
 | 
			
		||||
												<div class="w-full">
 | 
			
		||||
													<div class=" self-center text-xs font-medium min-w-fit mb-1">
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user