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 lifecycle command-agent dispatch
rcourtmanccfd6ee7b722
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.mdindex 082071a92f..18ed120d12 100644--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md@@ -234,7 +234,12 @@ Docker / Podman container start, stop, and restart affordances follow that sameboundary: lifecycle UI may consume unified-resource capabilities for enabled ordisabled presentation, but execution must stay inside the API-owned actionexecutor wired from `internal/api/router.go` and must not shell out, SSH, or call-Docker / Podman from lifecycle-local code.+Docker / Podman from lifecycle-local code. That API-owned executor may resolve+the command WebSocket by Docker source ID or canonical Docker host name and may+mark its vetted container lifecycle dispatch as a trusted agent command after+the API action has entered execution; lifecycle surfaces still consume only the+resource payload, action readiness, and action-audit result rather than issuing+or approving command-agent grants themselves.Disconnected command-agent state is also API-owned readiness: lifecyclesurfaces may reflect missing backend-advertised capabilities, but must notreconnect, substitute, or directly address an agent to make a stale containerdiff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.mdindex 43e3805c23..554f6d3c4b 100644--- a/docs/release-control/v6/internal/subsystems/api-contracts.md+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md@@ -1013,6 +1013,14 @@ the canonical monitored-system blocked payload.uses that hook for command-agent connectivity and runtime posture; browsercontrols may consume advertised capabilities, but must not replace thischeck with direct shell, SSH, provider, or agent-command calls.+ Docker / Podman lifecycle execution resolves the command WebSocket by the+ Docker reporting agent ID first, then by canonical Docker host name when the+ runtime source ID differs from the command-agent registration ID. Once+ `/api/actions/{id}/execute` has entered the API-owned execution contract,+ the executor may dispatch the vetted container lifecycle and verification+ commands as trusted agent commands; the host-agent hard-block policy still+ applies, and the action audit remains the approval and lifecycle source of+ truth.Resource payloads may expose the same executor-owned unavailable state as`actionReadiness[]` entries with stable `name`, `available`, `reasonCode`,and `reason` fields so browser and agent clients can explain disableddiff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.mdindex a08fc0677c..a73d80e21a 100644--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md@@ -226,7 +226,12 @@ Docker / Podman start, stop, and restart actions are adjacent runtime actions,not storage or recovery controls: storage/recovery consumers may render theirredacted action history as context, but must not treat container lifecyclecapabilities, `DockerData`, or agent command verification as backup freshness,-restore support, or a recovery-local execution path.+restore support, or a recovery-local execution path. When the API-owned Docker+lifecycle executor resolves a command agent by Docker source ID or canonical+host name and dispatches a trusted internal container command after action+approval, storage and recovery consumers may observe only the resulting action+audit and verification evidence; they must not reinterpret that trusted command+path as recovery authority or a storage-owned action transport.Disconnected command-agent readiness for those lifecycle actions remains anAPI/runtime fail-closed condition; storage/recovery consumers may observe thatan action is unavailable, but must not reinterpret it as recovery degradationdiff --git a/internal/api/contract_test.go b/internal/api/contract_test.goindex 3e98d716c5..0163bfaec4 100644--- a/internal/api/contract_test.go+++ b/internal/api/contract_test.go@@ -15187,6 +15187,29 @@ func TestContract_ResourceActionReadinessPayloadShape(t *testing.T) {}}+func TestContract_DockerLifecycleActionsResolveCommandAgentAndDispatchTrusted(t *testing.T) {+ source, err := os.ReadFile("docker_container_action_executor.go")+ if err != nil {+ t.Fatalf("read docker_container_action_executor.go: %v", err)+ }+ src := string(source)+ for _, snippet := range []string{+ "GetAgentForHost(hostname string) (string, bool)",+ "func (e dockerContainerActionExecutor) connectedDockerCommandAgentID(resource unified.Resource) (string, error)",+ "resource.Docker.AgentID",+ "e.agents.GetAgentForHost(strings.TrimSpace(resource.Docker.Hostname))",+ "Trusted: true",+ } {+ if !strings.Contains(src, snippet) {+ t.Fatalf("docker lifecycle executor must pin command-agent/trusted dispatch snippet %q", snippet)+ }+ }+ if strings.Index(src, "if agentID := strings.TrimSpace(resource.Docker.AgentID)") >+ strings.Index(src, "e.agents.GetAgentForHost(strings.TrimSpace(resource.Docker.Hostname))") {+ t.Fatal("docker lifecycle executor must try the Docker reporting agent id before falling back to hostname resolution")+ }+}+// TestContract_AgentCapabilitiesManifestIsPublic pins the auth// contract for the discovery surface: the manifest must be in the// router's publicPaths list so it serves without a token. Thediff --git a/internal/api/docker_container_action_executor.go b/internal/api/docker_container_action_executor.goindex d34b06c9ec..3afbca2428 100644--- a/internal/api/docker_container_action_executor.go+++ b/internal/api/docker_container_action_executor.go@@ -15,6 +15,7 @@ const dockerContainerLifecycleHandler = "docker.container.lifecycle"type dockerActionAgentCommander interface {ExecuteCommand(ctx context.Context, agentID string, cmd agentexec.ExecuteCommandPayload) (*agentexec.CommandResultPayload, error)+ GetAgentForHost(hostname string) (string, bool)IsAgentConnected(agentID string) bool}@@ -52,12 +53,9 @@ func (e dockerContainerActionExecutor) ExecuteAction(ctx context.Context, recordif containerRef == "" {return nil, fmt.Errorf("docker container resource %q has no executable container id", record.Request.ResourceID)}- agentID := strings.TrimSpace(resource.Docker.AgentID)- if agentID == "" {- return nil, fmt.Errorf("docker container resource %q is not backed by a reporting Pulse agent", record.Request.ResourceID)- }- if !e.agents.IsAgentConnected(agentID) {- return nil, fmt.Errorf("docker container command agent is not connected")+ agentID, err := e.connectedDockerCommandAgentID(resource)+ if err != nil {+ return nil, err}command := fmt.Sprintf("%s %s %s", runtime, operation, shellQuote(containerRef))@@ -67,6 +65,7 @@ func (e dockerContainerActionExecutor) ExecuteAction(ctx context.Context, recordApprovalID: record.ID,TargetType: "agent",Timeout: 120,+ Trusted: true,})if err != nil {return nil, err@@ -104,8 +103,7 @@ func (e dockerContainerActionExecutor) CheckActionAvailable(ctx context.Context,if _, err := e.executableDockerContainerResource(ctx, resource, operation); err != nil {return unavailableDockerActionReadiness(operation, dockerActionUnavailableReasonCode(err), dockerActionUnavailableReason(err))}- agentID := strings.TrimSpace(resource.Docker.AgentID)- if !e.agents.IsAgentConnected(agentID) {+ if _, err := e.connectedDockerCommandAgentID(resource); err != nil {return unavailableDockerActionReadiness(operation, "command_agent_disconnected", "Docker / Podman command agent is not connected.")}return readiness@@ -148,6 +146,25 @@ func (e dockerContainerActionExecutor) executableDockerContainerResource(_ contereturn resource, nil}+func (e dockerContainerActionExecutor) connectedDockerCommandAgentID(resource unified.Resource) (string, error) {+ if e.agents == nil {+ return "", fmt.Errorf("docker container command agent is not connected")+ }+ if resource.Docker == nil {+ return "", fmt.Errorf("docker resource metadata missing")+ }+ if agentID := strings.TrimSpace(resource.Docker.AgentID); agentID != "" && e.agents.IsAgentConnected(agentID) {+ return agentID, nil+ }+ if agentID, ok := e.agents.GetAgentForHost(strings.TrimSpace(resource.Docker.Hostname)); ok {+ agentID = strings.TrimSpace(agentID)+ if agentID != "" && e.agents.IsAgentConnected(agentID) {+ return agentID, nil+ }+ }+ return "", fmt.Errorf("docker container command agent is not connected")+}+func unavailableDockerActionReadiness(operation, reasonCode, reason string) unified.ResourceActionReadiness {return unified.ResourceActionReadiness{Name: strings.TrimSpace(operation),@@ -251,6 +268,7 @@ func (e dockerContainerActionExecutor) verifyContainerState(ctx context.Context,ApprovalID: actionID,TargetType: "agent",Timeout: 30,+ Trusted: true,})if err != nil {return &unified.ActionVerificationResult{Ran: false}diff --git a/internal/api/docker_container_action_executor_test.go b/internal/api/docker_container_action_executor_test.goindex 1d822795ce..f09b93b1ce 100644--- a/internal/api/docker_container_action_executor_test.go+++ b/internal/api/docker_container_action_executor_test.go@@ -18,12 +18,15 @@ import ()type fakeDockerActionAgentCommander struct {- results []*agentexec.CommandResultPayload- calls []agentexec.ExecuteCommandPayload- connected map[string]bool+ results []*agentexec.CommandResultPayload+ calls []agentexec.ExecuteCommandPayload+ callAgents []string+ connected map[string]bool+ agentByHost map[string]string}-func (f *fakeDockerActionAgentCommander) ExecuteCommand(_ context.Context, _ string, cmd agentexec.ExecuteCommandPayload) (*agentexec.CommandResultPayload, error) {+func (f *fakeDockerActionAgentCommander) ExecuteCommand(_ context.Context, agentID string, cmd agentexec.ExecuteCommandPayload) (*agentexec.CommandResultPayload, error) {+ f.callAgents = append(f.callAgents, agentID)f.calls = append(f.calls, cmd)if len(f.results) == 0 {return &agentexec.CommandResultPayload{RequestID: cmd.RequestID, Success: true, ExitCode: 0}, nil@@ -33,6 +36,14 @@ func (f *fakeDockerActionAgentCommander) ExecuteCommand(_ context.Context, _ strreturn result, nil}+func (f *fakeDockerActionAgentCommander) GetAgentForHost(hostname string) (string, bool) {+ if f.agentByHost == nil {+ return "", false+ }+ agentID, ok := f.agentByHost[strings.TrimSpace(hostname)]+ return agentID, ok+}+func (f *fakeDockerActionAgentCommander) IsAgentConnected(agentID string) bool {if f.connected == nil {return true@@ -85,12 +96,66 @@ func TestDockerContainerActionExecutorDispatchesPodmanRestartAndVerification(t *if got := agents.calls[0].Command; got != "podman restart 'container-123'" {t.Fatalf("dispatch command = %q", got)}- if agents.calls[0].ApprovalID != "act_container" || agents.calls[0].Trusted {+ if agents.calls[0].ApprovalID != "act_container" || !agents.calls[0].Trusted {t.Fatalf("dispatch approval/trust = %q/%v", agents.calls[0].ApprovalID, agents.calls[0].Trusted)}if got := agents.calls[1].Command; got != "podman inspect -f '{{.State.Status}} {{.State.Running}}' 'container-123'" {t.Fatalf("verification command = %q", got)}+ if !agents.calls[1].Trusted {+ t.Fatalf("verification command should be trusted")+ }+}++func TestDockerContainerActionExecutorResolvesCommandAgentByDockerHostname(t *testing.T) {+ now := time.Now().UTC()+ resource := dockerContainerActionResource("app-container:api", "docker", "running", now)+ resource.Docker.AgentID = "docker-source-1"+ resource.Docker.Hostname = "tower"+ h := NewResourceHandlers(&config.Config{DataPath: t.TempDir()})+ h.SetStateProvider(resourceUnifiedSeedProvider{+ snapshot: models.StateSnapshot{LastUpdate: now},+ resources: []unified.Resource{resource},+ })+ agents := &fakeDockerActionAgentCommander{+ results: []*agentexec.CommandResultPayload{+ {RequestID: "act_container", Success: true, ExitCode: 0, Stdout: "api restarted"},+ {RequestID: "act_container-verify", Success: true, ExitCode: 0, Stdout: "running true"},+ },+ connected: map[string]bool{+ "docker-source-1": false,+ "command-agent-1": true,+ },+ agentByHost: map[string]string{"tower": "command-agent-1"},+ }+ executor := newDockerContainerActionExecutor(h, agents).(dockerContainerActionExecutor)++ readiness := executor.CheckActionAvailable(context.Background(), unified.ActionRequest{+ RequestID: "req-availability",+ ResourceID: "app-container:api",+ CapabilityName: "restart",+ Reason: "operator requested restart",+ RequestedBy: "operator",+ }, resource)+ if !readiness.Available {+ t.Fatalf("CheckActionAvailable readiness = %#v, want available through hostname-resolved command agent", readiness)+ }++ result, err := executor.ExecuteAction(context.Background(), dockerContainerActionRecord("act_container", "app-container:api", "restart"))+ if err != nil {+ t.Fatalf("ExecuteAction: %v", err)+ }+ if result == nil || !result.Success {+ t.Fatalf("result = %#v, want successful execution", result)+ }+ if len(agents.callAgents) != 2 {+ t.Fatalf("call agents = %#v, want dispatch and verification through hostname-resolved agent", agents.callAgents)+ }+ for _, agentID := range agents.callAgents {+ if agentID != "command-agent-1" {+ t.Fatalf("called agent %q, want command-agent-1; all calls %#v", agentID, agents.callAgents)+ }+ }}func TestDockerContainerActionExecutorFailsWhenCapabilityNoLongerAdvertised(t *testing.T) {