A free open source IT asset/license management system
Fixed #19518 - added support for SASL LDAP
snipe6a5557f54343
diff --git a/app/Console/Commands/LdapTroubleshooter.php b/app/Console/Commands/LdapTroubleshooter.phpindex e7b5583eea..db66945395 100644--- a/app/Console/Commands/LdapTroubleshooter.php+++ b/app/Console/Commands/LdapTroubleshooter.php@@ -165,18 +165,27 @@ class LdapTroubleshooter extends Command}$output[] = 'ldapsearch';$output[] = '-H '.$settings->ldap_server;- $output[] = '-x';$output[] = '-b '.escapeshellarg($settings->ldap_basedn);- $output[] = '-D '.escapeshellarg($settings->ldap_uname);- try {- $w = Crypt::decrypt($settings->ldap_pword);- } catch (Exception $e) {- $this->warn('Could not decrypt password. This usually means an LDAP password was not set or the APP_KEY was changed since the LDAP pasword was last saved. Aborting.');- exit(0);+ if ($settings->ldap_use_sasl_external_bind) {+ // SASL EXTERNAL identifies the client TLS+ // cert loaded above (LDAPTLS_CERT / LDAPTLS_KEY) instead+ // of a bind DN + password. See the ldapsearch man page's -Y flag.+ $output[] = '-Y EXTERNAL';+ } else {+ $output[] = '-x';+ $output[] = '-D '.escapeshellarg($settings->ldap_uname);++ try {+ $w = Crypt::decrypt($settings->ldap_pword);+ } catch (Exception $e) {+ $this->warn('Could not decrypt password. This usually means an LDAP password was not set or the APP_KEY was changed since the LDAP pasword was last saved. Aborting.');+ exit(0);+ }++ $output[] = '-w '.escapeshellarg($w);}- $output[] = '-w '.escapeshellarg($w);$output[] = escapeshellarg(parenthesized_filter($settings->ldap_filter));if ($settings->ldap_tls) {$this->line('# adding STARTTLS option');@@ -386,6 +395,14 @@ class LdapTroubleshooter extends Command$this->line('STAGE 4: Test Administrative Bind for LDAP Sync');foreach ($ldap_urls as $ldap_url) {+ if ($settings->ldap_use_sasl_external_bind) {+ // SASL EXTERNAL uses the client TLS cert already loaded+ // in connect_to_ldap() as the auth identity. No username+ // or password gets sent. See GH #19518.+ $this->test_sasl_external_bind($ldap_url[0], $ldap_url[1], $ldap_url[2]);++ continue;+ }try {$w = Crypt::decrypt($settings->ldap_pword);} catch (Exception $e) {@@ -407,14 +424,24 @@ class LdapTroubleshooter extends Command$this->debugout('LDAP constants are: '.print_r($ldap_constants, true));foreach ($ldap_urls as $ldap_url) {- try {- $w = Crypt::decrypt($settings->ldap_pword);- } catch (Exception $e) {- $this->warn('Could not decrypt password. This usually means an LDAP password was not set or the APP_KEY was changed since the LDAP pasword was last saved. Aborting.');- exit(0);+ if ($settings->ldap_use_sasl_external_bind) {+ // Password decrypt + username don't apply under SASL+ // EXTERNAL - both are null'd in the bind call. The+ // informational read after the bind uses the same $settings+ // path either way, so the branch is only around the bind.+ $w = '';+ $uname = null;+ } else {+ try {+ $w = Crypt::decrypt($settings->ldap_pword);+ } catch (Exception $e) {+ $this->warn('Could not decrypt password. This usually means an LDAP password was not set or the APP_KEY was changed since the LDAP pasword was last saved. Aborting.');+ exit(0);+ }+ $uname = $settings->ldap_uname;}- if ($this->test_informational_bind($ldap_url[0], $ldap_url[1], $ldap_url[2], $settings->ldap_uname, $w, $settings)) {+ if ($this->test_informational_bind($ldap_url[0], $ldap_url[1], $ldap_url[2], $uname, $w, $settings)) {$this->info('Success getting informational bind!');} else {$this->error('Unable to get information from bind.');@@ -526,18 +553,51 @@ class LdapTroubleshooter extends Command});}+ public function test_sasl_external_bind($ldap_url, $check_cert, $start_tls)+ {+ return $this->timed_boolean_execute(function () use ($ldap_url, $check_cert, $start_tls) {+ try {+ $lconn = $this->connect_to_ldap($ldap_url, $check_cert, $start_tls);+ $bind_results = ldap_sasl_bind($lconn, null, null, 'EXTERNAL');+ ldap_close($lconn);+ if (! $bind_results) {+ $this->error("WARNING: Failed to bind to $ldap_url via SASL EXTERNAL");++ return false;+ }+ $this->info("SUCCESS - Able to bind to $ldap_url via SASL EXTERNAL");++ return (bool) $lconn;+ } catch (Exception $e) {+ $this->error('WARNING: Exception caught during SASL EXTERNAL bind - '.$e->getMessage());++ return false;+ }+ });+ }+public function test_informational_bind($ldap_url, $check_cert, $start_tls, $username, $password, $settings){return $this->timed_boolean_execute(function () use ($ldap_url, $check_cert, $start_tls, $username, $password, $settings) {try { // TODO - copypasta'ed from test_authed_bind$conn = $this->connect_to_ldap($ldap_url, $check_cert, $start_tls);- $bind_results = ldap_bind($conn, $username, $password);+ // Null $username signals the SASL EXTERNAL branch. The+ // Stage 5 caller sets it that way when+ // ldap_use_sasl_external_bind is on. Post-bind logic is+ // identical either way.+ if ($username === null) {+ $bind_results = ldap_sasl_bind($conn, null, null, 'EXTERNAL');+ $identityLabel = 'the SASL EXTERNAL client certificate';+ } else {+ $bind_results = ldap_bind($conn, $username, $password);+ $identityLabel = $username;+ }if (! $bind_results) {- $this->error("WARNING: Failed to bind to $ldap_url as $username");+ $this->error("WARNING: Failed to bind to $ldap_url as $identityLabel");return false;}- $this->info("SUCCESS - Able to bind to $ldap_url as $username");+ $this->info("SUCCESS - Able to bind to $ldap_url as $identityLabel");$cleaned_results = [];try {// This _may_ only work for Active Directory?diff --git a/app/Livewire/LdapSettings.php b/app/Livewire/LdapSettings.phpindex 622647d4ed..1b79884244 100644--- a/app/Livewire/LdapSettings.php+++ b/app/Livewire/LdapSettings.php@@ -113,6 +113,14 @@ class LdapSettings extends Componentpublic string $ldap_client_tls_cert = '';+ // SASL EXTERNAL bind uses the client TLS cert (loaded via+ // LDAP_OPT_X_TLS_CERTFILE / _KEYFILE in Ldap::connectToLdap()) as the+ // authentication identity instead of a bind DN + password. Depends on+ // ldap_client_tls_cert + ldap_client_tls_key being populated. Enables+ // directories like Google Workspace LDAP that authenticate via mTLS+ // certificate. See GH #19518.+ public bool $ldap_use_sasl_external_bind = false;+// Step 2: Bind credentialspublic string $ldap_uname = '';@@ -272,6 +280,7 @@ class LdapSettings extends Component$this->ldap_server_cert_ignore = (bool) $setting->ldap_server_cert_ignore;$this->ldap_client_tls_key = (string) $setting->ldap_client_tls_key;$this->ldap_client_tls_cert = (string) $setting->ldap_client_tls_cert;+ $this->ldap_use_sasl_external_bind = (bool) $setting->ldap_use_sasl_external_bind;$this->ldap_uname = (string) $setting->ldap_uname;// ldap_pword stays ''. See property docstring.@@ -426,6 +435,7 @@ class LdapSettings extends Component$setting->ldap_server_cert_ignore = $this->ldap_server_cert_ignore ? '1' : '0';$setting->ldap_client_tls_key = $this->ldap_client_tls_key;$setting->ldap_client_tls_cert = $this->ldap_client_tls_cert;+ $setting->ldap_use_sasl_external_bind = $this->ldap_use_sasl_external_bind ? '1' : '0';$this->persistAndAdvance($setting);}@@ -454,6 +464,15 @@ class LdapSettings extends Component*/protected function step1SyntaxRules(): array{+ // Snapshot the form values into locals so the SASL EXTERNAL+ // cross-field rule below sees the CURRENT submission (not the+ // persisted values). Otherwise a user who filled in cert + key+ // and toggled SASL EXTERNAL in the same page load would trip+ // the "cert not configured" guard even though they're one save+ // away from having it configured.+ $tlsCert = trim($this->ldap_client_tls_cert);+ $tlsKey = trim($this->ldap_client_tls_key);+return ['ldap_server' => 'required|starts_with:ldap://,ldaps://','ldap_client_tls_key' => [@@ -491,6 +510,25 @@ class LdapSettings extends Component}},],+ 'ldap_use_sasl_external_bind' => [+ 'nullable',+ 'boolean',+ /** @SuppressWarnings(PHPMD.UnusedFormalParameter) */+ function ($attribute, $value, $fail) use ($tlsCert, $tlsKey) {+ if (! $value) {+ return;+ }+ // SASL EXTERNAL requires the client cert + key. The+ // required_with rules above already gate the pair+ // together. Here we ensure both are populated (not+ // just consistent with each other) before enabling+ // the toggle. Empty pair + SASL toggle on would+ // fail at bind time with an opaque server error.+ if ($tlsCert === '' || $tlsKey === '') {+ $fail(trans('admin/settings/general.ldap_wizard.sasl_external_requires_cert'));+ }+ },+ ],];}@@ -500,6 +538,7 @@ class LdapSettings extends Component'ldap_server' => trans('admin/settings/general.ldap_server'),'ldap_client_tls_key' => trans('admin/settings/general.ldap_client_tls_key'),'ldap_client_tls_cert' => trans('admin/settings/general.ldap_client_tls_cert'),+ 'ldap_use_sasl_external_bind' => trans('admin/settings/general.ldap_use_sasl_external_bind'),];}@@ -623,6 +662,7 @@ class LdapSettings extends Component}$setting = Setting::getSettings();+ $setting->ldap_use_sasl_external_bind = $this->ldap_use_sasl_external_bind ? '1' : '0';$setting->ldap_uname = $this->ldap_uname;// Only overwrite the persisted encrypted password when the user// provided a new value. Blank pword = keep-what's-in-DB.@@ -642,7 +682,11 @@ class LdapSettings extends Componentprotected function canAdvanceStep2(): bool{- if (trim($this->ldap_uname) === '') {+ // SASL EXTERNAL mode authenticates via the client cert configured+ // on step 1, so ldap_uname / ldap_pword are optional (and would+ // be ignored on bind if present). Skip the empty-uname gate when+ // SASL EXTERNAL is on.+ if (! $this->ldap_use_sasl_external_bind && trim($this->ldap_uname) === '') {return false;}if (trim($this->ldap_basedn) === '') {@@ -674,9 +718,20 @@ class LdapSettings extends Component$normalizeDn = fn ($dn) => strtolower(preg_replace('/\s*,\s*/', ',', trim((string) $dn)));$bindDn = $normalizeDn($this->ldap_uname);+ // SASL EXTERNAL bind uses the client TLS cert for auth, so+ // ldap_uname / ldap_pword are optional (and unused) when it's+ // on. The flag lives on step 1 (next to the cert/key it+ // depends on). This branch just reads its persisted state to+ // decide requiredness here.+ $sasl = $this->ldap_use_sasl_external_bind;+ $unameRule = $sasl ? ['nullable', 'max:191'] : 'required|max:191';+ $pwordRule = $sasl+ ? 'nullable'+ : \Illuminate\Validation\Rule::when(! $canReusePersisted, 'required');+return [- 'ldap_uname' => 'required|max:191',- 'ldap_pword' => \Illuminate\Validation\Rule::when(! $canReusePersisted, 'required'),+ 'ldap_uname' => $unameRule,+ 'ldap_pword' => $pwordRule,'ldap_basedn' => ['required',// Guard against the common misconfiguration where the base@@ -732,29 +787,42 @@ class LdapSettings extends Componentreturn;}- // Bind, always with credentials (uname required in step2SyntaxRules).- // Password resolution: form value if provided, otherwise fall back- // to the persisted encrypted password when the username matches.+ // Bind. SASL EXTERNAL uses the client cert loaded by+ // openLdapConnectionForTest() (via LDAP_OPT_X_TLS_CERTFILE /+ // _KEYFILE) as the auth identity, so no username / password+ // gets passed. Simple bind path resolves the password from the+ // form value first, otherwise falls back to the persisted+ // encrypted password when the username matches.$settings = Setting::getSettings();$server = (string) $settings->ldap_server;- $uname = trim($this->ldap_uname);- $pword = $this->ldap_pword;- if ($pword === '' && $uname === trim((string) $settings->ldap_uname) && $settings->ldap_pword) {- try {- $pword = Crypt::decrypt($settings->ldap_pword);- } catch (\Exception $e) {- @ldap_unbind($conn);- $this->recordTestResult(- 'error',- trans('admin/settings/general.ldap_wizard.bind.pword_decrypt_failed'),- 'ldap bind test',- );- return;+ if ($this->ldap_use_sasl_external_bind) {+ // Success message uses $uname for the "Bound as ..."+ // interpolation. Under SASL EXTERNAL there is no bind+ // username, the client cert is the identity, so surface+ // that instead of leaving $uname undefined.+ $uname = trans('admin/settings/general.ldap_wizard.bind.sasl_external_identity');+ $bindOk = @ldap_sasl_bind($conn, null, null, 'EXTERNAL');+ } else {+ $uname = trim($this->ldap_uname);+ $pword = $this->ldap_pword;+ if ($pword === '' && $uname === trim((string) $settings->ldap_uname) && $settings->ldap_pword) {+ try {+ $pword = Crypt::decrypt($settings->ldap_pword);+ } catch (\Exception $e) {+ @ldap_unbind($conn);+ $this->recordTestResult(+ 'error',+ trans('admin/settings/general.ldap_wizard.bind.pword_decrypt_failed'),+ 'ldap bind test',+ );++ return;+ }}- }- $bindOk = @ldap_bind($conn, $uname, $pword);+ $bindOk = @ldap_bind($conn, $uname, $pword);+ }if (! $bindOk) {$errno = ldap_errno($conn);$ldapError = Ldap::bindError($conn);@@ -1542,17 +1610,28 @@ class LdapSettings extends Component'ldap_username_field','ldap_fname_field','custom_forgot_pass_url',- 'test_sample_username'+ 'test_sample_username',], true)) {$this->resetValidation($property);}- if (!in_array($property, [+ // Toggling is_ad ON hides the SASL EXTERNAL checkbox in the+ // Blade view but doesn't otherwise clear its state, so a user+ // who had SASL on and then flipped to AD mode would be left+ // with a hidden-but-active flag that silently gates uname /+ // pword requiredness on step 2 and picks the SASL bind branch+ // in Ldap::bindAdminToLdap(). Force it off here so the toggle+ // is always false when it isn't visible.+ if ($property === 'is_ad' && $this->is_ad && $this->ldap_use_sasl_external_bind) {+ $this->ldap_use_sasl_external_bind = false;+ }++ if (! in_array($property, ['currentStep','highestStepReached','dirty','testStatus',- 'testMessage'+ 'testMessage',], true)) {$this->dirty = true;}diff --git a/app/Models/Ldap.php b/app/Models/Ldap.phpindex 66eb552cde..ab74efd654 100644--- a/app/Models/Ldap.php+++ b/app/Models/Ldap.php@@ -271,17 +271,30 @@ class Ldap extends Model*/public static function bindAdminToLdap($connection){- $ldap_username = Setting::getSettings()->ldap_uname;+ $settings = Setting::getSettings();- if ($ldap_username) {+ // SASL EXTERNAL bind uses the client TLS cert (already loaded via+ // LDAP_OPT_X_TLS_CERTFILE / _KEYFILE in connectToLdap()) as the+ // authentication identity, so username / password are not sent.+ // Off by default. Opting in requires client cert + key to be+ // configured on step 1 of the LDAP wizard. Enables directories+ // like Google Workspace LDAP that authenticate via mTLS+ // certificate rather than a bind DN + password. See GH #19518.+ $ldap_username = $settings->ldap_uname;++ if ($settings->ldap_use_sasl_external_bind) {+ if (! @ldap_sasl_bind($connection, null, null, 'EXTERNAL')) {+ throw new Exception('Could not bind to LDAP via SASL EXTERNAL: '.self::bindError($connection));+ }+ } elseif ($ldap_username) {// Lets return some nicer messages for users who donked their app key, and disable LDAPtry {- $ldap_pass = Crypt::decrypt(Setting::getSettings()->ldap_pword);+ $ldap_pass = Crypt::decrypt($settings->ldap_pword);} catch (Exception $e) {throw new Exception('Your app key has changed! Could not decrypt LDAP password using your current app key, so LDAP authentication has been disabled. Login with a local account, update the LDAP password and re-enable it in Admin > Settings.');}- if (! $ldapbind = @ldap_bind($connection, $ldap_username, $ldap_pass)) {+ if (! @ldap_bind($connection, $ldap_username, $ldap_pass)) {throw new Exception('Could not bind to LDAP: '.self::bindError($connection));}// TODO - this just "falls off the end" but the function states that it should return true or false@@ -291,7 +304,7 @@ class Ldap extends Model// at the next refactor, this should be appropriately modified to be more consistent.} else {// LDAP should also work with anonymous bind (no dn, no password available)- if (! $ldapbind = @ldap_bind($connection)) {+ if (! @ldap_bind($connection)) {throw new Exception('Could not bind to LDAP: '.self::bindError($connection));}}diff --git a/app/Models/Setting.php b/app/Models/Setting.phpindex 89c7d7b5a7..008ab64176 100755--- a/app/Models/Setting.php+++ b/app/Models/Setting.php@@ -426,6 +426,7 @@ class Setting extends Model'ad_append_domain','ldap_client_tls_key','ldap_client_tls_cert',+ 'ldap_use_sasl_external_bind','ldap_default_group','ldap_dept','ldap_phone_field',diff --git a/database/migrations/2026_08_26_010000_add_ldap_use_sasl_external_bind_to_settings.php b/database/migrations/2026_08_26_010000_add_ldap_use_sasl_external_bind_to_settings.phpnew file mode 100644index 0000000000..686077dc26--- /dev/null+++ b/database/migrations/2026_08_26_010000_add_ldap_use_sasl_external_bind_to_settings.php@@ -0,0 +1,34 @@+<?php++use Illuminate\Database\Migrations\Migration;+use Illuminate\Database\Schema\Blueprint;+use Illuminate\Support\Facades\Schema;++/**+ * Opt-in toggle for LDAP SASL EXTERNAL bind. When on, bindAdminToLdap+ * uses ldap_sasl_bind() with the EXTERNAL mechanism (authenticates the+ * caller via the client TLS cert already configured via+ * ldap_client_tls_cert / ldap_client_tls_key) instead of a+ * username/password simple bind. Used by installs that authenticate to+ * their directory with a client cert, notably Google Workspace LDAP+ * (see GH #19518).+ *+ * Off by default so every existing install keeps the simple / anonymous+ * bind behavior it had before.+ */+return new class extends Migration+{+ public function up(): void+ {+ Schema::table('settings', function (Blueprint $table) {+ $table->boolean('ldap_use_sasl_external_bind')->default(false)->after('ldap_client_tls_cert');+ });+ }++ public function down(): void+ {+ Schema::table('settings', function (Blueprint $table) {+ $table->dropColumn('ldap_use_sasl_external_bind');+ });+ }+};diff --git a/phpstan-baseline.neon b/phpstan-baseline.neonindex 04f64537da..5ec9a6c867 100644--- a/phpstan-baseline.neon+++ b/phpstan-baseline.neon@@ -7353,7 +7353,7 @@ parameters:-message: '#^Method App\\Models\\Ldap\:\:bindAdminToLdap\(\) should return bool but return statement is missing\.$#'identifier: return.missing- count: 2+ count: 3path: app/Models/Ldap.php-diff --git a/resources/lang/en-US/admin/settings/general.php b/resources/lang/en-US/admin/settings/general.phpindex 3c3d74a922..cacc217373 100644--- a/resources/lang/en-US/admin/settings/general.php+++ b/resources/lang/en-US/admin/settings/general.php@@ -105,10 +105,12 @@ return [],'step_connection_help' => 'Configure how to reach your LDAP or Active Directory server. Once saved, you can test the connection before moving on to bind credentials.','ldap_uname_help' => 'The distinguished name (DN) or User Principal Name (UPN) of an admin service account that can search your directory. For Active Directory this is usually a UPN like <code>[email protected]</code>. For OpenLDAP and most other directories this is a full DN like <code>cn=admin,dc=example,dc=com</code>. Enter the entire path including the base DN portion, not just the account name.',+ 'sasl_external_requires_cert' => 'SASL EXTERNAL bind requires a client TLS certificate and key. Configure both on the Connection step before enabling this option.','ldap_pword_help' => 'Leave blank to keep the previously-saved password.','bind' => ['pword_decrypt_failed' => 'Could not decrypt the stored bind password. This usually means the app key changed since the password was saved. Enter the password again to fix.','rejected' => 'The LDAP server rejected the bind (:error). Double-check the username and password.',+ 'sasl_external_identity' => 'the SASL EXTERNAL client certificate',],'ldap_basedn_help' => 'The distinguished name (DN) where the user search begins. Everything below this DN is in scope. Typically the OU or container that holds your synced users.','ldap_filter_help' => 'LDAP filter expression used to narrow the search to synceable users. Omit the outer parentheses, they are wrapped automatically. Leave blank to accept all objects under the base DN, though this is rarely what you want.',@@ -212,6 +214,8 @@ return ['ldap_tls' => 'Use TLS','ldap_tls_help' => 'This should be checked only if you are running STARTTLS on your LDAP server. ','ldap_uname' => 'LDAP Bind DN/UPN',+ 'ldap_use_sasl_external_bind' => 'Use SASL EXTERNAL bind (authenticate with client certificate)',+ 'ldap_use_sasl_external_bind_help' => 'When enabled, Snipe-IT authenticates to the directory using the client TLS certificate and key configured on the Server step, and the Bind DN/UPN and Bind Password below are ignored. Required for Google Workspace LDAP deployments that use certificate-based authentication.','ldap_dept' => 'Department Field','ldap_phone' => 'Phone Number Field','ldap_jobtitle' => 'Job Title Field',diff --git a/resources/views/blade/form/row.blade.php b/resources/views/blade/form/row.blade.phpindex dd7e332340..bf54f0cc31 100644--- a/resources/views/blade/form/row.blade.php+++ b/resources/views/blade/form/row.blade.php@@ -10,6 +10,7 @@'label' => null,'label_class' => 'col-md-3','input_div_class' => 'col-md-7',+ 'help_class' => 'col-md-9 col-md-offset-3','input_icon' => null,'input_group_addon' => null,'maxlength' => null,@@ -135,7 +136,13 @@<div class="clearfix"></div>@endif- <div @class(['col-md-9 col-md-offset-3' => ! $stacked])>+ {{-- Error + help wrapper. Default col-md-9 col-md-offset-3 aligns+ under the input column (which sits after the col-md-3 label)+ with room to breathe on its own row. Callers with a visually-+ narrower input (a textarea whose width is pinned by its rows+ attribute, for example) can pass help_class to match the input+ width so long help doesn't extend past the visible input box. --}}+ <div @class([$help_class => ! $stacked])><x-form.error :name="$name" />@if ($help_text)diff --git a/resources/views/livewire/ldap-settings.blade.php b/resources/views/livewire/ldap-settings.blade.phpindex 7696a04c0c..0ef3f680f8 100644--- a/resources/views/livewire/ldap-settings.blade.php+++ b/resources/views/livewire/ldap-settings.blade.php@@ -429,6 +429,7 @@<x-form.rowname="ldap_client_tls_key":label="trans('admin/settings/general.ldap_client_tls_key')"+ help_class="col-md-7 col-md-offset-3"><x-slot:input><x-input.textarea@@ -447,6 +448,7 @@name="ldap_client_tls_cert":label="trans('admin/settings/general.ldap_client_tls_cert')"help_text="{!! trans('admin/settings/general.ldap_client_tls_cert_help') !!}"+ help_class="col-md-7 col-md-offset-3"><x-slot:input><x-input.textarea@@ -460,6 +462,26 @@</x-slot:input></x-form.row>+ {{-- SASL EXTERNAL bind toggle. Lives next to the cert /+ key fields it depends on. Its state makes the Bind+ DN/UPN + Bind Password fields on step 2 optional.+ Hidden when is_ad is on: Active Directory servers+ support cert-based auth only under a specific AD+ Certificate Services / cert-mapping deployment that+ almost nobody runs, and cluttering the AD-common+ path with an option nobody uses would confuse more+ than it helps. --}}+ @if (! $is_ad)+ <x-form.checkbox-row+ name="ldap_use_sasl_external_bind"+ wire:model.live="ldap_use_sasl_external_bind"+ :label="trans('admin/settings/general.ldap_use_sasl_external_bind')"+ :checked="$ldap_use_sasl_external_bind"+ help_text="{!! trans('admin/settings/general.ldap_use_sasl_external_bind_help') !!}"+ :disabled="$isReadOnly"+ />+ @endif+@elseif ($currentStep === 2){{-- Merged Authenticate + Scope step. Bind credentialsappear next to the base DN so users composing a@@ -494,14 +516,16 @@><x-slot:input>{{-- Placeholder swaps based on the step-1 AD flag:- UPN form for AD, full DN form otherwise. --}}+ UPN form for AD, full DN form otherwise. Not+ required when SASL EXTERNAL is on because+ the bind identity comes from the client cert. --}}<x-input.textname="ldap_uname"wire:model.live.debounce.500ms="ldap_uname"placeholder="{{ trans('general.example').($is_ad ? '[email protected]' : 'cn=admin,dc=example,dc=com') }}":ignore-autofill="true"- :required="true"- :readonly="$isReadOnly"+ :required="! $ldap_use_sasl_external_bind"+ :readonly="$isReadOnly || $ldap_use_sasl_external_bind"/></x-slot:input></x-form.row>@@ -516,9 +540,9 @@<x-input.passwordname="ldap_pword"wire:model.live.debounce.500ms="ldap_pword"- :required="true"+ :required="! $ldap_use_sasl_external_bind":ignore-autofill="true"- :readonly="$isReadOnly"+ :readonly="$isReadOnly || $ldap_use_sasl_external_bind"/></x-slot:input></x-form.row>@@ -795,6 +819,7 @@'ldap_server_cert_ignore' => trans('admin/settings/general.ldap_server_cert_ignore'),'is_ad' => trans('admin/settings/general.is_ad'),'ad_domain' => trans('admin/settings/general.ad_domain'),+ 'ldap_use_sasl_external_bind' => trans('admin/settings/general.ldap_use_sasl_external_bind'),],],2 => [diff --git a/tests/Unit/LdapTest.php b/tests/Unit/LdapTest.phpindex 73b6f52c22..7aaf9d788c 100644--- a/tests/Unit/LdapTest.php+++ b/tests/Unit/LdapTest.php@@ -94,6 +94,60 @@ class LdapTest extends TestCase$this->assertNull(Ldap::bindAdminToLdap('dummy'));}+ public function test_sasl_external_bind_when_setting_is_on()+ {+ // GH #19518: SASL EXTERNAL bind (auth via client TLS cert)+ // must route through ldap_sasl_bind, not ldap_bind. Username+ // and password on the setting must be ignored.+ $this->settings->enableLdap();+ $this->settings->set(['ldap_use_sasl_external_bind' => 1]);++ $this->getFunctionMock('App\\Models', 'ldap_sasl_bind')+ ->expects($this->once())+ ->with('dummy', null, null, 'EXTERNAL')+ ->willReturn(true);+ $this->getFunctionMock('App\\Models', 'ldap_bind')+ ->expects($this->never());++ $this->assertNull(Ldap::bindAdminToLdap('dummy'));+ }++ public function test_sasl_external_bind_failure_surfaces_error()+ {+ $this->settings->enableLdap();+ $this->settings->set(['ldap_use_sasl_external_bind' => 1]);++ $this->getFunctionMock('App\\Models', 'ldap_sasl_bind')+ ->expects($this->once())+ ->willReturn(false);+ $this->getFunctionMock('App\\Models', 'ldap_error')+ ->expects($this->once())+ ->willReturn('cert rejected');+ // bindError also queries LDAP_OPT_DIAGNOSTIC_MESSAGE (see #19519).+ $this->getFunctionMock('App\\Models', 'ldap_get_option')+ ->expects($this->once())+ ->willReturn(true);+ $this->expectExceptionMessage('Could not bind to LDAP via SASL EXTERNAL');++ $this->assertNull(Ldap::bindAdminToLdap('dummy'));+ }++ public function test_simple_bind_still_used_when_sasl_external_is_off()+ {+ // Regression guard: existing installs (SASL EXTERNAL off, which+ // is the default) must keep the pre-#19518 simple-bind path.+ $this->settings->enableLdap();+ $this->settings->set(['ldap_use_sasl_external_bind' => 0]);++ $this->getFunctionMock('App\\Models', 'ldap_bind')+ ->expects($this->once())+ ->willReturn(true);+ $this->getFunctionMock('App\\Models', 'ldap_sasl_bind')+ ->expects($this->never());++ $this->assertNull(Ldap::bindAdminToLdap('dummy'));+ }+public function test_find_and_bind(){$this->settings->enableLdap();