From 8c131a06090950c70c0035fd9797852d5ef57ede Mon Sep 17 00:00:00 2001 From: Clint Branham Date: Wed, 25 Mar 2026 08:34:30 -0500 Subject: [PATCH] fix: re-authenticate during cluster join -Wait on 401 Cluster join restarts auth services on the joining node, which invalidates the PVE ticket mid-poll. When WaitForTask gets a 401, catch it and re-authenticate with the password already available in the cmdlet, then retry the wait. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../Cluster/AddPveClusterMemberCmdlet.cs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/PSProxmoxVE/Cmdlets/Cluster/AddPveClusterMemberCmdlet.cs b/src/PSProxmoxVE/Cmdlets/Cluster/AddPveClusterMemberCmdlet.cs index 5817459..0f630f4 100644 --- a/src/PSProxmoxVE/Cmdlets/Cluster/AddPveClusterMemberCmdlet.cs +++ b/src/PSProxmoxVE/Cmdlets/Cluster/AddPveClusterMemberCmdlet.cs @@ -1,7 +1,10 @@ using System; using System.Management.Automation; +using System.Net; using System.Runtime.InteropServices; using System.Security; +using PSProxmoxVE.Core.Authentication; +using PSProxmoxVE.Core.Exceptions; using PSProxmoxVE.Core.Models.Vms; using PSProxmoxVE.Core.Services; @@ -80,7 +83,20 @@ namespace PSProxmoxVE.Cmdlets.Cluster { var nodeName = upid.Split(':').Length > 1 ? upid.Split(':')[1] : session.Hostname; var taskService = new TaskService(); - task = taskService.WaitForTask(session, nodeName, upid); + try + { + task = taskService.WaitForTask(session, nodeName, upid); + } + catch (PveApiException ex) when (ex.StatusCode == HttpStatusCode.Unauthorized) + { + // Cluster join restarts auth services on this node, invalidating + // the ticket mid-poll. Re-authenticate and retry. + WriteVerbose("Session expired during join — re-authenticating to poll task status..."); + var newSession = PveAuthenticator.AuthenticateWithCredentials( + session.Hostname, session.Port, session.SkipCertificateCheck, + "root@pam", plainPassword); + task = taskService.WaitForTask(newSession, nodeName, upid); + } } WriteObject(task);