From 1aa2355aed098079376dfe19f1280d3dc2418975 Mon Sep 17 00:00:00 2001 From: Christoph Heiss Date: Tue, 31 Jan 2023 13:50:42 +0100 Subject: [PATCH] ldap: Allow quoted values for DN attribute values This fixes #3748 by allowing reserved characters in `bind_dn` (and other properties of the same format) if they are properly quoted and adds some corresponding documentation regarding that. This was tested by setting up a slapd server and creating a user with the CN `Test, User` much like in the bug report, then using this user as `bind_dn` in the sync options. I also tested some variants of that CN, including just `TestUser`.) One thing that still won't work is syncing of LDAP users with colons or slashes in their CNs. In such cases, the message > value 'Test, User@ldap' does not look like a valid user name will pop up. This is due to spaces and colons being explicitly disallowed in usernames by PVE access-control's username schema. This probably means that such names can never be allowed, which is being documented too as separate pve-docs patch. Note that while this is now a bit more strict for some cases too, they should not matter in practice. For context; see RFC 2253 [0], section 4. Interestingly, this document was obsoleted by RFC 4514 [1] in 2006, which only mentions this in section 2.4 ("Converting an AttributeValue from ASN.1 to a String") and appendix A ("Presentation Issues"). But the first one seems to be the "authoritive" document on this matter, at least looking at some other docs about LDAP DNs (RedHat, Microsoft, ..). [0] https://www.ietf.org/rfc/rfc2253.txt [1] https://docs.ldap.com/specs/rfc4514.txt Reviewed-by: Dominik Csapak Tested-by: Dominik Csapak Signed-off-by: Christoph Heiss [ T: added commit message ] Signed-off-by: Thomas Lamprecht --- src/PVE/Auth/LDAP.pm | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/PVE/Auth/LDAP.pm b/src/PVE/Auth/LDAP.pm index 4792586..4d771e7 100755 --- a/src/PVE/Auth/LDAP.pm +++ b/src/PVE/Auth/LDAP.pm @@ -10,6 +10,8 @@ use PVE::Tools; use base qw(PVE::Auth::Plugin); +our $dn_regex = qr!\w+=("[\w ,+/<>;=]+"|[^ ,+"/<>;=]+)(,\s*\w+=("[\w ,+/<>;=]+"|[^ ,+"/<>;=]+))*!; + sub type { return 'ldap'; } @@ -19,7 +21,7 @@ sub properties { base_dn => { description => "LDAP base domain name", type => 'string', - pattern => '\w+=[^,]+(,\s*\w+=[^,]+)*', + pattern => $dn_regex, optional => 1, maxLength => 256, }, @@ -33,7 +35,7 @@ sub properties { bind_dn => { description => "LDAP bind domain name", type => 'string', - pattern => '\w+=[^,]+(,\s*\w+=[^,]+)*', + pattern => $dn_regex, optional => 1, maxLength => 256, }, @@ -91,7 +93,7 @@ sub properties { description => "LDAP base domain name for group sync. If not set, the" ." base_dn will be used.", type => 'string', - pattern => '\w+=[^,]+(,\s*\w+=[^,]+)*', + pattern => $dn_regex, optional => 1, maxLength => 256, },