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 Docker command recovery after token rotation
rcourtman3a9dffa850af
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.mdindex 0fddbdaa2b..a57cd56799 100644--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md@@ -6059,6 +6059,15 @@ The registration-bound hostname is authoritative and is not rewritten by anequivalent spelling the agent reports, because the still-unconsumed installgrant compares against it.+Command-capable Docker / Podman resources may retain a last-seen telemetry+token after their enrollment token rotates. Action dispatch therefore tries+the report token first, then permits recovery only through one live admission+in the same tenant whose agent ID and canonical hostname both match the+resource. Independent ID-only or hostname-only fallback remains forbidden for+token-named resources, preventing a stale report from crossing identities+while restoring start, stop, restart, and update control for the same agent+(#1728).+A blocked registration is not a silent skip. When the pre-registration checkreports `canRegister=false`, the agent must log at error level, return a setuperror to its caller, and record the operator-facing reason in adiff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.mdindex a572e29451..e265408c1d 100644--- a/docs/release-control/v6/internal/subsystems/api-contracts.md+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md@@ -4216,6 +4216,14 @@ admission decision exactly via the shared binding evaluation in`internal/api/agent_exec_token_binding.go`, so the config payload neveradvertises command execution that admission would reject.+Docker / Podman lifecycle and update actions use the same stale-token model+without weakening dispatch identity. They resolve the report token first; when+that sticky token no longer names a live session, fallback is allowed only when+one tenant-scoped command admission matches both the resource's agent ID and+canonical hostname. A token-named resource never falls back through agent ID+or hostname independently, so token rotation restores control for the same+installed agent without permitting cross-host dispatch (#1728).+### Agent update target responses are reconciliation-safe`GET` and `HEAD /api/agent/version` projectdiff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.mdindex 3c6431d20f..a25c693f59 100644--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md@@ -5354,3 +5354,12 @@ delivery outcomes and the delivery gate state only; they add no storage,backup, snapshot, restore, retention, cleanup, or recovery capability, writenothing, and leave storage and recovery state, evidence freshness,persistence, and admission contracts unchanged.++### Docker command-session identity recovery does not grant storage authority++The shared Docker / Podman action executor may recover from a stale telemetry+token only when one live tenant-scoped command admission matches both the+resource agent ID and canonical hostname. This identity reconciliation changes+neither backup, snapshot, restore, retention, nor recovery authority; those+operations remain governed by their existing resource capabilities and action+lifecycle contracts.diff --git a/internal/agentexec/server.go b/internal/agentexec/server.goindex 4c6e9280c0..ad9e30c520 100644--- a/internal/agentexec/server.go+++ b/internal/agentexec/server.go@@ -2328,6 +2328,29 @@ func (s *Server) GetAgentForTokenForOrganization(organizationID, tokenID string)return "", false}+// GetAgentForIdentityForOrganization resolves a live command session only+// when one tenant-scoped admission matches both the supplied agent ID and the+// canonical hostname. This is the safe recovery path for telemetry whose+// last-seen token ID predates an enrollment-token rotation.+func (s *Server) GetAgentForIdentityForOrganization(organizationID, agentID, hostname string) (string, bool) {+ if s == nil {+ return "", false+ }+ organizationID = normalizeOrganizationID(organizationID)+ agentID = strings.TrimSpace(agentID)+ hostname = strings.TrimSpace(hostname)+ if agentID == "" || hostname == "" {+ return "", false+ }+ ac, ok := s.connectionForOrganization(organizationID, agentID)+ if !ok || normalizeOrganizationID(ac.admission.OrganizationID) != organizationID ||+ strings.TrimSpace(ac.admission.AgentID) != agentID ||+ !unifiedresources.HostnamesEquivalent(ac.admission.Hostname, hostname) {+ return "", false+ }+ return agentID, true+}+// --- Deploy protocol ---// SubscribeDeployProgress registers a channel to receive deploy progressdiff --git a/internal/agentexec/server_test.go b/internal/agentexec/server_test.goindex 83a6d4dfab..1b8382d0dd 100644--- a/internal/agentexec/server_test.go+++ b/internal/agentexec/server_test.go@@ -416,6 +416,31 @@ func TestConnectedAgentLookups(t *testing.T) {}}+func TestGetAgentForIdentityForOrganizationRequiresOneExactLiveAdmission(t *testing.T) {+ s := NewServer(allowAllTestTokens)+ s.mu.Lock()+ s.agents[agentSessionKey("org-a", "a1")] = &agentConn{+ agent: ConnectedAgent{AgentID: "a1", Hostname: "node.example.com"},+ admission: AgentAdmission{OrganizationID: "org-a", TokenID: "rotated-token", AgentID: "a1", Hostname: "node.example.com"},+ }+ s.mu.Unlock()++ if got, ok := s.GetAgentForIdentityForOrganization("org-a", "a1", "NODE"); !ok || got != "a1" {+ t.Fatalf("exact identity lookup = %q, %v; want a1, true", got, ok)+ }+ for _, mismatch := range []struct{ org, agentID, hostname string }{+ {"org-b", "a1", "node"},+ {"org-a", "a2", "node"},+ {"org-a", "a1", "other"},+ {"org-a", "", "node"},+ {"org-a", "a1", ""},+ } {+ if got, ok := s.GetAgentForIdentityForOrganization(mismatch.org, mismatch.agentID, mismatch.hostname); ok {+ t.Fatalf("mismatched identity unexpectedly resolved %q for %#v", got, mismatch)+ }+ }+}+func TestGetAgentForHostNormalizesFQDNAndCase(t *testing.T) {s := NewServer(allowAllTestTokens)now := time.Now().Add(-1 * time.Minute)diff --git a/internal/api/action_executor.go b/internal/api/action_executor.goindex 8bc1020481..88809bc152 100644--- a/internal/api/action_executor.go+++ b/internal/api/action_executor.go@@ -112,6 +112,15 @@ type scopedActionAgentCommander interface {GetAgentForTokenForOrganization(organizationID, tokenID string) (string, bool)}+// scopedActionIdentityAgentCommander resolves a command session only when the+// tenant, agent ID, and hostname all describe the same live admission. It is+// intentionally separate from scopedActionAgentCommander so older action+// commander implementations cannot accidentally approximate this proof with+// independent ID and hostname lookups.+type scopedActionIdentityAgentCommander interface {+ GetAgentForIdentityForOrganization(organizationID, agentID, hostname string) (string, bool)+}+type scopedAgentOperationReceiptCapability interface {AgentOperationReceiptVersionForOrganization(organizationID, agentID string) int}@@ -162,6 +171,18 @@ func commandAgentForToken(ctx context.Context, agents actionAgentCommander, tokereturn "", false}+func commandAgentForIdentity(ctx context.Context, agents actionAgentCommander, agentID, hostname string) (string, bool) {+ agentID = strings.TrimSpace(agentID)+ hostname = strings.TrimSpace(hostname)+ if agentID == "" || hostname == "" {+ return "", false+ }+ if scoped, ok := agents.(scopedActionIdentityAgentCommander); ok {+ return scoped.GetAgentForIdentityForOrganization(GetOrgID(ctx), agentID, hostname)+ }+ return "", false+}+func liveAgentOperationReceiptVersion(ctx context.Context, agents any, agentID string) int {if scoped, ok := agents.(scopedAgentOperationReceiptCapability); ok {return scoped.AgentOperationReceiptVersionForOrganization(GetOrgID(ctx), agentID)diff --git a/internal/api/contract_test.go b/internal/api/contract_test.goindex 8d1ca65d0b..187ca21dcd 100644--- a/internal/api/contract_test.go+++ b/internal/api/contract_test.go@@ -21315,6 +21315,7 @@ func TestContract_DockerLifecycleActionsResolveCommandAgentAndDispatchOneTypedOp"func (e dockerContainerActionExecutor) connectedDockerCommandAgentID(ctx context.Context, resource unified.Resource) (string, error)","resource.Docker.TokenID","commandAgentForToken(ctx, e.agents, resource.Docker.TokenID)",+ "commandAgentForIdentity(ctx, e.agents, resource.Docker.AgentID, resource.Docker.Hostname)","resource.Docker.AgentID","commandAgentForHost(ctx, e.agents, strings.TrimSpace(resource.Docker.Hostname))","ExecuteDockerContainerLifecycle(context.Context, string, agentexec.DockerContainerLifecyclePayload)",@@ -21352,10 +21353,12 @@ func TestContract_DockerLifecycleActionsResolveCommandAgentAndDispatchOneTypedOpt.Fatal("durable reconciliation must not rediscover its executor from current resource inventory")}if strings.Index(src, "commandAgentForToken(ctx, e.agents, resource.Docker.TokenID)") >- strings.Index(src, "if agentID := strings.TrimSpace(resource.Docker.AgentID)") ||+ strings.Index(src, "commandAgentForIdentity(ctx, e.agents, resource.Docker.AgentID, resource.Docker.Hostname)") ||+ strings.Index(src, "commandAgentForIdentity(ctx, e.agents, resource.Docker.AgentID, resource.Docker.Hostname)") >+ strings.Index(src, "if agentID := strings.TrimSpace(resource.Docker.AgentID)") ||strings.Index(src, "if agentID := strings.TrimSpace(resource.Docker.AgentID)") >strings.Index(src, "commandAgentForHost(ctx, e.agents, strings.TrimSpace(resource.Docker.Hostname))") {- t.Fatal("docker lifecycle executor must resolve the immutable reporting token before legacy agent-id and hostname fallbacks")+ t.Fatal("docker lifecycle executor must resolve the reporting token, exact identity, then legacy agent-id and hostname fallbacks")}}diff --git a/internal/api/docker_container_action_executor.go b/internal/api/docker_container_action_executor.goindex 93505ef2ce..8b1750e5d5 100644--- a/internal/api/docker_container_action_executor.go+++ b/internal/api/docker_container_action_executor.go@@ -435,10 +435,15 @@ func (e dockerContainerActionExecutor) connectedDockerCommandAgentID(ctx contextif agentID, ok := commandAgentForToken(ctx, e.agents, resource.Docker.TokenID); ok {return strings.TrimSpace(agentID), nil}- // When telemetry names a token, it is the immutable session binding. Do- // not fall back to a different identity or hostname after rotation.+ // Telemetry retains its last-seen token ID across enrollment-token rotation.+ // A token miss may therefore use the live admission only when its tenant,+ // agent ID, and hostname all match this resource. Never degrade this to an+ // ID-only or hostname-only lookup: either could select a different identity.if tokenID := strings.TrimSpace(resource.Docker.TokenID); tokenID != "" {- return "", fmt.Errorf("docker container command agent is not connected: no live command session for enrollment token %s (agent %q, hostname %q); a token-named resource never falls back to identity or hostname lookup", tokenID, strings.TrimSpace(resource.Docker.AgentID), strings.TrimSpace(resource.Docker.Hostname))+ if agentID, ok := commandAgentForIdentity(ctx, e.agents, resource.Docker.AgentID, resource.Docker.Hostname); ok {+ return strings.TrimSpace(agentID), nil+ }+ return "", fmt.Errorf("docker container command agent is not connected: no live command session matches enrollment token %s or the exact agent %q and hostname %q identity", tokenID, strings.TrimSpace(resource.Docker.AgentID), strings.TrimSpace(resource.Docker.Hostname))}if agentID := strings.TrimSpace(resource.Docker.AgentID); agentID != "" && isAgentCommandConnected(ctx, e.agents, agentID) {return agentID, nildiff --git a/internal/api/docker_container_action_executor_test.go b/internal/api/docker_container_action_executor_test.goindex f63d310723..3b0c018902 100644--- a/internal/api/docker_container_action_executor_test.go+++ b/internal/api/docker_container_action_executor_test.go@@ -53,6 +53,12 @@ func (f *scopedFakeDockerActionAgentCommander) GetAgentForTokenForOrganization(oreturn agentID, ok}+func (f *scopedFakeDockerActionAgentCommander) GetAgentForIdentityForOrganization(organizationID, agentID, hostname string) (string, bool) {+ f.lastOrg = organizationID+ hostAgentID, ok := f.GetAgentForHost(hostname)+ return agentID, ok && hostAgentID == agentID && f.IsAgentConnected(agentID)+}+func dockerActionDispatchContext(t *testing.T, executor dockerContainerActionExecutor, record unified.ActionAuditRecord) context.Context {t.Helper()attempt, err := unified.NewActionDispatchAttempt(record.ID, time.Now())@@ -144,7 +150,7 @@ func dockerActionReadinessByName(readinesses []unified.ResourceActionReadiness,return unified.ResourceActionReadiness{}, false}-func TestDockerCommandSessionResolutionUsesTenantAndImmutableReportToken(t *testing.T) {+func TestDockerCommandSessionResolutionUsesTenantAndRecoversFromStaleReportToken(t *testing.T) {agents := &scopedFakeDockerActionAgentCommander{fakeDockerActionAgentCommander: &fakeDockerActionAgentCommander{connected: map[string]bool{"canonical-agent": true, "stale-agent": true},@@ -169,8 +175,15 @@ func TestDockerCommandSessionResolutionUsesTenantAndImmutableReportToken(t *test}delete(agents.tokenAgents, "fresh-token")+ agents.agentByHost["docker-host"] = "canonical-agent"+ resource.Docker.AgentID = "canonical-agent"+ if agentID, err := executor.connectedDockerCommandAgentID(ctx, resource); err != nil || agentID != "canonical-agent" {+ t.Fatalf("stale token exact-identity fallback = %q, %v; want canonical-agent", agentID, err)+ }++ resource.Docker.AgentID = "stale-agent"if agentID, err := executor.connectedDockerCommandAgentID(ctx, resource); err == nil {- t.Fatalf("stale token unexpectedly fell back to report identity %q", agentID)+ t.Fatalf("stale token unexpectedly crossed report identity to %q", agentID)}}@@ -717,8 +730,8 @@ func TestDockerContainerActionAvailabilityDetailNamesMissedLookup(t *testing.T)t.Fatalf("token-named readiness = %#v, want disconnected agent", readiness)}if !strings.Contains(readiness.Detail, "rotated-token") ||- !strings.Contains(readiness.Detail, "never falls back") {- t.Fatalf("token-named detail = %q, want the stale token binding named", readiness.Detail)+ !strings.Contains(readiness.Detail, `exact agent "agent-1" and hostname "docker-host" identity`) {+ t.Fatalf("token-named detail = %q, want the stale token and failed exact identity proof named", readiness.Detail)}}