From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id 3889A1FF0E7 for ; Fri, 10 Jul 2026 13:53:53 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id BF25F21444; Fri, 10 Jul 2026 13:53:51 +0200 (CEST) From: Elias Huhsovitz To: pve-devel@lists.proxmox.com Subject: [PATCH access-control v2] fix #7144: auth: ldap: force utf-8 encoding for bind credentials Date: Fri, 10 Jul 2026 13:52:58 +0200 Message-ID: <20260710115258.108502-1-e.huhsovitz@proxmox.com> X-Mailer: git-send-email 2.47.3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1783684386271 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.000 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: 5Q7N7XR44U3NFTP67VLIXCCRRJDIXT3H X-Message-ID-Hash: 5Q7N7XR44U3NFTP67VLIXCCRRJDIXT3H X-MailFrom: e.huhsovitz@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Elias Huhsovitz X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: When saving the LDAP/AD bind password to /etc/pve/priv/realm/.pw, the file was written using the default byte encoding. This caused passwords containing non-ASCII characters (e.g., '£' or '§') to be truncated to their lowest byte, resulting in authentication failures during subsequent sync operations. Pass the 'force_utf8' flag to file_set_contents to ensure the password is encoded as UTF-8 before being written to disk. Explicitly pass 0600 as the permission mask. (Previously undef, using the default 0644 for PVE::File::file_set_contents). Decode the password into a UTF-8 string after reading from disk. Signed-off-by: Elias Huhsovitz --- changes since v1: * explain the choice of 0600 in the commit message. * decode ldap bind credential as UTF-8 before sending it. src/PVE/Auth/LDAP.pm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/PVE/Auth/LDAP.pm b/src/PVE/Auth/LDAP.pm index 6a73ee8..bf6ba17 100755 --- a/src/PVE/Auth/LDAP.pm +++ b/src/PVE/Auth/LDAP.pm @@ -438,7 +438,7 @@ sub ldap_set_credentials { my $cred_file = ldap_cred_file_name($realmid); mkdir $ldap_pw_dir; - PVE::Tools::file_set_contents($cred_file, $password); + PVE::Tools::file_set_contents($cred_file, $password, 0600, 1); return $cred_file; } @@ -447,7 +447,8 @@ sub ldap_get_credentials { my ($realmid) = @_; if (my $cred_file = get_cred_file($realmid)) { - return PVE::Tools::file_read_firstline($cred_file); + my $raw = PVE::Tools::file_read_firstline($cred_file); + return defined($raw) ? decode('UTF-8', $raw) : undef; } return undef; } -- 2.47.3