Skip to content

armgit / Pulse

Public Imported from GitHub
0

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.

fix(monitoring): honour removal block on forked re-enroll

pulse-triage[bot]54f0619e5761
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
index 7d4e4819c2..3be657745e 100644
--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
@@ -8090,3 +8090,18 @@ the local image carries more than one valid RepoDigest. The shared resolution
path is covered by `TestAgent_getImageRepoDigests_MultipleDigestsForOneImage`
and `TestRegistryChecker_MultipleLocalRepoDigestsSuppressFalseUpdate`; this is
source-level proof, not installed acceptance.
+
+### Forked re-enrollment consults the base-identity removal block
+
+Host report admission resolves the reporting identity before it consults the
+removal block. When a colliding live record with the same base ID and an older
+token is still present in the unified read model, identity resolution forks the
+report onto a derived `<base>-<hex>` identity. The removal block is keyed on the
+base machine identity, so the derived ID bypassed it and the removed machine
+was silently re-admitted under a new identity; each remove/reinstall cycle added
+another derived record. `ApplyHostReport` now also consults the removal block on
+the base identity when the presenting token had no prior binding, so a fresh
+install token clears the block and heals to the base identity, while a token
+already bound to its own derived identity (an established distinct host sharing
+a hostname or machine ID, #1753) is left untouched. Focused proof lives in
+`internal/monitoring/monitor_host_agents_test.go`.
diff --git a/docs/release-control/v6/internal/subsystems/monitoring.md b/docs/release-control/v6/internal/subsystems/monitoring.md
index 604cc1207f..8fa50f318f 100644
--- a/docs/release-control/v6/internal/subsystems/monitoring.md
+++ b/docs/release-control/v6/internal/subsystems/monitoring.md
@@ -4091,3 +4091,13 @@ reported as outdated. `TestRegistryChecker_MultipleLocalRepoDigestsSuppressFalse
`TestAgent_getImageRepoDigests_MultipleDigestsForOneImage` and the multi-digest
`TestRegistryChecker_DigestsDiffer` cases pin the comparison. This is synthetic
registry-transport evidence, not reporter acceptance.
+
+### Forked host reports cannot bypass a base-identity removal block
+
+Host report admission resolves identity before consulting removal blocks, so a
+report that forked onto a derived `<base>-<hex>` identity could bypass a block
+keyed on the base machine identity and be silently admitted. Monitoring now
+consults the base identity as well when the presenting token had no prior
+binding: a fresh install token clears the block and heals to the base identity,
+and a token already bound to its own derived identity is left alone (#1753).
+Focused proof lives in `internal/monitoring/monitor_host_agents_test.go`.
diff --git a/internal/monitoring/monitor_agents.go b/internal/monitoring/monitor_agents.go
index a8acef02b2..4bfe270a24 100644
--- a/internal/monitoring/monitor_agents.go
+++ b/internal/monitoring/monitor_agents.go
@@ -3083,6 +3083,7 @@ func (m *Monitor) ApplyHostReport(report agentshost.Report, tokenRecord *config.
reportMachineID := strings.TrimSpace(report.Host.MachineID)
identifier := baseIdentifier
+ hadPriorHostBinding := false
if tokenRecord != nil && strings.TrimSpace(tokenRecord.ID) != "" {
tokenID := strings.TrimSpace(tokenRecord.ID)
bindingKey := hostTokenMachineBindingKey(tokenID, hostname, reportMachineID)
@@ -3099,6 +3100,7 @@ func (m *Monitor) ApplyHostReport(report agentshost.Report, tokenRecord *config.
// the unbound path so this machine gets its own identity slot.
boundID = ""
}
+ hadPriorHostBinding = boundID != ""
if boundID != "" {
m.hostTokenBindings[bindingKey] = boundID
}
@@ -3196,6 +3198,22 @@ func (m *Monitor) ApplyHostReport(report agentshost.Report, tokenRecord *config.
tokenID = strings.TrimSpace(tokenRecord.ID)
}
blocked, wasRemoved := m.lookupRemovedHostAgent(identifier, hostname, report.Host.MachineID, tokenID)
+ if !wasRemoved && identifier != baseIdentifier && !hadPriorHostBinding {
+ // Identity resolution can fork a re-enrolling machine onto a derived
+ // suffix before the removal block is consulted: the fork keys off a
+ // colliding live record with the same base ID and an older token, and
+ // the block is keyed on the identity the operator removed (the base
+ // machine identity). Consult the base identity too, so the block is
+ // honoured (rejected, or cleared for a fresh install token) instead of
+ // silently admitting the machine under a derived identity (#2113).
+ //
+ // A token that already had its own binding was forked previously and is
+ // an established distinct host sharing a hostname/machine ID, so the
+ // removed host's block must not capture it (#1753).
+ if baseBlocked, baseRemoved := m.lookupRemovedHostAgent(baseIdentifier, hostname, report.Host.MachineID, tokenID); baseRemoved {
+ blocked, wasRemoved = baseBlocked, true
+ }
+ }
if wasRemoved && removedHostAgentAllowsFreshReenroll(blocked, identifier, report, tokenRecord) {
// A token minted after the host was removed means the user generated a
// fresh install command for this machine: that is explicit re-enroll
diff --git a/internal/monitoring/monitor_host_agents_test.go b/internal/monitoring/monitor_host_agents_test.go
index 97211ac167..05bb0a1e33 100644
--- a/internal/monitoring/monitor_host_agents_test.go
+++ b/internal/monitoring/monitor_host_agents_test.go
@@ -5929,3 +5929,89 @@ func TestDedupeUnifiedMetricWritesDropsExactReplays(t *testing.T) {
t.Fatalf("advanced write count = %d, want 1", len(got))
}
}
+
+// Issue #2113: a removed host agent re-enrolls under a derived suffixed
+// identity because identity resolution forks the machine before the removal
+// block is consulted. The block is keyed on the base machine identity, so the
+// forked ID bypasses it and the machine is silently admitted instead of being
+// rejected or cleared. This reproduces the fork trigger (a live base-identity
+// record still present in the unified read model with an older token) and
+// asserts a fresh install token heals to the base identity.
+func TestApplyHostReportHonoursRemovalBlockWhenIdentityWouldFork(t *testing.T) {
+ now := time.Now().UTC()
+ const (
+ baseID = "bf3f9ff3273346d9944c49160dc57288"
+ hostname = "truenas-iscsi.local"
+ machineID = "bf3f9ff3273346d9944c49160dc57288"
+ )
+
+ live := models.Host{
+ ID: baseID,
+ MachineID: machineID,
+ Hostname: hostname,
+ Platform: "linux",
+ Status: "online",
+ LastSeen: now,
+ IntervalSeconds: 30,
+ TokenID: "token-old",
+ }
+ state := models.NewState()
+ state.Hosts = []models.Host{live}
+
+ registry := unifiedresources.NewRegistry(nil)
+ registry.IngestSnapshot(state.GetSnapshot())
+ adapter := unifiedresources.NewMonitorAdapter(registry)
+
+ monitor := &Monitor{
+ state: state,
+ resourceStore: adapter,
+ alertManager: alerts.NewManager(),
+ hostTokenBindings: map[string]string{"token-old": baseID},
+ removedHostAgents: make(map[string]time.Time),
+ rateTracker: NewRateTracker(),
+ config: &config.Config{},
+ }
+ t.Cleanup(func() { monitor.alertManager.Stop() })
+
+ // The operator removed the host while the live record was still present in
+ // the read model: the tombstone is keyed on the base identity.
+ removedAt := now.Add(-2 * time.Hour)
+ monitor.state.AddRemovedHostAgent(models.RemovedHostAgent{
+ ID: baseID,
+ Hostname: hostname,
+ MachineID: machineID,
+ TokenID: "token-old",
+ RemovedAt: removedAt,
+ })
+ monitor.removedHostAgents[baseID] = removedAt
+
+ report := agentshost.Report{
+ Agent: agentshost.AgentInfo{ID: baseID, Type: "unified", IntervalSeconds: 30},
+ Host: agentshost.HostInfo{
+ ID: baseID,
+ Hostname: hostname,
+ MachineID: machineID,
+ Platform: "linux",
+ },
+ Timestamp: now,
+ }
+ // The fresh token post-dates the removal, but the colliding live record is
+ // still reporting, so the stale-identity reuse path declines and identity
+ // resolution forks.
+ freshToken := &config.APITokenRecord{
+ ID: "token-new",
+ Name: "reinstall",
+ CreatedAt: now.Add(-time.Hour),
+ }
+
+ host, err := monitor.ApplyHostReport(report, freshToken)
+ if err != nil {
+ t.Fatalf("fresh re-enroll should clear the block, got %v", err)
+ }
+ if host.ID != baseID {
+ t.Fatalf("expected re-enroll to heal to base identity %q, got derived %q", baseID, host.ID)
+ }
+ if len(monitor.state.GetRemovedHostAgents()) != 0 {
+ t.Fatalf("expected removal block to be cleared, still have %+v", monitor.state.GetRemovedHostAgents())
+ }
+}