Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
Fix Proxmox token preservation regressions
rcourtmand52231855d19
diff --git a/install.sh b/install.shindex 91b71abfc3..e3ad570d22 100755--- a/install.sh+++ b/install.sh@@ -2109,6 +2109,35 @@ extract_pve_token_value() {'}+pve_token_already_exists_error() {+ local token_output="$1"+ printf '%s\n' "$token_output" | grep -Eqi 'already exists|already defined|duplicate|exists already'+}++create_pve_auto_register_token() {+ local token_name="$1"+ local token_output_var="$2"+ local token_status_var="$3"+ local token_output=""+ local token_status=0++ set +e+ token_output=$(pveum user token add pulse-monitor@pve "$token_name" --privsep 1 --output-format json 2>&1)+ token_status=$?+ set -e++ # Older pveum builds reject --output-format; fall back to the legacy table form.+ if [[ $token_status -ne 0 ]] && printf '%s\n' "$token_output" | grep -Eqi 'unknown option|unknown command|no such option|unable to parse option|output-format'; then+ set +e+ token_output=$(pveum user token add pulse-monitor@pve "$token_name" --privsep 1 2>&1)+ token_status=$?+ set -e+ fi++ printf -v "$token_output_var" '%s' "$token_output"+ printf -v "$token_status_var" '%s' "$token_status"+}+auto_register_pve_node() {local ctid="$1"local pulse_ip="$2"@@ -2419,16 +2448,16 @@ PY)local token_output=""- set +e- token_output=$(pveum user token add pulse-monitor@pve "$token_name" --privsep 1 --output-format json 2>&1)- local token_status=$?- set -e- # Older pveum builds reject --output-format; fall back to the legacy table form.- if [[ $token_status -ne 0 ]] && printf '%s\n' "$token_output" | grep -Eqi 'unknown option|unknown command|no such option|unable to parse option|output-format'; then- set +e- token_output=$(pveum user token add pulse-monitor@pve "$token_name" --privsep 1 2>&1)- token_status=$?- set -e+ local token_status=0+ create_pve_auto_register_token "$token_name" token_output token_status+ if [[ $token_status -ne 0 ]] && pve_token_already_exists_error "$token_output"; then+ print_info "Existing Proxmox monitoring token '${token_name}' found; rotating it so Pulse receives a fresh secret"+ if ! pveum user token remove pulse-monitor@pve "$token_name" >/dev/null 2>&1; then+ AUTO_NODE_REGISTER_ERROR="failed to rotate existing token"+ print_warn "Unable to remove existing monitoring API token; skipping automatic node registration"+ return+ fi+ create_pve_auto_register_token "$token_name" token_output token_statusfiif [[ $token_status -ne 0 ]]; thenAUTO_NODE_REGISTER_ERROR="failed to create token"diff --git a/internal/api/config_handlers.go b/internal/api/config_handlers.goindex 9ccf05bfef..fae1b953d6 100644--- a/internal/api/config_handlers.go+++ b/internal/api/config_handlers.go@@ -2,6 +2,7 @@ package apiimport ("context"+ "encoding/json""fmt""net""net/http"@@ -691,6 +692,26 @@ type NodeConfigRequest struct {MonitorQuarantine *bool `json:"monitorQuarantine,omitempty"` // PMG onlyMonitorDomainStats *bool `json:"monitorDomainStats,omitempty"` // PMG onlyEnabled *bool `json:"enabled,omitempty"` // Lifecycle toggle; nil on update preserves current+ guestURLSet bool `json:"-"`+ fingerprintSet bool `json:"-"`+}++func (r *NodeConfigRequest) UnmarshalJSON(data []byte) error {+ type nodeConfigRequestJSON NodeConfigRequest++ var decoded nodeConfigRequestJSON+ if err := json.Unmarshal(data, &decoded); err != nil {+ return err+ }+ var raw map[string]json.RawMessage+ if err := json.Unmarshal(data, &raw); err != nil {+ return err+ }++ *r = NodeConfigRequest(decoded)+ _, r.guestURLSet = raw["guestURL"]+ _, r.fingerprintSet = raw["fingerprint"]+ return nil}func (r *NodeConfigRequest) normalizeTokenAliases() {@@ -703,6 +724,40 @@ func (r *NodeConfigRequest) normalizeTokenAliases() {if r.TokenValue == "" {r.TokenValue = strings.TrimSpace(r.TokenSecret)}+ if isRedactedCredentialPlaceholder(r.TokenValue) {+ r.TokenValue = ""+ }+ if isRedactedCredentialPlaceholder(r.Password) {+ r.Password = ""+ }+}++func (r NodeConfigRequest) hasGuestURLField() bool {+ return r.guestURLSet+}++func (r NodeConfigRequest) hasFingerprintField() bool {+ return r.fingerprintSet+}++func isRedactedCredentialPlaceholder(value string) bool {+ trimmed := strings.TrimSpace(value)+ switch strings.ToLower(trimmed) {+ case "[redacted]", "redacted", "********":+ return true+ }+ if len([]rune(trimmed)) < 6 {+ return false+ }+ for _, r := range trimmed {+ switch r {+ case '*', '•', '●':+ continue+ default:+ return false+ }+ }+ return true}// NodeResponse represents a node in API responsesdiff --git a/internal/api/config_handlers_update_test.go b/internal/api/config_handlers_update_test.goindex 923101fff3..31a1f69e64 100644--- a/internal/api/config_handlers_update_test.go+++ b/internal/api/config_handlers_update_test.go@@ -243,3 +243,164 @@ func TestHandleUpdateNode_AllowsProjectedNetNewSystemWithoutPaidLimit(t *testingt.Fatalf("expected update to apply new host without paid limit enforcement, got %q", got)}}++func TestHandleUpdateNode_PreservesPVESecretsAndConnectionFieldsWhenOmitted(t *testing.T) {+ cfg := &config.Config{+ DataPath: t.TempDir(),+ PVEInstances: []config.PVEInstance{{+ Name: "cluster",+ Host: "https://pve.local:8006",+ GuestURL: "https://guest.pve.local",+ Fingerprint: "AA:BB:CC",+ TokenName: "pulse-monitor@pve!pulse-pve-local",+ TokenValue: "saved-secret",+ VerifySSL: true,+ }},+ }+ handler := newTestConfigHandlers(t, cfg)++ body, _ := json.Marshal(map[string]any{+ "name": "cluster-renamed",+ "tokenName": "pulse-monitor@pve!pulse-pve-local",+ "tokenValue": "********",+ })+ req := httptest.NewRequest(http.MethodPut, "/api/config/nodes/pve-0", bytes.NewBuffer(body))+ rec := httptest.NewRecorder()++ handler.HandleUpdateNode(rec, req)++ if rec.Code != http.StatusOK {+ t.Fatalf("expected update to succeed, got %d: %s", rec.Code, rec.Body.String())+ }+ node := cfg.PVEInstances[0]+ if node.TokenValue != "saved-secret" {+ t.Fatalf("token value = %q, want preserved saved secret", node.TokenValue)+ }+ if node.GuestURL != "https://guest.pve.local" {+ t.Fatalf("guestURL = %q, want preserved guest URL", node.GuestURL)+ }+ if node.Fingerprint != "AA:BB:CC" {+ t.Fatalf("fingerprint = %q, want preserved fingerprint", node.Fingerprint)+ }+}++func TestHandleUpdateNode_RejectsTokenNameChangeWithoutNewSecret(t *testing.T) {+ cfg := &config.Config{+ DataPath: t.TempDir(),+ PVEInstances: []config.PVEInstance{{+ Name: "cluster",+ Host: "https://pve.local:8006",+ TokenName: "pulse-monitor@pve!old",+ TokenValue: "saved-secret",+ }},+ }+ handler := newTestConfigHandlers(t, cfg)++ body, _ := json.Marshal(map[string]any{+ "tokenName": "pulse-monitor@pve!new",+ })+ req := httptest.NewRequest(http.MethodPut, "/api/config/nodes/pve-0", bytes.NewBuffer(body))+ rec := httptest.NewRecorder()++ handler.HandleUpdateNode(rec, req)++ if rec.Code != http.StatusBadRequest {+ t.Fatalf("expected token-name-only change to fail, got %d: %s", rec.Code, rec.Body.String())+ }+ node := cfg.PVEInstances[0]+ if node.TokenName != "pulse-monitor@pve!old" || node.TokenValue != "saved-secret" {+ t.Fatalf("token auth changed after rejected update: %+v", node)+ }+}++func TestHandleUpdateNode_RejectsTokenNameWithoutPreservedSecret(t *testing.T) {+ cfg := &config.Config{+ DataPath: t.TempDir(),+ PVEInstances: []config.PVEInstance{{+ Name: "cluster",+ Host: "https://pve.local:8006",+ User: "root@pam",+ Password: "saved-password",+ }},+ }+ handler := newTestConfigHandlers(t, cfg)++ body, _ := json.Marshal(map[string]any{+ "tokenName": "pulse-monitor@pve!new",+ })+ req := httptest.NewRequest(http.MethodPut, "/api/config/nodes/pve-0", bytes.NewBuffer(body))+ rec := httptest.NewRecorder()++ handler.HandleUpdateNode(rec, req)++ if rec.Code != http.StatusBadRequest {+ t.Fatalf("expected token auth without a secret to fail, got %d: %s", rec.Code, rec.Body.String())+ }+ node := cfg.PVEInstances[0]+ if node.Password != "saved-password" || node.TokenName != "" || node.TokenValue != "" {+ t.Fatalf("password auth changed after rejected update: %+v", node)+ }+}++func TestHandleUpdateNode_UserOnlyEditDoesNotClearProxmoxTokenAuth(t *testing.T) {+ cfg := &config.Config{+ DataPath: t.TempDir(),+ PBSInstances: []config.PBSInstance{{+ Name: "backup",+ Host: "https://pbs.local:8007",+ User: "",+ Password: "",+ TokenName: "pulse-monitor@pbs!pulse-pbs-local",+ TokenValue: "pbs-secret",+ MonitorBackups: false,+ }},+ PMGInstances: []config.PMGInstance{{+ Name: "mail",+ Host: "https://pmg.local:8006",+ User: "",+ Password: "",+ TokenName: "pulse-monitor@pmg!pulse-pmg-local",+ TokenValue: "pmg-secret",+ MonitorMailStats: false,+ }},+ }+ handler := newTestConfigHandlers(t, cfg)++ for _, tc := range []struct {+ name string+ nodeID string+ }{+ {name: "pbs", nodeID: "pbs-0"},+ {name: "pmg", nodeID: "pmg-0"},+ } {+ t.Run(tc.name, func(t *testing.T) {+ body, _ := json.Marshal(map[string]any{+ "user": "someone",+ })+ req := httptest.NewRequest(http.MethodPut, "/api/config/nodes/"+tc.nodeID, bytes.NewBuffer(body))+ rec := httptest.NewRecorder()++ handler.HandleUpdateNode(rec, req)++ if rec.Code != http.StatusOK {+ t.Fatalf("expected update to succeed, got %d: %s", rec.Code, rec.Body.String())+ }+ })+ }++ pbs := cfg.PBSInstances[0]+ if pbs.TokenName != "pulse-monitor@pbs!pulse-pbs-local" || pbs.TokenValue != "pbs-secret" || pbs.User != "" || pbs.Password != "" {+ t.Fatalf("PBS token auth changed after user-only edit: %+v", pbs)+ }+ if pbs.MonitorBackups {+ t.Fatalf("PBS monitor backups should preserve false when omitted")+ }++ pmg := cfg.PMGInstances[0]+ if pmg.TokenName != "pulse-monitor@pmg!pulse-pmg-local" || pmg.TokenValue != "pmg-secret" || pmg.User != "" || pmg.Password != "" {+ t.Fatalf("PMG token auth changed after user-only edit: %+v", pmg)+ }+ if pmg.MonitorMailStats {+ t.Fatalf("PMG monitor mail stats should preserve false when omitted")+ }+}diff --git a/internal/api/config_node_handlers.go b/internal/api/config_node_handlers.goindex 62a71ac916..f0bbf09b1c 100644--- a/internal/api/config_node_handlers.go+++ b/internal/api/config_node_handlers.go@@ -1054,8 +1054,160 @@ func (h *ConfigHandlers) handleTestConnection(w http.ResponseWriter, r *http.Req}}-// HandleUpdateNode updates an existing node+func applyPVEAuthUpdate(updated *config.PVEInstance, req NodeConfigRequest) error {+ tokenNameProvided := req.TokenName != ""+ tokenValueProvided := req.TokenValue != ""++ switch {+ case tokenNameProvided && tokenValueProvided:+ updated.TokenName = req.TokenName+ updated.TokenValue = req.TokenValue+ updated.Password = ""+ if req.User != "" {+ updated.User = req.User+ }+ case tokenValueProvided:+ if strings.TrimSpace(updated.TokenName) == "" {+ return fmt.Errorf("token value requires an existing token ID or tokenName")+ }+ updated.TokenValue = req.TokenValue+ updated.Password = ""+ if req.User != "" {+ updated.User = req.User+ }+ case tokenNameProvided:+ if strings.TrimSpace(updated.TokenValue) == "" {+ return fmt.Errorf("tokenName without tokenValue cannot enable token authentication")+ }+ if updated.TokenName != "" && req.TokenName != updated.TokenName {+ return fmt.Errorf("tokenName changes require a new tokenValue")+ }+ updated.TokenName = req.TokenName+ updated.Password = ""+ if req.User != "" {+ updated.User = req.User+ }+ case req.Password != "":+ if req.User != "" {+ updated.User = normalizePVEUser(req.User)+ } else if updated.User != "" {+ updated.User = normalizePVEUser(updated.User)+ }+ updated.Password = req.Password+ updated.TokenName = ""+ updated.TokenValue = ""+ default:+ if req.User != "" && updated.Password != "" && updated.TokenName == "" && updated.TokenValue == "" {+ updated.User = normalizePVEUser(req.User)+ } else if updated.User != "" {+ updated.User = normalizePVEUser(updated.User)+ }+ }++ return nil+}++func applyPBSAuthUpdate(updated *config.PBSInstance, req NodeConfigRequest) error {+ tokenNameProvided := req.TokenName != ""+ tokenValueProvided := req.TokenValue != ""++ switch {+ case tokenNameProvided && tokenValueProvided:+ updated.TokenName = req.TokenName+ updated.TokenValue = req.TokenValue+ updated.User = ""+ updated.Password = ""+ case tokenValueProvided:+ if strings.TrimSpace(updated.TokenName) == "" {+ return fmt.Errorf("token value requires an existing token ID or tokenName")+ }+ updated.TokenValue = req.TokenValue+ updated.User = ""+ updated.Password = ""+ case tokenNameProvided:+ if strings.TrimSpace(updated.TokenValue) == "" {+ return fmt.Errorf("tokenName without tokenValue cannot enable token authentication")+ }+ if updated.TokenName != "" && req.TokenName != updated.TokenName {+ return fmt.Errorf("tokenName changes require a new tokenValue")+ }+ updated.TokenName = req.TokenName+ updated.User = ""+ updated.Password = ""+ case req.Password != "":+ updated.Password = req.Password+ updated.User = normalizePBSUser(req.User)+ updated.TokenName = ""+ updated.TokenValue = ""+ default:+ if req.User != "" && updated.Password != "" && updated.TokenName == "" && updated.TokenValue == "" {+ updated.User = normalizePBSUser(req.User)+ }+ }++ return nil+}++func applyPMGAuthUpdate(updated *config.PMGInstance, req NodeConfigRequest) error {+ tokenNameProvided := req.TokenName != ""+ tokenValueProvided := req.TokenValue != ""++ switch {+ case tokenNameProvided && tokenValueProvided:+ updated.TokenName = req.TokenName+ updated.TokenValue = req.TokenValue+ updated.User = ""+ updated.Password = ""+ case tokenValueProvided:+ if strings.TrimSpace(updated.TokenName) == "" {+ return fmt.Errorf("token value requires an existing token ID or tokenName")+ }+ updated.TokenValue = req.TokenValue+ updated.User = ""+ updated.Password = ""+ case tokenNameProvided:+ if strings.TrimSpace(updated.TokenValue) == "" {+ return fmt.Errorf("tokenName without tokenValue cannot enable token authentication")+ }+ if updated.TokenName != "" && req.TokenName != updated.TokenName {+ return fmt.Errorf("tokenName changes require a new tokenValue")+ }+ updated.TokenName = req.TokenName+ updated.User = ""+ updated.Password = ""+ case req.Password != "":+ if req.User != "" {+ updated.User = normalizePMGUser(req.User)+ }+ updated.Password = req.Password+ updated.TokenName = ""+ updated.TokenValue = ""+ default:+ if req.User != "" && updated.Password != "" && updated.TokenName == "" && updated.TokenValue == "" {+ updated.User = normalizePMGUser(req.User)+ }+ }++ return nil+}+func normalizePBSUser(user string) string {+ user = strings.TrimSpace(user)+ if user == "" || strings.Contains(user, "@") {+ return user+ }+ return user + "@pbs"+}++func normalizePMGUser(user string) string {+ user = strings.TrimSpace(user)+ if user == "" || strings.Contains(user, "@") {+ return user+ }+ return user + "@pmg"+}++// HandleUpdateNode updates an existing nodefunc (h *ConfigHandlers) handleUpdateNode(w http.ResponseWriter, r *http.Request) {// Prevent node modifications in mock modeif mock.IsMockEnabled() {@@ -1115,43 +1267,18 @@ func (h *ConfigHandlers) handleUpdateNode(w http.ResponseWriter, r *http.Requestupdated.Host = host}- // Update GuestURL if provided- updated.GuestURL = req.GuestURL+ if req.hasGuestURLField() {+ updated.GuestURL = req.GuestURL+ }- // Handle authentication updates - only switch auth method if explicitly provided- if req.TokenName != "" || req.TokenValue != "" {- // Switching to or updating token authentication- if req.TokenName != "" {- updated.TokenName = req.TokenName- }- if req.TokenValue != "" {- updated.TokenValue = req.TokenValue- }- // Clear password to avoid conflicts- updated.Password = ""- if req.User != "" {- updated.User = req.User- }- } else if req.Password != "" {- // Explicitly switching to password authentication- if req.User != "" {- updated.User = normalizePVEUser(req.User)- } else if updated.User != "" {- updated.User = normalizePVEUser(updated.User)- }- updated.Password = req.Password- // Clear token fields when switching to password auth- updated.TokenName = ""- updated.TokenValue = ""- } else {- // No authentication changes - preserve existing auth fields- // Only normalize user if it exists- if updated.User != "" {- updated.User = normalizePVEUser(updated.User)- }+ if err := applyPVEAuthUpdate(&updated, req); err != nil {+ http.Error(w, err.Error(), http.StatusBadRequest)+ return}- updated.Fingerprint = req.Fingerprint+ if req.hasFingerprintField() {+ updated.Fingerprint = req.Fingerprint+ }if req.VerifySSL != nil {updated.VerifySSL = *req.VerifySSL}@@ -1200,57 +1327,23 @@ func (h *ConfigHandlers) handleUpdateNode(w http.ResponseWriter, r *http.Requestupdated.Host = host}- // Update GuestURL if provided- updated.GuestURL = req.GuestURL+ if req.hasGuestURLField() {+ updated.GuestURL = req.GuestURL+ }- // Handle authentication updates - only switch auth method if explicitly provided- if req.TokenName != "" && req.TokenValue != "" {- // Switching to token authentication- updated.TokenName = req.TokenName- updated.TokenValue = req.TokenValue- // Clear user/password when switching to token auth- updated.User = ""- updated.Password = ""- } else if req.TokenName != "" {- // Token name provided without new value - keep existing token value- updated.TokenName = req.TokenName- // Clear user/password when using token auth- updated.User = ""- updated.Password = ""- } else if req.Password != "" {- // Switching to password authentication- updated.Password = req.Password- // Ensure user has realm for PBS- pbsUser := req.User- if req.User != "" && !strings.Contains(req.User, "@") {- pbsUser = req.User + "@pbs" // Default to @pbs realm if not specified- }- updated.User = pbsUser- // Clear token fields when switching to password auth- updated.TokenName = ""- updated.TokenValue = ""- } else if req.User != "" {- // User provided - assume password auth but keep existing password- // Ensure user has realm for PBS- pbsUser := req.User- if !strings.Contains(req.User, "@") {- pbsUser = req.User + "@pbs" // Default to @pbs realm if not specified- }- updated.User = pbsUser- // Clear token fields when using password auth- updated.TokenName = ""- updated.TokenValue = ""+ if err := applyPBSAuthUpdate(&updated, req); err != nil {+ http.Error(w, err.Error(), http.StatusBadRequest)+ return}- // else: No authentication changes - preserve existing auth fields- updated.Fingerprint = req.Fingerprint+ if req.hasFingerprintField() {+ updated.Fingerprint = req.Fingerprint+ }if req.VerifySSL != nil {updated.VerifySSL = *req.VerifySSL}if req.MonitorBackups != nil {updated.MonitorBackups = *req.MonitorBackups- } else {- updated.MonitorBackups = true // Enable by default for PBS}if req.MonitorDatastores != nil {updated.MonitorDatastores = *req.MonitorDatastores@@ -1283,7 +1376,9 @@ func (h *ConfigHandlers) handleUpdateNode(w http.ResponseWriter, r *http.RequestpmgInst := &h.getConfig(r.Context()).PMGInstances[index]current := *pmgInstupdated := current- updated.Name = req.Name+ if req.Name != "" {+ updated.Name = req.Name+ }if req.Host != "" {host, err := normalizeNodeHost(req.Host, nodeType)@@ -1294,55 +1389,23 @@ func (h *ConfigHandlers) handleUpdateNode(w http.ResponseWriter, r *http.Requestupdated.Host = host}- // Update GuestURL if provided- updated.GuestURL = req.GuestURL+ if req.hasGuestURLField() {+ updated.GuestURL = req.GuestURL+ }- // Handle authentication updates - only switch auth method if explicitly provided- if req.TokenName != "" && req.TokenValue != "" {- // Switching to token authentication- updated.TokenName = req.TokenName- updated.TokenValue = req.TokenValue- // Clear user/password when switching to token auth- updated.User = ""- updated.Password = ""- } else if req.Password != "" {- // Switching to password authentication- if req.User != "" {- user := req.User- if !strings.Contains(user, "@") {- user = user + "@pmg"- }- updated.User = user- }- updated.Password = req.Password- // Clear token fields when switching to password auth- updated.TokenName = ""- updated.TokenValue = ""- } else if req.User != "" {- // User provided - assume password auth but keep existing password- user := req.User- if !strings.Contains(user, "@") {- user = user + "@pmg"- }- updated.User = user- // Clear token fields when using password auth- updated.TokenName = ""- updated.TokenValue = ""+ if err := applyPMGAuthUpdate(&updated, req); err != nil {+ http.Error(w, err.Error(), http.StatusBadRequest)+ return}- // else: No authentication changes - preserve existing auth fields- updated.Fingerprint = req.Fingerprint+ if req.hasFingerprintField() {+ updated.Fingerprint = req.Fingerprint+ }if req.VerifySSL != nil {updated.VerifySSL = *req.VerifySSL}- // Special logic for MonitorMailStats: default to true if all monitor flags are false/unsetif req.MonitorMailStats != nil {updated.MonitorMailStats = *req.MonitorMailStats- } else if (req.MonitorMailStats == nil || !*req.MonitorMailStats) &&- (req.MonitorQueues == nil || !*req.MonitorQueues) &&- (req.MonitorQuarantine == nil || !*req.MonitorQuarantine) &&- (req.MonitorDomainStats == nil || !*req.MonitorDomainStats) {- updated.MonitorMailStats = true}if req.MonitorQueues != nil {updated.MonitorQueues = *req.MonitorQueuesdiff --git a/internal/api/contract_test.go b/internal/api/contract_test.goindex dde3efbec3..a48c51ef75 100644--- a/internal/api/contract_test.go+++ b/internal/api/contract_test.go@@ -798,6 +798,34 @@ fi`}}+func TestContract_NodeConfigUpdateTracksOptionalConnectionFieldsAndRedactedSecrets(t *testing.T) {+ var preserveReq NodeConfigRequest+ if err := json.Unmarshal([]byte(`{"name":"cluster","tokenName":"pulse-monitor@pve!pulse-pve","tokenValue":"********"}`), &preserveReq); err != nil {+ t.Fatalf("decode preserve request: %v", err)+ }+ preserveReq.normalizeTokenAliases()+ if preserveReq.hasGuestURLField() {+ t.Fatal("omitted guestURL must preserve the stored connection URL")+ }+ if preserveReq.hasFingerprintField() {+ t.Fatal("omitted fingerprint must preserve the stored TLS fingerprint")+ }+ if preserveReq.TokenValue != "" {+ t.Fatalf("redacted token placeholder must not become a stored token secret, got %q", preserveReq.TokenValue)+ }++ var clearReq NodeConfigRequest+ if err := json.Unmarshal([]byte(`{"guestURL":"","fingerprint":""}`), &clearReq); err != nil {+ t.Fatalf("decode clear request: %v", err)+ }+ if !clearReq.hasGuestURLField() {+ t.Fatal("explicit empty guestURL must remain observable so clients can clear it intentionally")+ }+ if !clearReq.hasFingerprintField() {+ t.Fatal("explicit empty fingerprint must remain observable so clients can clear it intentionally")+ }+}+func TestContract_HostedMagicLinkStablePrincipalProof(t *testing.T) {source, err := os.ReadFile(filepath.Clean("magic_link_handlers.go"))if err != nil {diff --git a/scripts/installtests/root_install_sh_test.go b/scripts/installtests/root_install_sh_test.goindex 4793f7d89a..02cd9265fb 100644--- a/scripts/installtests/root_install_sh_test.go+++ b/scripts/installtests/root_install_sh_test.go@@ -924,6 +924,38 @@ func TestRootInstallAutoRegisterPrefersJsonTokenForm(t *testing.T) {}}+func TestRootInstallAutoRegisterRotatesExistingDeterministicToken(t *testing.T) {+ content, err := os.ReadFile(filepath.Join("..", "..", "install.sh"))+ if err != nil {+ t.Fatalf("read root install.sh: %v", err)+ }+ script := string(content)++ required := []string{+ `pve_token_already_exists_error() {`,+ `create_pve_auto_register_token() {`,+ `create_pve_auto_register_token "$token_name" token_output token_status`,+ `pve_token_already_exists_error "$token_output"`,+ `pveum user token remove pulse-monitor@pve "$token_name"`,+ `Existing Proxmox monitoring token '${token_name}' found; rotating it so Pulse receives a fresh secret`,+ }+ for _, needle := range required {+ if !strings.Contains(script, needle) {+ t.Fatalf("install.sh missing deterministic token rotation contract: %s", needle)+ }+ }++ alreadyExistsIdx := strings.Index(script, `pve_token_already_exists_error "$token_output"`)+ removeIdx := strings.Index(script, `pveum user token remove pulse-monitor@pve "$token_name"`)+ retryIdx := strings.LastIndex(script, `create_pve_auto_register_token "$token_name" token_output token_status`)+ if alreadyExistsIdx < 0 || removeIdx < 0 || retryIdx < 0 || !(alreadyExistsIdx < removeIdx && removeIdx < retryIdx) {+ t.Fatalf("expected existing-token detection to remove then retry token creation (exists=%d remove=%d retry=%d)", alreadyExistsIdx, removeIdx, retryIdx)+ }+ if strings.Contains(script, `pveum user token remove pulse-monitor@pve`) && !strings.Contains(script, `pve_token_already_exists_error "$token_output"`) {+ t.Fatalf("token removal must stay gated by an explicit existing-token create error")+ }+}+func TestRootInstallDeployAgentScriptsDeploysSignatureSidecars(t *testing.T) {extractDir := t.TempDir()installDir := t.TempDir()