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.

Allow insecure dev HTTP agent runtime URLs

rcourtmaneb98c13896ce
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
index 8e539282b3..bde4d5240e 100644
--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
@@ -222,6 +222,7 @@ an add-only capacity posture.
6. Keep legacy Unified Agent compatibility names explicitly secondary when touching shared `internal/api/` runtime helpers: the legacy host-route family and `host-agent:*` scope names may remain as ingress or migration aliases, but they must not retake primary ownership in router state, live runtime scope checks, handler commentary, or operator-facing guidance.
7. Add or change the unified agent CLI entrypoint, version/help exit semantics, or startup argument/error routing through `cmd/pulse-agent/main.go`.
The CLI entrypoint owns propagation of persistence context into runtime-owned helpers. When installer-selected state roots differ from the default, `cmd/pulse-agent/main.go` must pass that exact `StateDir` through both the host-agent runtime and updater startup paths instead of letting one path silently fall back to `/var/lib/pulse-agent`.
+ The same runtime-owned boundary also owns Pulse control-plane URL validation for agent startup, remote config, updater continuity, and command transport. Non-loopback control-plane URLs remain HTTPS/WSS by default, but explicitly insecure agent/dev-runtime flows may use plain HTTP/WS for LAN development control planes; installer-persisted dev URLs must not be accepted by one runtime path and rejected by another.
8. Add or change installer flags, persisted service arguments, or upgrade-safe re-entry behavior through `scripts/install.sh` and `scripts/install.ps1`.
Persistence-sensitive NAS targets must keep one canonical continuity model here: installer-owned bootstraps may use flash-backed or immutable-root launch hooks only as thin trampolines, while the durable wrapper, state, and reboot-surviving binary copy stay in the governed persistent state directory that updater continuity also refreshes.
9. Add or change profile management, the extracted agent profiles runtime owner, the infrastructure source-manager landing, the pure unified-agent inventory/install model, the connections-ledger workspace shell, the unified ConnectionEditor and its per-type credential slots, route model, shared install section owner, the shared direct-node/discovery infrastructure settings owners plus their model, shared frontend install-command assembly, Proxmox setup/install API transport, TrueNAS platform-connection management, VMware platform-connection management, the shared monitored-system admission preview shell for those platform connections, setup-completion install handoff transport, deploy-fallback manual install transport, and fleet-control presentation through `frontend-modern/src/api/agentProfiles.ts`, `frontend-modern/src/api/nodes.ts`, `frontend-modern/src/components/Settings/AgentProfilesPanel.tsx`, `frontend-modern/src/components/Settings/useAgentProfilesPanelState.ts`, `frontend-modern/src/components/Settings/ConnectionsTable.tsx`, `frontend-modern/src/components/Settings/connectionsTableModel.ts`, `frontend-modern/src/components/Settings/useConnectionsLedger.ts`, `frontend-modern/src/components/Settings/useConnectionRowActions.ts`, `frontend-modern/src/components/Settings/ConnectionEditor/ConnectionEditor.tsx`, `frontend-modern/src/components/Settings/ConnectionEditor/AddressProbeStep.tsx`, `frontend-modern/src/components/Settings/ConnectionEditor/useConnectionEditor.ts`, `frontend-modern/src/components/Settings/ConnectionEditor/CredentialSlots/NodeCredentialSlot.tsx`, `frontend-modern/src/components/Settings/ConnectionEditor/CredentialSlots/TrueNASCredentialSlot.tsx`, `frontend-modern/src/components/Settings/ConnectionEditor/CredentialSlots/VMwareCredentialSlot.tsx`, `frontend-modern/src/components/Settings/infrastructureOperationsModel.tsx`, `frontend-modern/src/components/Settings/InfrastructureInstallerSection.tsx`, `frontend-modern/src/components/Settings/InfrastructureWorkspace.tsx`, `frontend-modern/src/components/Settings/InfrastructureSourceManager.tsx`, `frontend-modern/src/components/Settings/infrastructureWorkspaceModel.ts`, `frontend-modern/src/components/Settings/MonitoredSystemAdmissionPreview.tsx`, `frontend-modern/src/components/Settings/platformConnectionsModel.ts`, `frontend-modern/src/components/Settings/useTrueNASSettingsPanelState.ts`, `frontend-modern/src/components/Settings/useVMwareSettingsPanelState.ts`, `frontend-modern/src/components/Settings/proxmoxSettingsModel.ts`, `frontend-modern/src/components/Settings/ConfiguredNodeTables.tsx`, `frontend-modern/src/components/Settings/SettingsSectionNav.tsx`, `frontend-modern/src/components/Settings/infrastructureSettingsModel.ts`, `frontend-modern/src/components/Settings/useInfrastructureConfiguredNodesState.ts`, `frontend-modern/src/components/Settings/useInfrastructureDiscoveryRuntimeState.ts`, `frontend-modern/src/components/Settings/useInfrastructureInstallState.tsx`, `frontend-modern/src/components/Settings/useInfrastructureOperationsState.tsx`, `frontend-modern/src/components/Settings/useInfrastructureSettingsState.ts`, `frontend-modern/src/components/Settings/nodeModalModel.ts`, `frontend-modern/src/components/Settings/useNodeModalState.ts`, `frontend-modern/src/components/SetupWizard/SetupCompletionPanel.tsx`, and `frontend-modern/src/utils/agentInstallCommand.ts`. Phase 9 retired the legacy reporting/inventory surface (InfrastructureOperationsController, InfrastructureInventorySection, InfrastructureActiveRowDetails, InfrastructureIgnoredRowDetails, InfrastructureStopMonitoringDialog, useInfrastructureReportingState) and the per-type shells (PlatformConnectionsWorkspace, ProxmoxSettingsPanel, ProxmoxDirectWorkspace, ProxmoxConfiguredNodesTable, ProxmoxDirectConnectionsCard, ProxmoxDiscoveryResultsCard, ProxmoxDeleteNodeDialog, ProxmoxNodeModalStack, NodeModal shell, TrueNASSettingsPanel, VMwareSettingsPanel, useProxmoxDirectWorkspaceState); lifecycle extensions must route through the unified aggregator ledger, source-manager cards, and ConnectionEditor credential slots rather than reintroducing those retired surfaces.
diff --git a/internal/agentupdate/coverage_test.go b/internal/agentupdate/coverage_test.go
index 6467fc9996..2764a3ae53 100644
--- a/internal/agentupdate/coverage_test.go
+++ b/internal/agentupdate/coverage_test.go
@@ -217,8 +217,8 @@ func TestValidatePulseURL(t *testing.T) {
t.Run("RejectRemoteHTTPInInsecureMode", func(t *testing.T) {
u := newUpdaterForTest("http://pulse.example.com")
u.cfg.InsecureSkipVerify = true
- if err := u.validatePulseURL(); err == nil {
- t.Fatalf("expected remote http URL in insecure mode to be rejected")
+ if err := u.validatePulseURL(); err != nil {
+ t.Fatalf("expected remote http URL in insecure mode to be allowed, got %v", err)
}
})
@@ -229,6 +229,14 @@ func TestValidatePulseURL(t *testing.T) {
}
})
+ t.Run("AllowPrivateNetworkHTTPInInsecureMode", func(t *testing.T) {
+ u := newUpdaterForTest("http://10.0.0.5:7655")
+ u.cfg.InsecureSkipVerify = true
+ if err := u.validatePulseURL(); err != nil {
+ t.Fatalf("expected private-network http URL in insecure mode to be allowed, got %v", err)
+ }
+ })
+
t.Run("RejectUnsupportedScheme", func(t *testing.T) {
u := newUpdaterForTest("ftp://pulse.example.com")
if err := u.validatePulseURL(); err == nil {
diff --git a/internal/agentupdate/update.go b/internal/agentupdate/update.go
index 6b32592fdd..4d0ba5b6a3 100644
--- a/internal/agentupdate/update.go
+++ b/internal/agentupdate/update.go
@@ -620,7 +620,9 @@ func (u *Updater) validatePulseURL() error {
return fmt.Errorf("Pulse URL is empty")
}
- parsed, err := securityutil.NormalizePulseHTTPBaseURL(pulseURL)
+ parsed, err := securityutil.NormalizePulseHTTPBaseURLWithOptions(pulseURL, securityutil.PulseURLValidationOptions{
+ AllowInsecureHTTP: u.cfg.InsecureSkipVerify,
+ })
if err != nil {
return fmt.Errorf("invalid Pulse URL: %w", err)
}
diff --git a/internal/dockeragent/agent.go b/internal/dockeragent/agent.go
index 0eb49f5188..fd06bcc9d4 100644
--- a/internal/dockeragent/agent.go
+++ b/internal/dockeragent/agent.go
@@ -316,7 +316,7 @@ func normalizeTargets(raw []TargetConfig) ([]TargetConfig, error) {
return nil, fmt.Errorf("pulse target %s is missing API token", targetURL)
}
- normalizedURL, err := normalizeTargetURL(targetURL)
+ normalizedURL, err := normalizeTargetURL(targetURL, target.InsecureSkipVerify)
if err != nil {
return nil, fmt.Errorf("invalid pulse target URL %q: %w", targetURL, err)
}
@@ -337,8 +337,10 @@ func normalizeTargets(raw []TargetConfig) ([]TargetConfig, error) {
return normalized, nil
}
-func normalizeTargetURL(raw string) (string, error) {
- parsed, err := securityutil.NormalizePulseHTTPBaseURL(raw)
+func normalizeTargetURL(raw string, allowInsecureHTTP bool) (string, error) {
+ parsed, err := securityutil.NormalizePulseHTTPBaseURLWithOptions(raw, securityutil.PulseURLValidationOptions{
+ AllowInsecureHTTP: allowInsecureHTTP,
+ })
if err != nil {
return "", err
}
diff --git a/internal/dockeragent/agent_internal_test.go b/internal/dockeragent/agent_internal_test.go
index 599af4457b..bbc1a25692 100644
--- a/internal/dockeragent/agent_internal_test.go
+++ b/internal/dockeragent/agent_internal_test.go
@@ -75,7 +75,7 @@ func TestNormalizeTargetsInvalid(t *testing.T) {
}
func TestNormalizeTargetURL(t *testing.T) {
- normalized, err := normalizeTargetURL(" HTTPS://Pulse.EXAMPLE.com:443/api/ ")
+ normalized, err := normalizeTargetURL(" HTTPS://Pulse.EXAMPLE.com:443/api/ ", false)
if err != nil {
t.Fatalf("normalizeTargetURL returned error: %v", err)
}
@@ -84,6 +84,29 @@ func TestNormalizeTargetURL(t *testing.T) {
}
}
+func TestNormalizeTargetURLAllowsInsecureRemoteHTTP(t *testing.T) {
+ normalized, err := normalizeTargetURL(" http://10.0.0.5:7655/api/ ", true)
+ if err != nil {
+ t.Fatalf("normalizeTargetURL returned error: %v", err)
+ }
+ if normalized != "http://10.0.0.5:7655/api" {
+ t.Fatalf("unexpected normalized URL %q", normalized)
+ }
+}
+
+func TestNormalizeTargetsAllowsInsecureRemoteHTTP(t *testing.T) {
+ targets, err := normalizeTargets([]TargetConfig{{URL: "http://10.0.0.5:7655", Token: "token", InsecureSkipVerify: true}})
+ if err != nil {
+ t.Fatalf("unexpected error: %v", err)
+ }
+ if len(targets) != 1 {
+ t.Fatalf("expected 1 target, got %d", len(targets))
+ }
+ if targets[0].URL != "http://10.0.0.5:7655" {
+ t.Fatalf("unexpected target URL %q", targets[0].URL)
+ }
+}
+
func TestNormalizeTargetsRejectsInsecureOrInvalidURLs(t *testing.T) {
tests := []struct {
name string
diff --git a/internal/hostagent/agent.go b/internal/hostagent/agent.go
index fee63fbf87..122e70cf3c 100644
--- a/internal/hostagent/agent.go
+++ b/internal/hostagent/agent.go
@@ -156,7 +156,7 @@ func New(cfg Config) (*Agent, error) {
pulseURL = "http://localhost:7655"
}
var err error
- pulseURL, err = normalizePulseURL(pulseURL)
+ pulseURL, err = normalizePulseURL(pulseURL, cfg.InsecureSkipVerify)
if err != nil {
return nil, fmt.Errorf("invalid pulse URL: %w", err)
}
@@ -852,8 +852,10 @@ func normalisePlatform(platform string) string {
}
}
-func normalizePulseURL(rawURL string) (string, error) {
- parsed, err := securityutil.NormalizePulseHTTPBaseURL(rawURL)
+func normalizePulseURL(rawURL string, allowInsecureHTTP bool) (string, error) {
+ parsed, err := securityutil.NormalizePulseHTTPBaseURLWithOptions(rawURL, securityutil.PulseURLValidationOptions{
+ AllowInsecureHTTP: allowInsecureHTTP,
+ })
if err != nil {
return "", err
}
diff --git a/internal/hostagent/agent_new_test.go b/internal/hostagent/agent_new_test.go
index efb32ef1b8..8bc0c4882e 100644
--- a/internal/hostagent/agent_new_test.go
+++ b/internal/hostagent/agent_new_test.go
@@ -54,6 +54,28 @@ func TestNew_AllowsMissingAPITokenWhenEnrollmentDisabled(t *testing.T) {
}
}
+func TestNew_AllowsInsecureRemoteHTTPPulseURL(t *testing.T) {
+ mc := &mockCollector{
+ hostInfoFn: func(context.Context) (*gohost.InfoStat, error) {
+ return &gohost.InfoStat{Hostname: "host", HostID: "hid", KernelArch: runtime.GOARCH}, nil
+ },
+ }
+
+ agent, err := New(Config{
+ PulseURL: "http://192.168.0.98:7655",
+ APIToken: "token",
+ InsecureSkipVerify: true,
+ LogLevel: zerolog.InfoLevel,
+ Collector: mc,
+ })
+ if err != nil {
+ t.Fatalf("New() error = %v", err)
+ }
+ if agent.trimmedPulseURL != "http://192.168.0.98:7655" {
+ t.Fatalf("trimmedPulseURL = %q", agent.trimmedPulseURL)
+ }
+}
+
func TestNew_RequiresAPITokenWhenEnrollmentEnabled(t *testing.T) {
mc := &mockCollector{
hostInfoFn: func(context.Context) (*gohost.InfoStat, error) {
diff --git a/internal/hostagent/command_client_test.go b/internal/hostagent/command_client_test.go
index 058e316b07..aea95f6d1f 100644
--- a/internal/hostagent/command_client_test.go
+++ b/internal/hostagent/command_client_test.go
@@ -128,6 +128,11 @@ func TestCommandClientBuildWebSocketURL(t *testing.T) {
pulseURL: "ftp://example.invalid",
wantErr: true,
},
+ {
+ name: "insecure remote http becomes ws",
+ pulseURL: "http://10.0.0.5:7655/pulse",
+ want: "ws://10.0.0.5:7655/pulse/api/agent/ws",
+ },
{
name: "missing host returns error",
pulseURL: "/relative/path",
@@ -138,6 +143,9 @@ func TestCommandClientBuildWebSocketURL(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
client := &CommandClient{pulseURL: tt.pulseURL}
+ if tt.name == "insecure remote http becomes ws" {
+ client.insecureSkipVerify = true
+ }
got, err := client.buildWebSocketURL()
if (err != nil) != tt.wantErr {
t.Fatalf("buildWebSocketURL() err = %v, wantErr %v", err, tt.wantErr)
@@ -186,11 +194,19 @@ func TestCommandClientBuildWebSocketOrigin(t *testing.T) {
pulseURL: "/relative/path",
wantErr: true,
},
+ {
+ name: "insecure remote http stays http origin",
+ pulseURL: "http://10.0.0.5:7655/pulse",
+ want: "http://10.0.0.5:7655",
+ },
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
client := &CommandClient{pulseURL: tt.pulseURL}
+ if tt.name == "insecure remote http stays http origin" {
+ client.insecureSkipVerify = true
+ }
got, err := client.buildWebSocketOrigin()
if (err != nil) != tt.wantErr {
t.Fatalf("buildWebSocketOrigin() err = %v, wantErr %v", err, tt.wantErr)
diff --git a/internal/hostagent/commands.go b/internal/hostagent/commands.go
index 59ee4899b0..1427ed1857 100644
--- a/internal/hostagent/commands.go
+++ b/internal/hostagent/commands.go
@@ -360,7 +360,9 @@ func (c *CommandClient) connectAndHandle(ctx context.Context) error {
}
func (c *CommandClient) buildWebSocketURL() (string, error) {
- parsed, err := securityutil.NormalizePulseWebSocketBaseURL(c.pulseURL)
+ parsed, err := securityutil.NormalizePulseWebSocketBaseURLWithOptions(c.pulseURL, securityutil.PulseURLValidationOptions{
+ AllowInsecureHTTP: c.insecureSkipVerify,
+ })
if err != nil {
return "", err
}
@@ -378,7 +380,9 @@ func (c *CommandClient) buildWebSocketURL() (string, error) {
}
func (c *CommandClient) buildWebSocketOrigin() (string, error) {
- return securityutil.HTTPOriginForWebSocketBaseURL(c.pulseURL)
+ return securityutil.HTTPOriginForWebSocketBaseURLWithOptions(c.pulseURL, securityutil.PulseURLValidationOptions{
+ AllowInsecureHTTP: c.insecureSkipVerify,
+ })
}
func (c *CommandClient) sendRegistration(conn *websocket.Conn) error {
diff --git a/internal/hostagent/commands_deploy.go b/internal/hostagent/commands_deploy.go
index 9f2340baca..4e3b1ea47a 100644
--- a/internal/hostagent/commands_deploy.go
+++ b/internal/hostagent/commands_deploy.go
@@ -259,7 +259,7 @@ func (c *CommandClient) preflightTarget(
"preflight_complete", "failed", fmt.Sprintf("Invalid node IP: %s", target.NodeIP), data, false)
return false
}
- normalizedPulseURL, err := normalizePulseURL(pulseURL)
+ normalizedPulseURL, err := normalizePulseURL(pulseURL, c.insecureSkipVerify)
if err != nil {
data := marshalPreflightResult(false, false, false, "", err.Error())
c.sendDeployProgress(conn, requestID, jobID, target.TargetID,
@@ -366,7 +366,7 @@ func (c *CommandClient) installTarget(
"install_complete", "failed", fmt.Sprintf("Invalid node IP: %s", target.NodeIP), data, false)
return false
}
- normalizedPulseURL, err := normalizePulseURL(pulseURL)
+ normalizedPulseURL, err := normalizePulseURL(pulseURL, c.insecureSkipVerify)
if err != nil {
data := marshalInstallResult(-1, err.Error())
c.sendDeployProgress(conn, requestID, jobID, target.TargetID,
@@ -549,7 +549,7 @@ func (c *CommandClient) writeTokenSSH(ctx context.Context, nodeIP, token string)
// runInstallSSH runs the Pulse install script on a remote node via SSH.
func (c *CommandClient) runInstallSSH(ctx context.Context, nodeIP, pulseURL string) (int, string, error) {
- normalizedPulseURL, err := normalizePulseURL(pulseURL)
+ normalizedPulseURL, err := normalizePulseURL(pulseURL, c.insecureSkipVerify)
if err != nil {
return -1, "", err
}
diff --git a/internal/hostagent/commands_deploy_test.go b/internal/hostagent/commands_deploy_test.go
index 41ebec5631..f3c5c27ba8 100644
--- a/internal/hostagent/commands_deploy_test.go
+++ b/internal/hostagent/commands_deploy_test.go
@@ -228,6 +228,35 @@ func TestRunInstallSSH_RejectsNonLoopbackPlainHTTP(t *testing.T) {
}
}
+func TestRunInstallSSH_AllowsNonLoopbackPlainHTTPInInsecureMode(t *testing.T) {
+ origExec := execCommandContext
+ defer func() { execCommandContext = origExec }()
+
+ var capturedArgs []string
+ execCommandContext = func(ctx context.Context, name string, args ...string) *exec.Cmd {
+ capturedArgs = append([]string{name}, args...)
+ return exec.Command("true")
+ }
+
+ c := &CommandClient{
+ insecureSkipVerify: true,
+ logger: zerolog.New(zerolog.NewTestWriter(t)),
+ sshKnownHosts: stubKnownHostsManager{path: "/tmp/pulse-test-known-hosts"},
+ }
+
+ exitCode, _, err := c.runInstallSSH(context.Background(), "10.0.0.1", "http://10.0.0.1:7655")
+ if err != nil {
+ t.Fatalf("runInstallSSH error: %v", err)
+ }
+ if exitCode != 0 {
+ t.Fatalf("expected exit code 0, got %d", exitCode)
+ }
+ joined := strings.Join(capturedArgs, " ")
+ if !strings.Contains(joined, "http://10.0.0.1:7655") || !strings.Contains(joined, "/install.sh") {
+ t.Fatalf("SSH install command missing plain HTTP installer URL: %s", joined)
+ }
+}
+
func TestRunInstallSSH_UsesConfiguredDeploySSHUserWithSudo(t *testing.T) {
origExec := execCommandContext
defer func() { execCommandContext = origExec }()
diff --git a/internal/hostagent/proxmox_setup.go b/internal/hostagent/proxmox_setup.go
index f5c88f3056..62adefc88b 100644
--- a/internal/hostagent/proxmox_setup.go
+++ b/internal/hostagent/proxmox_setup.go
@@ -343,7 +343,7 @@ func NewProxmoxSetup(logger zerolog.Logger, httpClient *http.Client, collector S
// 2. Creates the monitoring user and API token
// 3. Registers the node with Pulse via auto-register
func (p *ProxmoxSetup) Run(ctx context.Context) (*ProxmoxSetupResult, error) {
- pulseURL, err := normalizePulseURL(p.pulseURL)
+ pulseURL, err := normalizePulseURL(p.pulseURL, p.insecureSkipVerify)
if err != nil {
return nil, fmt.Errorf("invalid pulse URL: %w", err)
}
@@ -419,7 +419,7 @@ func (p *ProxmoxSetup) Run(ctx context.Context) (*ProxmoxSetupResult, error) {
// supported configuration). Each type gets its own registration and state tracking.
// Returns results for all types that were processed (skipping already-registered ones).
func (p *ProxmoxSetup) RunAll(ctx context.Context) ([]*ProxmoxSetupResult, error) {
- pulseURL, err := normalizePulseURL(p.pulseURL)
+ pulseURL, err := normalizePulseURL(p.pulseURL, p.insecureSkipVerify)
if err != nil {
return nil, fmt.Errorf("invalid pulse URL: %w", err)
}
@@ -478,7 +478,7 @@ func (p *ProxmoxSetup) RunAll(ctx context.Context) ([]*ProxmoxSetupResult, error
// health-check rotation, which would cause uncontrolled token churn if Pulse
// is temporarily unreachable.
func (p *ProxmoxSetup) RunHealthCheck(ctx context.Context) ([]*ProxmoxSetupResult, error) {
- pulseURL, err := normalizePulseURL(p.pulseURL)
+ pulseURL, err := normalizePulseURL(p.pulseURL, p.insecureSkipVerify)
if err != nil {
return nil, fmt.Errorf("invalid pulse URL: %w", err)
}
diff --git a/internal/hostagent/proxmox_setup_test.go b/internal/hostagent/proxmox_setup_test.go
index c3f61f07e8..1164b48812 100644
--- a/internal/hostagent/proxmox_setup_test.go
+++ b/internal/hostagent/proxmox_setup_test.go
@@ -88,6 +88,16 @@ func TestParseProxmoxProductType(t *testing.T) {
}
}
+func TestProxmoxSetupNormalizePulseURL_AllowsInsecureRemoteHTTP(t *testing.T) {
+ got, err := normalizePulseURL("http://10.0.0.5:7655/pulse/", true)
+ if err != nil {
+ t.Fatalf("normalizePulseURL() error = %v", err)
+ }
+ if got != "http://10.0.0.5:7655/pulse" {
+ t.Fatalf("normalizePulseURL() = %q", got)
+ }
+}
+
func TestRegisterWithPulse_Payload(t *testing.T) {
var gotPayload autoRegisterRequest
var setupTokenHeader string
diff --git a/internal/kubernetesagent/agent.go b/internal/kubernetesagent/agent.go
index f90ff9f063..284207e3b9 100644
--- a/internal/kubernetesagent/agent.go
+++ b/internal/kubernetesagent/agent.go
@@ -136,7 +136,7 @@ func New(cfg Config) (*Agent, error) {
if pulseURL == "" {
pulseURL = "http://localhost:7655"
}
- pulseURL, err := normalizePulseURL(pulseURL)
+ pulseURL, err := normalizePulseURL(pulseURL, cfg.InsecureSkipVerify)
if err != nil {
return nil, fmt.Errorf("invalid pulse URL: %w", err)
}
@@ -222,8 +222,10 @@ func New(cfg Config) (*Agent, error) {
return agent, nil
}
-func normalizePulseURL(rawURL string) (string, error) {
- parsed, err := securityutil.NormalizePulseHTTPBaseURL(rawURL)
+func normalizePulseURL(rawURL string, allowInsecureHTTP bool) (string, error) {
+ parsed, err := securityutil.NormalizePulseHTTPBaseURLWithOptions(rawURL, securityutil.PulseURLValidationOptions{
+ AllowInsecureHTTP: allowInsecureHTTP,
+ })
if err != nil {
return "", err
}
diff --git a/internal/kubernetesagent/agent_new_test.go b/internal/kubernetesagent/agent_new_test.go
index a4c8e1607f..7d79241f49 100644
--- a/internal/kubernetesagent/agent_new_test.go
+++ b/internal/kubernetesagent/agent_new_test.go
@@ -162,7 +162,7 @@ func TestNormalizePulseURL(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
- got, err := normalizePulseURL(tt.raw)
+ got, err := normalizePulseURL(tt.raw, false)
if tt.wantError != "" {
if err == nil {
t.Fatalf("normalizePulseURL(%q) expected error", tt.raw)
@@ -182,6 +182,16 @@ func TestNormalizePulseURL(t *testing.T) {
}
}
+func TestNormalizePulseURLAllowsInsecureRemoteHTTP(t *testing.T) {
+ got, err := normalizePulseURL("http://10.0.0.5:7655/base/", true)
+ if err != nil {
+ t.Fatalf("normalizePulseURL() error = %v", err)
+ }
+ if got != "http://10.0.0.5:7655/base" {
+ t.Fatalf("normalizePulseURL() = %q", got)
+ }
+}
+
func TestNew_InvalidPulseURLFailsFast(t *testing.T) {
_, err := New(Config{
PulseURL: "ftp://pulse.local",
diff --git a/internal/remoteconfig/client.go b/internal/remoteconfig/client.go
index c0c7c5eafb..53413f0e1d 100644
--- a/internal/remoteconfig/client.go
+++ b/internal/remoteconfig/client.go
@@ -362,7 +362,7 @@ func normalizeConfig(cfg Config) (Config, error) {
cfg.AgentID = strings.TrimSpace(cfg.AgentID)
cfg.Hostname = strings.TrimSpace(cfg.Hostname)
- normalizedPulseURL, err := normalizePulseURL(cfg.PulseURL)
+ normalizedPulseURL, err := normalizePulseURL(cfg.PulseURL, cfg.InsecureSkipVerify)
if err != nil {
return cfg, err
}
@@ -371,8 +371,10 @@ func normalizeConfig(cfg Config) (Config, error) {
return cfg, nil
}
-func normalizePulseURL(raw string) (string, error) {
- parsed, err := securityutil.NormalizePulseHTTPBaseURL(raw)
+func normalizePulseURL(raw string, allowInsecureHTTP bool) (string, error) {
+ parsed, err := securityutil.NormalizePulseHTTPBaseURLWithOptions(raw, securityutil.PulseURLValidationOptions{
+ AllowInsecureHTTP: allowInsecureHTTP,
+ })
if err != nil {
return "", fmt.Errorf("invalid pulse URL: %w", err)
}
diff --git a/internal/remoteconfig/client_additional_test.go b/internal/remoteconfig/client_additional_test.go
index 137e6bd28d..49336a7ad8 100644
--- a/internal/remoteconfig/client_additional_test.go
+++ b/internal/remoteconfig/client_additional_test.go
@@ -341,6 +341,16 @@ func TestClientFetchConfigValidation(t *testing.T) {
},
wantText: "must use https unless host is loopback",
},
+ {
+ name: "private-network http allowed in insecure mode",
+ cfg: Config{
+ PulseURL: "http://10.0.0.5:7655",
+ APIToken: "token",
+ AgentID: "agent-1",
+ InsecureSkipVerify: true,
+ },
+ wantText: "do request:",
+ },
{
name: "missing API token",
cfg: Config{
diff --git a/internal/securityutil/httpurl.go b/internal/securityutil/httpurl.go
index eac8143fd1..4630c508b2 100644
--- a/internal/securityutil/httpurl.go
+++ b/internal/securityutil/httpurl.go
@@ -9,6 +9,8 @@ import (
pubsec "github.com/rcourtman/pulse-go-rewrite/pkg/securityutil"
)
+type PulseURLValidationOptions = pubsec.PulseURLValidationOptions
+
func NormalizeAbsoluteHTTPURL(raw string) (*url.URL, error) {
return pubsec.NormalizeAbsoluteHTTPURL(raw)
}
@@ -29,10 +31,18 @@ func NormalizePulseHTTPBaseURL(raw string) (*url.URL, error) {
return pubsec.NormalizePulseHTTPBaseURL(raw)
}
+func NormalizePulseHTTPBaseURLWithOptions(raw string, opts PulseURLValidationOptions) (*url.URL, error) {
+ return pubsec.NormalizePulseHTTPBaseURLWithOptions(raw, opts)
+}
+
func NormalizePulseWebSocketBaseURL(raw string) (*url.URL, error) {
return pubsec.NormalizePulseWebSocketBaseURL(raw)
}
+func NormalizePulseWebSocketBaseURLWithOptions(raw string, opts PulseURLValidationOptions) (*url.URL, error) {
+ return pubsec.NormalizePulseWebSocketBaseURLWithOptions(raw, opts)
+}
+
func AppendURLPath(base *url.URL, segments ...string) *url.URL {
return pubsec.AppendURLPath(base, segments...)
}
diff --git a/internal/securityutil/httpurl_test.go b/internal/securityutil/httpurl_test.go
index c9b6652593..c421fc7384 100644
--- a/internal/securityutil/httpurl_test.go
+++ b/internal/securityutil/httpurl_test.go
@@ -103,6 +103,18 @@ func TestNormalizePulseHTTPBaseURL(t *testing.T) {
}
}
+func TestNormalizePulseHTTPBaseURLWithOptions(t *testing.T) {
+ got, err := NormalizePulseHTTPBaseURLWithOptions("http://10.0.0.5:7655/pulse/", PulseURLValidationOptions{
+ AllowInsecureHTTP: true,
+ })
+ if err != nil {
+ t.Fatalf("NormalizePulseHTTPBaseURLWithOptions() error = %v", err)
+ }
+ if got.String() != "http://10.0.0.5:7655/pulse" {
+ t.Fatalf("NormalizePulseHTTPBaseURLWithOptions() = %q", got.String())
+ }
+}
+
func TestNormalizeSecureHTTPBaseURL(t *testing.T) {
tests := []struct {
name string
@@ -215,6 +227,18 @@ func TestNormalizePulseWebSocketBaseURL(t *testing.T) {
}
}
+func TestNormalizePulseWebSocketBaseURLWithOptions(t *testing.T) {
+ got, err := NormalizePulseWebSocketBaseURLWithOptions("http://10.0.0.5:7655/pulse", PulseURLValidationOptions{
+ AllowInsecureHTTP: true,
+ })
+ if err != nil {
+ t.Fatalf("NormalizePulseWebSocketBaseURLWithOptions() error = %v", err)
+ }
+ if got.String() != "ws://10.0.0.5:7655/pulse" {
+ t.Fatalf("NormalizePulseWebSocketBaseURLWithOptions() = %q", got.String())
+ }
+}
+
func TestSameHostWebSocketOrigin(t *testing.T) {
tests := []struct {
name string
@@ -273,6 +297,18 @@ func TestHTTPOriginForWebSocketBaseURL(t *testing.T) {
}
}
+func TestHTTPOriginForWebSocketBaseURLWithOptions(t *testing.T) {
+ got, err := HTTPOriginForWebSocketBaseURLWithOptions("http://10.0.0.5:7655/pulse", PulseURLValidationOptions{
+ AllowInsecureHTTP: true,
+ })
+ if err != nil {
+ t.Fatalf("HTTPOriginForWebSocketBaseURLWithOptions() error = %v", err)
+ }
+ if got != "http://10.0.0.5:7655" {
+ t.Fatalf("HTTPOriginForWebSocketBaseURLWithOptions() = %q", got)
+ }
+}
+
func TestResolveRelativeURLRejectsAbsoluteURL(t *testing.T) {
base, err := NormalizeHTTPBaseURL("https://example.com/api", "")
if err != nil {
diff --git a/internal/securityutil/websocket_origin.go b/internal/securityutil/websocket_origin.go
index 656d7a2c3b..9a294d2971 100644
--- a/internal/securityutil/websocket_origin.go
+++ b/internal/securityutil/websocket_origin.go
@@ -13,3 +13,7 @@ func SameHostWebSocketOrigin(origin string, requestHost string) bool {
func HTTPOriginForWebSocketBaseURL(raw string) (string, error) {
return pubsec.HTTPOriginForWebSocketBaseURL(raw)
}
+
+func HTTPOriginForWebSocketBaseURLWithOptions(raw string, opts PulseURLValidationOptions) (string, error) {
+ return pubsec.HTTPOriginForWebSocketBaseURLWithOptions(raw, opts)
+}
diff --git a/pkg/securityutil/httpurl.go b/pkg/securityutil/httpurl.go
index ade9cc9ba8..060cb1dcd4 100644
--- a/pkg/securityutil/httpurl.go
+++ b/pkg/securityutil/httpurl.go
@@ -114,10 +114,24 @@ func IsLoopbackHost(host string) bool {
return ip != nil && ip.IsLoopback()
}
+// PulseURLValidationOptions controls optional relaxations for Pulse runtime
+// transports. The default zero value preserves the strict production contract.
+type PulseURLValidationOptions struct {
+ // AllowInsecureHTTP permits plain HTTP/WS to non-loopback hosts. This is
+ // reserved for explicitly insecure agent/dev-runtime flows.
+ AllowInsecureHTTP bool
+}
+
// NormalizePulseHTTPBaseURL validates a Pulse control-plane base URL.
// HTTPS is required for non-loopback hosts; loopback localhost may use HTTP.
func NormalizePulseHTTPBaseURL(raw string) (*url.URL, error) {
- return normalizePulseBaseURL(raw, false)
+ return NormalizePulseHTTPBaseURLWithOptions(raw, PulseURLValidationOptions{})
+}
+
+// NormalizePulseHTTPBaseURLWithOptions validates a Pulse control-plane base URL
+// with explicit runtime validation options.
+func NormalizePulseHTTPBaseURLWithOptions(raw string, opts PulseURLValidationOptions) (*url.URL, error) {
+ return normalizePulseBaseURL(raw, false, opts)
}
// NormalizeSecureHTTPBaseURL validates a general-purpose HTTP(S) base URL.
@@ -152,10 +166,16 @@ func NormalizeSecureHTTPBaseURL(raw string) (*url.URL, error) {
// NormalizePulseWebSocketBaseURL validates a Pulse command-channel base URL.
// Non-loopback hosts are normalized to WSS; loopback localhost may use WS.
func NormalizePulseWebSocketBaseURL(raw string) (*url.URL, error) {
- return normalizePulseBaseURL(raw, true)
+ return NormalizePulseWebSocketBaseURLWithOptions(raw, PulseURLValidationOptions{})
}
-func normalizePulseBaseURL(raw string, websocket bool) (*url.URL, error) {
+// NormalizePulseWebSocketBaseURLWithOptions validates a Pulse command-channel
+// base URL with explicit runtime validation options.
+func NormalizePulseWebSocketBaseURLWithOptions(raw string, opts PulseURLValidationOptions) (*url.URL, error) {
+ return normalizePulseBaseURL(raw, true, opts)
+}
+
+func normalizePulseBaseURL(raw string, websocket bool, opts PulseURLValidationOptions) (*url.URL, error) {
trimmed := strings.TrimSpace(raw)
if trimmed == "" {
return nil, fmt.Errorf("Pulse URL is required")
@@ -196,7 +216,7 @@ func normalizePulseBaseURL(raw string, websocket bool) (*url.URL, error) {
parsed.Scheme = "https"
}
case "http":
- if !IsLoopbackHost(parsed.Hostname()) {
+ if !IsLoopbackHost(parsed.Hostname()) && !opts.AllowInsecureHTTP {
if websocket {
return nil, fmt.Errorf("Pulse URL %q must use https/wss unless host is loopback", raw)
}
@@ -216,7 +236,7 @@ func normalizePulseBaseURL(raw string, websocket bool) (*url.URL, error) {
if !websocket {
return nil, fmt.Errorf("Pulse URL %q has unsupported scheme %q", raw, parsed.Scheme)
}
- if !IsLoopbackHost(parsed.Hostname()) {
+ if !IsLoopbackHost(parsed.Hostname()) && !opts.AllowInsecureHTTP {
return nil, fmt.Errorf("Pulse URL %q must use https/wss unless host is loopback", raw)
}
parsed.Scheme = "ws"
diff --git a/pkg/securityutil/websocket_origin.go b/pkg/securityutil/websocket_origin.go
index b5d9cebcd8..8cff7f0c89 100644
--- a/pkg/securityutil/websocket_origin.go
+++ b/pkg/securityutil/websocket_origin.go
@@ -39,7 +39,13 @@ func SameHostWebSocketOrigin(origin string, requestHost string) bool {
// HTTPOriginForWebSocketBaseURL returns the http(s) Origin header for a Pulse websocket base URL.
func HTTPOriginForWebSocketBaseURL(raw string) (string, error) {
- parsed, err := NormalizePulseWebSocketBaseURL(raw)
+ return HTTPOriginForWebSocketBaseURLWithOptions(raw, PulseURLValidationOptions{})
+}
+
+// HTTPOriginForWebSocketBaseURLWithOptions returns the http(s) Origin header
+// for a Pulse websocket base URL with explicit runtime validation options.
+func HTTPOriginForWebSocketBaseURLWithOptions(raw string, opts PulseURLValidationOptions) (string, error) {
+ parsed, err := NormalizePulseWebSocketBaseURLWithOptions(raw, opts)
if err != nil {
return "", err
}