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.

Reject empty credential-file arguments before installer fallback

pulse-triage[bot]623cdbdc31a7
diff --git a/scripts/install.sh b/scripts/install.sh
index e9697a470f..a3c2449bf7 100755
--- a/scripts/install.sh
+++ b/scripts/install.sh
@@ -6129,7 +6129,9 @@ while [[ $# -gt 0 ]]; do
--enable-action-runner) ACTION_RUNNER_ENABLED="true"; ACTION_RUNNER_EXPLICIT="true"; shift ;;
--disable-action-runner) ACTION_RUNNER_ENABLED="false"; ACTION_RUNNER_EXPLICIT="true"; shift ;;
--uninstall-action-runner) UNINSTALL_ACTION_RUNNER="true"; shift ;;
- --action-token-file) ACTION_TOKEN_FILE_PATH="$2"; shift 2 ;;
+ --action-token-file)
+ [[ $# -ge 2 && -n "$2" ]] || fail "--action-token-file requires a non-empty path" "$EXIT_MISSING_ARGS"
+ ACTION_TOKEN_FILE_PATH="$2"; shift 2 ;;
--grant-smart) GRANT_SMART="true"; shift ;;
--grant-pct) GRANT_PCT="true"; shift ;;
--health-addr) HEALTH_ADDR="$2"; HEALTH_ADDR_SET="true"; shift 2 ;;
@@ -6149,7 +6151,11 @@ while [[ $# -gt 0 ]]; do
--disk-exclude) DISK_EXCLUDES+=("$2"); shift 2 ;;
--disk-include) DISK_INCLUDES+=("$2"); shift 2 ;;
--non-interactive) NON_INTERACTIVE="true"; shift ;;
- --token-file) TOKEN_FILE_PATH="$2"; shift 2 ;;
+ --token-file)
+ # An explicitly selected file must not silently become inline or
+ # saved-credential fallback when its argument is empty.
+ [[ $# -ge 2 && -n "$2" ]] || fail "--token-file requires a non-empty path" "$EXIT_MISSING_ARGS"
+ TOKEN_FILE_PATH="$2"; shift 2 ;;
--pulse-url) PULSE_URL="$2"; shift 2 ;;
--output) OUTPUT_FORMAT="$2"; shift 2 ;;
--preflight-only) PREFLIGHT_ONLY="true"; shift ;;
diff --git a/scripts/tests/test_agent_installer_credential_paths.py b/scripts/tests/test_agent_installer_credential_paths.py
new file mode 100644
index 0000000000..4023d32667
--- /dev/null
+++ b/scripts/tests/test_agent_installer_credential_paths.py
@@ -0,0 +1,135 @@
+#!/usr/bin/env python3
+"""Exercise credential-file argument admission without any install operation."""
+
+import json
+import os
+from pathlib import Path
+import shutil
+import subprocess
+import tempfile
+import unittest
+
+
+ROOT = Path(__file__).resolve().parents[2]
+INSTALLER = ROOT / "scripts/install.sh"
+TOKEN = "synthetic-argument-test-not-a-credential"
+OPTIONS = ("--token-file", "--action-token-file")
+
+
+class AgentInstallerCredentialPathsTest(unittest.TestCase):
+ def setUp(self):
+ self.temporary = tempfile.TemporaryDirectory(prefix="pulse credential paths ")
+ self.addCleanup(self.temporary.cleanup)
+ self.home = Path(self.temporary.name)
+ self.operations = self.home / "unexpected-operation"
+ tools = self.home / "tools"
+ tools.mkdir()
+ # Both real-script refusals and the parser witness must precede these.
+ for name in ("curl", "wget", "sudo", "systemctl", "launchctl", "service"):
+ tool = tools / name
+ tool.write_text('#!/bin/sh\nprintf "%s\\n" "$0" >> "$ARGUMENT_OPERATION_LOG"\nexit 91\n')
+ tool.chmod(0o700)
+ self.env = dict(os.environ, HOME=str(self.home), PULSE_TOKEN=TOKEN,
+ PATH=str(tools) + os.pathsep + os.environ["PATH"],
+ ARGUMENT_OPERATION_LOG=str(self.operations))
+ # Preserve every byte of the actual installer through its parser. End
+ # main there, with an inert witness instead of any lifecycle operation.
+ source = INSTALLER.read_text()
+ prefix, _ = source.split('if [[ "$RETARGET_ONLY" == "true" && -z "$PULSE_URL" ]]; then', 1)
+ self.parser = self.home / "parser.sh"
+ self.parser.write_text(prefix + r'''
+python3 - "$TOKEN_FILE_PATH" "$ACTION_TOKEN_FILE_PATH" "$HEALTH_ADDR" <<'PY'
+import json, sys
+print("PARSER_ACCEPTED=" + json.dumps(sys.argv[1:]))
+PY
+}
+main "$@"
+''')
+
+ def run_script(self, arguments, *, parser=False, output="json"):
+ command = [shutil.which("bash"), str(self.parser if parser else INSTALLER),
+ "--non-interactive", "--output", output, *arguments]
+ result = subprocess.run(command, env=self.env, cwd=self.home,
+ capture_output=True, text=True, timeout=5)
+ self.assertFalse(self.operations.exists(), "argument parsing attempted an install operation")
+ self.assertNotIn(TOKEN, result.stdout + result.stderr, "diagnostic exposed an earlier credential")
+ return result
+
+ def assert_refused(self, result, option, output="json"):
+ self.assertEqual(result.returncode, 16, result.stdout + result.stderr)
+ message = f"{option} requires a non-empty path"
+ self.assertNotIn("PARSER_ACCEPTED=", result.stdout)
+ self.assertNotIn("unbound variable", result.stdout + result.stderr)
+ if output == "json":
+ self.assertEqual(json.loads(result.stdout), {
+ "phase": "error", "code": "install_failed",
+ "message": message, "exitCode": 16,
+ })
+ self.assertEqual(result.stderr, "")
+ else:
+ self.assertIn(message, result.stdout + result.stderr)
+
+ def test_missing_paths_have_real_structured_and_text_refusals(self):
+ for option in OPTIONS:
+ for output in ("json", "text"):
+ with self.subTest(option=option, output=output):
+ self.assert_refused(self.run_script([option], output=output), option, output)
+
+ def test_empty_paths_stop_the_real_script_before_later_validation(self):
+ # The invalid state directory is a second fail-closed fence for the old
+ # script: these controls can never proceed into an actual installation.
+ for option in OPTIONS:
+ with self.subTest(option=option):
+ self.assert_refused(self.run_script([
+ "--token", TOKEN, option, "", "--state-dir", "relative",
+ ]), option)
+
+ def test_empty_paths_cannot_fall_through_to_other_credential_routes(self):
+ for option in OPTIONS:
+ for profile in ([], ["--update"], ["--enable-action-runner"]):
+ for before in ([], ["--token", TOKEN], [option, str(self.home / "prior-file")]):
+ with self.subTest(option=option, profile=profile, before=bool(before)):
+ self.assert_refused(self.run_script([
+ *profile, *before, option, "",
+ ], parser=True), option)
+
+ def test_nonempty_paths_remain_literal_and_caller_owned(self):
+ path = self.home / "private path\nwith 'quotes';$(not-a-command)"
+ path.write_text(TOKEN + "\n")
+ path.chmod(0o600)
+ for option in OPTIONS:
+ for profile in ([], ["--update"], ["--enable-action-runner"]):
+ with self.subTest(option=option, profile=profile):
+ result = self.run_script([*profile, "--token", TOKEN, option, str(path)], parser=True)
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ parsed = json.loads(result.stdout.removeprefix("PARSER_ACCEPTED="))
+ self.assertEqual(parsed[:2], [str(path), ""] if option == "--token-file" else ["", str(path)])
+ self.assertEqual(path.read_text(), TOKEN + "\n")
+ self.assertEqual(path.stat().st_mode & 0o777, 0o600)
+
+ def test_path_validation_stays_with_the_existing_credential_reader(self):
+ # Parsing must not open a path or reinterpret a leading dash. Downstream
+ # private-file validation still owns nonexistent and invalid file types.
+ for option in OPTIONS:
+ for path in (str(self.home / "absent"), "--literal-file-name"):
+ with self.subTest(option=option, path=path):
+ result = self.run_script([option, path], parser=True)
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ self.assertIn(path, json.loads(result.stdout.removeprefix("PARSER_ACCEPTED=")))
+
+ def test_omitted_file_options_preserve_existing_credential_routes(self):
+ for profile in ([], ["--update"], ["--enable-action-runner"]):
+ for credential in ([], ["--token", TOKEN]):
+ with self.subTest(profile=profile, inline=bool(credential)):
+ result = self.run_script([*profile, *credential], parser=True)
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ self.assertEqual(json.loads(result.stdout.removeprefix("PARSER_ACCEPTED="))[:2], ["", ""])
+
+ def test_intentionally_empty_health_address_remains_supported(self):
+ result = self.run_script(["--health-addr", ""], parser=True)
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ self.assertEqual(json.loads(result.stdout.removeprefix("PARSER_ACCEPTED=")), ["", "", ""])
+
+
+if __name__ == "__main__":
+ unittest.main()