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 URL admission independent of inherited credentials

pulse-triage[bot]249b8f4e1529
diff --git a/cmd/pulse-agent/main.go b/cmd/pulse-agent/main.go
index 4408a86808..d20f11f60d 100644
--- a/cmd/pulse-agent/main.go
+++ b/cmd/pulse-agent/main.go
@@ -1271,7 +1271,6 @@ func kubernetesReportTargets(cfg Config) []kubernetesagent.TargetConfig {
func loadConfig(args []string, getenv func(string) string) (Config, error) {
// Environment Variables
envURL := strings.TrimSpace(getenv("PULSE_URL"))
- envToken := strings.TrimSpace(getenv("PULSE_TOKEN"))
envInterval := strings.TrimSpace(getenv("PULSE_INTERVAL"))
envHostname := strings.TrimSpace(getenv("PULSE_HOSTNAME"))
envAgentID := strings.TrimSpace(getenv("PULSE_AGENT_ID"))
@@ -1473,7 +1472,7 @@ func loadConfig(args []string, getenv func(string) string) (Config, error) {
if token == "" {
// Resolve token with priority: --token > --token-file > env > state-dir file.
var err error
- token, err = resolveToken(*tokenFlag, *tokenFileFlag, envToken, stateDir)
+ token, err = resolveToken(*tokenFlag, *tokenFileFlag, strings.TrimSpace(getenv("PULSE_TOKEN")), stateDir)
if err != nil {
return Config{}, err
}
diff --git a/cmd/pulse-agent/main_test.go b/cmd/pulse-agent/main_test.go
index 72ae657315..dda877bd69 100644
--- a/cmd/pulse-agent/main_test.go
+++ b/cmd/pulse-agent/main_test.go
@@ -29,6 +29,33 @@ import (
"github.com/rs/zerolog"
)
+func TestLoadConfigURLAdmissionDoesNotReadToken(t *testing.T) {
+ t.Cleanup(func() { securityutil.SetOperatorPlaintextHTTPConsent(false) })
+ for _, dryRun := range []bool{true, false} {
+ reads := 0
+ args := []string{"--url", "https://pulse.example.invalid", "--state-dir", t.TempDir()}
+ if dryRun {
+ args = append(args, "--validate-url")
+ }
+ cfg, err := loadConfig(args, func(key string) string {
+ if key == "PULSE_TOKEN" {
+ reads++
+ return "synthetic-inherited-token"
+ }
+ return ""
+ })
+ if err != nil {
+ t.Fatal(err)
+ }
+ if dryRun && (reads != 0 || cfg.APIToken != "") {
+ t.Fatal("URL-only admission read inherited credentials")
+ }
+ if !dryRun && (reads != 1 || cfg.APIToken != "synthetic-inherited-token") {
+ t.Fatal("ordinary startup lost its inherited-token fallback")
+ }
+ }
+}
+
func TestEnableCommandsHelpUsesPatrolRemediationCopy(t *testing.T) {
source, err := os.ReadFile("main.go")
if err != nil {
diff --git a/scripts/installtests/install_sh_test.go b/scripts/installtests/install_sh_test.go
index 15fff466a7..86f5e2ee09 100644
--- a/scripts/installtests/install_sh_test.go
+++ b/scripts/installtests/install_sh_test.go
@@ -27,6 +27,35 @@ import (
"time"
)
+func TestAgentURLAdmissionRefusesUnsupportedOrUnexecutableValidator(t *testing.T) {
+ if runtime.GOOS == "windows" {
+ t.Skip("Unix installer")
+ }
+ for _, executable := range []bool{true, false} {
+ dir := t.TempDir()
+ path := filepath.Join(dir, "staged-agent")
+ mode := os.FileMode(0600)
+ if executable {
+ mode = 0700
+ }
+ // Old binaries reject an unknown flag; noexec staging cannot run it.
+ if err := os.WriteFile(path, []byte("#!/bin/sh\nexit 2\n"), mode); err != nil {
+ t.Fatal(err)
+ }
+ script := `set -euo pipefail
+OUTPUT_FORMAT=json
+NON_INTERACTIVE=true
+EXIT_PREFLIGHT_FAILED=14
+PULSE_URL=https://pulse.example.invalid
+` + extractInstallShellFunction(t, "fail") + "\n" + extractInstallShellFunction(t, "json_event") + "\n" + extractInstallShellFunction(t, "validate_staged_agent_url") + "\nvalidate_staged_agent_url " + strconv.Quote(path) + "\nprintf 'UNEXPECTED-ADMITTED\\n'\n"
+ output, err := exec.Command("bash", "-c", script).CombinedOutput()
+ var failure *exec.ExitError
+ if !errors.As(err, &failure) || failure.ExitCode() != 14 || strings.Contains(string(output), "UNEXPECTED-ADMITTED") || !strings.Contains(string(output), `"exitCode":14`) {
+ t.Fatalf("unknown/unexecutable validator was not refused: %v\n%s", err, output)
+ }
+ }
+}
+
func TestContainerAgentCompatibilityWrapperDefaultsToUnifiedHostAndDockerMonitoring(t *testing.T) {
wrapperBytes, err := os.ReadFile(repoFile("scripts", "install-container-agent.sh"))
if err != nil {