]> git.proxmox.com Git - pve-access-control.git/commitdiff
LDAP: skip anonymous bind when clientcert/key is given
authorDominik Csapak <d.csapak@proxmox.com>
Fri, 8 May 2020 11:16:58 +0000 (13:16 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 8 May 2020 11:35:18 +0000 (13:35 +0200)
It seems that servers associate the client-cert/key with an account, so
doing an explicit anonymous bind then 'logs out' the already verified
user, limiting the search results in some cases

before refactoring to PVE::LDAP, we did not do '$ldap->bind' at all when
there was no bind_dn, but it is not really clear if Net::LDAP does this
automatically when searching (other libraries do this), so leave the
anonymous bind (for compatibility with PMG) but skip it when a client
certificate and key is given.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
PVE/Auth/LDAP.pm

index 9fa909500f3693d5626546ccf7b3369970eee1d6..09b220201a35ef49c18c852fe2f92560b1f71ea1 100755 (executable)
@@ -203,17 +203,17 @@ sub connect_and_bind {
 
     my $ldap = PVE::LDAP::ldap_connect($servers, $scheme, $port, \%ldap_args);
 
-    my $bind_dn;
-    my $bind_pass;
-
     if ($config->{bind_dn}) {
-       $bind_dn = $config->{bind_dn};
-       $bind_pass = ldap_get_credentials($realm);
+       my $bind_dn = $config->{bind_dn};
+       my $bind_pass = ldap_get_credentials($realm);
        die "missing password for realm $realm\n" if !defined($bind_pass);
+       PVE::LDAP::ldap_bind($ldap, $bind_dn, $bind_pass);
+    } elsif ($config->{cert} && $config->{certkey}) {
+       warn "skipping anonymous bind with clientcert\n";
+    } else {
+       PVE::LDAP::ldap_bind($ldap);
     }
 
-    PVE::LDAP::ldap_bind($ldap, $bind_dn, $bind_pass);
-
     if (!$config->{base_dn}) {
        my $root = $ldap->root_dse(attrs => [ 'defaultNamingContext' ]);
        $config->{base_dn} = $root->get_value('defaultNamingContext');