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 2DDA41FF0C0 for ; Wed, 18 Nov 2026 15:29:05 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 671AE2171C; Wed, 18 Nov 2026 15:28:50 +0100 (CET) From: Shannon Sterz To: pve-devel@lists.proxmox.com Subject: [PATCH cluster 2/2] cluster: setup: match PermitRootLogin option more precisely Date: Wed, 18 Nov 2026 15:28:25 +0100 Message-ID: <20261118142825.100797-3-s.sterz@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261118142825.100797-1-s.sterz@proxmox.com> References: <20261118142825.100797-1-s.sterz@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1795012123610 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.555 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) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust 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: LSKIT6J2M43S6ZARKE4KLD4B3TPDGNNN X-Message-ID-Hash: LSKIT6J2M43S6ZARKE4KLD4B3TPDGNNN X-MailFrom: s.sterz@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 X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: `setup_sshd_config()` tries to find a line relating to the setting `PermitRootLogin` in the sshd config. the previous regex did not match certain cases (e.g., " PermitRootLogin yes"; " # PermitRootLogin no"). if nothing is matched the function adds a "PermitRootLogin yes" line to the end of the file. this would allow for cases where " PermitRootLogin no" and "PermitRootLogin yes" are present in the same file. sshd applies the first option it finds, so root login would be disabled. without "PermitRootLogin yes" set any cluster join and certain functionality, such as zfs replication, would break. adjust the regex so that the "PermitRootLogin" option is picked up in those cases too. also match case insensitively and allow statements such as `permitrootlogin=yes` as OpenSSH also accepts them. further, the early return is extended to only care about the first occurrence of the `PermitRootLogin` option as that's the one OpenSSH cares about. Signed-off-by: Shannon Sterz --- Notes: note that by default on our installs the setting is "PermitRootLogin yes". so this scenario could only happen if a user manually adjusts it. however, setting "PermitRootLogin no" is often recommended so someone accidentally adding a space infront of that line is not impossible. src/PVE/Cluster/Setup.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PVE/Cluster/Setup.pm b/src/PVE/Cluster/Setup.pm index 2550f70..b446059 100644 --- a/src/PVE/Cluster/Setup.pm +++ b/src/PVE/Cluster/Setup.pm @@ -150,9 +150,9 @@ sub setup_sshd_config { my $conf = PVE::Tools::file_get_contents($ssh_system_server_config); - return if $conf =~ m/^PermitRootLogin\s+yes\s*$/m; + return if $conf =~ m/^\h*PermitRootLogin(?:\h*=\h*|\h+)(\S+)/mi && lc($1) eq 'yes'; - if ($conf !~ s/^#?PermitRootLogin.*$/PermitRootLogin yes/m) { + if ($conf !~ s/^(?:\h*#)*\h*PermitRootLogin.*$/PermitRootLogin yes/mi) { chomp $conf; $conf .= "\nPermitRootLogin yes\n"; } -- 2.47.3