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.

Keep CLI API requests within the configured Pulse origin

pulse-triage[bot]47b197a6a2db
diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.md
index a6b5a5ef25..959a2c3584 100644
--- a/docs/release-control/v6/internal/subsystems/api-contracts.md
+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md
@@ -1466,6 +1466,23 @@ show `message`.
## Shared Boundaries
+### CLI API redirects retain their configured authority
+
+The existing authenticated `pulse fleet connections` and `pulse actions`
+commands reuse `agentcapabilities.DoAgentHTTPRequest` for standard HTTP
+clients. A redirect cannot widen the initial request's scheme, hostname,
+effective port or userinfo authority, including for replayable plan, decision
+and execution bodies. Same-origin proxy paths remain usable. The caller's TLS,
+timeout, cookie jar and stricter redirect policy are retained without mutation;
+custom HTTPDoers continue to own their transport policy. Off-origin refusal
+uses the fixed final-base-URL diagnostic, not destination paths or queries.
+
+Registered `api_redirect_test.go` exercises all seven commands across the five
+redirect statuses with default and supplied clients, and same-origin TLS
+reads/writes. `actions_test.go` retains stricter caller refusals and the original
+last-response behaviour. This does not change server-owned approval, execution,
+scopes, grants, API payloads or the rendered web interface.
+
Scheduled reporting owns report generation, persisted attempts and scheduling.
Notifications owns SMTP configuration validation, MIME construction, structured
failure classification and the completed-message acceptance boundary. Report
diff --git a/pkg/pulsecli/actions_test.go b/pkg/pulsecli/actions_test.go
index ffb75455e9..ad650be12e 100644
--- a/pkg/pulsecli/actions_test.go
+++ b/pkg/pulsecli/actions_test.go
@@ -3,10 +3,12 @@ package pulsecli
import (
"bytes"
"encoding/json"
+ "errors"
"io"
"net/http"
"net/http/httptest"
"strings"
+ "sync/atomic"
"testing"
"time"
@@ -14,6 +16,37 @@ import (
"github.com/spf13/cobra"
)
+func TestActionsRedirectPreservesStricterCallerPolicy(t *testing.T) {
+ for _, stop := range []error{errors.New("caller redirect denied"), http.ErrUseLastResponse} {
+ t.Run(stop.Error(), func(t *testing.T) {
+ var requests, callbacks atomic.Int32
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ requests.Add(1)
+ http.Redirect(w, r, "/accepted", http.StatusTemporaryRedirect)
+ }))
+ defer server.Close()
+ client := server.Client()
+ client.CheckRedirect = func(*http.Request, []*http.Request) error {
+ callbacks.Add(1)
+ return stop
+ }
+ _, _, err := executeCLIRedirectCommand(t, cliRedirectCommands()[3], server.URL, client)
+ if err == nil || (stop != http.ErrUseLastResponse && !errors.Is(err, stop)) {
+ t.Fatalf("caller refusal was lost: %v", err)
+ }
+ if stop == http.ErrUseLastResponse && !strings.Contains(err.Error(), "307 Temporary Redirect") {
+ t.Fatalf("last response was not handled as an HTTP refusal: %v", err)
+ }
+ if requests.Load() != 1 || callbacks.Load() != 1 {
+ t.Fatalf("requests=%d callbacks=%d, want one of each", requests.Load(), callbacks.Load())
+ }
+ if client.CheckRedirect(nil, nil) != stop {
+ t.Fatal("caller redirect policy was mutated")
+ }
+ })
+ }
+}
+
func TestActionsPlanCommandPostsCanonicalRequest(t *testing.T) {
plannedAt := time.Date(2026, 5, 3, 10, 0, 0, 0, time.UTC)
var received unified.ActionRequest
diff --git a/pkg/pulsecli/api_client.go b/pkg/pulsecli/api_client.go
index 9805fdd19f..2e4bbe2192 100644
--- a/pkg/pulsecli/api_client.go
+++ b/pkg/pulsecli/api_client.go
@@ -9,6 +9,8 @@ import (
"net/url"
"os"
"strings"
+
+ "github.com/rcourtman/pulse-go-rewrite/internal/agentcapabilities"
)
const (
@@ -22,10 +24,17 @@ type HTTPDoer interface {
}
func cliHTTPClient(client HTTPDoer) HTTPDoer {
- if client != nil {
- return client
- }
- return http.DefaultClient
+ return cliAPIClient{next: client}
+}
+
+type cliAPIClient struct{ next HTTPDoer }
+
+func (c cliAPIClient) Do(req *http.Request) (*http.Response, error) {
+ // Fleet and action commands have the same token/body authority boundary
+ // as MCP. Reuse that guard rather than maintaining a second redirect
+ // policy. Standard clients keep their TLS, timeout and stricter policy;
+ // custom HTTPDoers continue to own their transport/redirect handling.
+ return agentcapabilities.DoAgentHTTPRequest(c.next, req)
}
func cliGetenv(getenv func(string) string, key string) string {