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.

Let NOPASSWD sudo users run the agent install command

rcourtmandab7582c9519
diff --git a/frontend-modern/browser-verification/dfa48ee9faabee46.json b/frontend-modern/browser-verification/dfa48ee9faabee46.json
new file mode 100644
index 0000000000..111f1bde50
--- /dev/null
+++ b/frontend-modern/browser-verification/dfa48ee9faabee46.json
@@ -0,0 +1,36 @@
+{
+ "version": 1,
+ "base_sha": "a4febe855194305d5616d438b5b8fd379817774e",
+ "verified_at": "2026-10-25T19:40:17Z",
+ "result": "passed",
+ "changed_paths": [
+ "frontend-modern/src/utils/agentInstallCommand.ts"
+ ],
+ "content_sha256": {
+ "frontend-modern/src/utils/agentInstallCommand.ts": "937016008072d8eebcc85894a8259496484cbe001c1071444814686e9190e849"
+ },
+ "routes": [
+ "/settings/infrastructure?add=linux-host"
+ ],
+ "viewports": [
+ {
+ "width": 1280,
+ "height": 800
+ },
+ {
+ "width": 390,
+ "height": 844
+ }
+ ],
+ "states": [
+ "Production vite build of this tree served by vite preview and proxied to the pulse-dev :7699 perf rig (token-required auth); Chromium headless, desktop 1280x800 and touch-phone 390x844.",
+ "Before a token exists the Linux path offers only Generate token. After generation all ten Unix install commands on the page (Linux, private-token-file, macOS and the other Unix families) read 'then if ! sudo -n true 2>/dev/null; then sudo -v; fi;' and none use a bare 'sudo -v'; the two remaining code fragments are the literal word sudo in guidance.",
+ "Token reveal dialog unchanged; after Escape the Install on Linux and private-file commands render in their code blocks with the copy control. No page horizontal overflow and no page errors at either width.",
+ "Shell behaviour on the same Ubuntu 24.04 cloud-init host (NOPASSWD user, no password): the old preflight prints 'sudo: a password is required'; the new one passes without a prompt because the silent 'sudo -n true' succeeds, leaving 'sudo -v' only for hosts that need a password.",
+ "The synthetic install tokens minted on the rig during the runs were revoked afterwards (DELETE 204 each) and the preview server stopped."
+ ],
+ "interactions": [
+ "Sign in, open Settings > Infrastructure, Add infrastructure, Install Pulse Agent.",
+ "Generate token, dismiss the reveal with Escape, scroll to the Install on Linux command and read every visible code block."
+ ]
+}
diff --git a/frontend-modern/src/utils/__tests__/agentInstallCommand.test.ts b/frontend-modern/src/utils/__tests__/agentInstallCommand.test.ts
index 77565c4616..b4e4cd128a 100644
--- a/frontend-modern/src/utils/__tests__/agentInstallCommand.test.ts
+++ b/frontend-modern/src/utils/__tests__/agentInstallCommand.test.ts
@@ -38,6 +38,19 @@ describe('agentInstallCommand', () => {
expect(command).toContain('--insecure');
});
+ // `sudo -v` alone asks NOPASSWD cloud-image users for a password they do
+ // not have whenever another rule (Ubuntu's %sudo) needs one.
+ it('tries a silent sudo before falling back to sudo -v', () => {
+ const command = buildUnixAgentInstallCommand({
+ baseUrl: 'https://pulse.example',
+ token: 'token-123',
+ });
+
+ expect(command).toContain(
+ 'elif command -v sudo >/dev/null 2>&1; then if ! sudo -n true 2>/dev/null; then sudo -v; fi;',
+ );
+ });
+
it('shell-quotes canonical URL and token-file bootstrap transport', () => {
const command = buildUnixAgentInstallCommand({
baseUrl: "https://pulse.example/base path/agent's",
@@ -519,7 +532,7 @@ exec /bin/stty "$@"`,
fake('id', 'if [ "$1" = -u ]; then echo "$FAKE_UID"; else exec /usr/bin/id "$@"; fi');
fake(
'sudo',
- 'printf "%s\\n" "$@" >> "$ARGV"; [ "$FAIL_AT" != sudo ] || exit 1; [ "$1" != -v ] || exit 0; exec "$@"',
+ 'printf "%s\\n" "$@" >> "$ARGV"; [ "$FAIL_AT" != sudo ] || exit 1; [ "$1" != -v ] || exit 0; [ "$*" != "-n true" ] || exit 0; exec "$@"',
);
fake(
'mktemp',
diff --git a/frontend-modern/src/utils/agentInstallCommand.ts b/frontend-modern/src/utils/agentInstallCommand.ts
index c2f9f2bd42..fa4087cb0e 100644
--- a/frontend-modern/src/utils/agentInstallCommand.ts
+++ b/frontend-modern/src/utils/agentInstallCommand.ts
@@ -231,7 +231,11 @@ export const buildUnixAgentInstallCommand = ({
'set +xv;',
'set -eu;',
'umask 077;',
- 'if [ "$(id -u)" -eq 0 ]; then :; elif command -v sudo >/dev/null 2>&1; then sudo -v; else echo "Root privileges required. Run as root (su -) and retry." >&2; exit 1; fi;',
+ // Settle any sudo password before the silent token prompt. Alone,
+ // `sudo -v` demands a password even under NOPASSWD when another sudoers
+ // rule (Ubuntu's %sudo) needs one, and cloud-image users have none; a
+ // silent `sudo -n true` passes there first.
+ 'if [ "$(id -u)" -eq 0 ]; then :; elif command -v sudo >/dev/null 2>&1; then if ! sudo -n true 2>/dev/null; then sudo -v; fi; else echo "Root privileges required. Run as root (su -) and retry." >&2; exit 1; fi;',
'bootstrap_dir=$(mktemp -d /tmp/pulse-bootstrap.XXXXXX);',
'install_script="$bootstrap_dir/install.sh";',
'cleanup() { rm -f -- "$install_script"; rmdir -- "$bootstrap_dir"; };',
diff --git a/internal/api/agent_install_command_shared_test.go b/internal/api/agent_install_command_shared_test.go
index b689ff4111..26e5efb5dd 100644
--- a/internal/api/agent_install_command_shared_test.go
+++ b/internal/api/agent_install_command_shared_test.go
@@ -19,7 +19,9 @@ func requirePrivateBootstrapPrivilegeDispatch(t *testing.T, command string) {
// The shared producer selects its root/sudo argv inside an isolated
// subshell. Duplicating the credential reader into literal root and sudo
// branches would exceed the common pasted-line budget.
- require.Contains(t, command, `elif command -v sudo >/dev/null 2>&1; then sudo -v;`)
+ // `sudo -v` alone refuses NOPASSWD cloud-image users whose %sudo rule
+ // needs a password; a silent `sudo -n true` must be tried first.
+ require.Contains(t, command, `elif command -v sudo >/dev/null 2>&1; then if ! sudo -n true 2>/dev/null; then sudo -v; fi;`)
require.Contains(t, command, `if [ "$(id -u)" -eq 0 ]; then set --; else set -- sudo; fi;`)
require.Contains(t, command, `"$@" bash -c `)
require.Equal(t, 1, strings.Count(command, "bash -c "), "the privileged body must be emitted once")
diff --git a/internal/api/configapi/install_command.go b/internal/api/configapi/install_command.go
index 7ac65f7ebd..8ca37277b6 100644
--- a/internal/api/configapi/install_command.go
+++ b/internal/api/configapi/install_command.go
@@ -110,7 +110,11 @@ func privateBootstrapCommand(scriptURL, curlFlags, preflight, run string, needsT
child := "bash -c " + posixShellQuote(strings.Join(privileged, " ")) + ` pulse-bootstrap "$install_script";`
return strings.Join([]string{
"(", "set +xv;", "set -eu;", "umask 077;",
- `if [ "$(id -u)" -eq 0 ]; then :; elif command -v sudo >/dev/null 2>&1; then sudo -v; else echo "Root privileges required. Run as root (su -) and retry." >&2; exit 1; fi;`,
+ // Settle any sudo password before the silent token prompt. Alone,
+ // `sudo -v` demands a password even under NOPASSWD when another
+ // sudoers rule (Ubuntu's %sudo) needs one, and cloud-image users have
+ // none; a silent `sudo -n true` passes there first.
+ `if [ "$(id -u)" -eq 0 ]; then :; elif command -v sudo >/dev/null 2>&1; then if ! sudo -n true 2>/dev/null; then sudo -v; fi; else echo "Root privileges required. Run as root (su -) and retry." >&2; exit 1; fi;`,
`bootstrap_dir=$(mktemp -d /tmp/pulse-bootstrap.XXXXXX);`,
`install_script="$bootstrap_dir/install.sh";`,
`cleanup() { rm -f -- "$install_script"; rmdir -- "$bootstrap_dir"; };`,
diff --git a/internal/api/configapi/install_command_test.go b/internal/api/configapi/install_command_test.go
index 849ec78e80..203eb7775c 100644
--- a/internal/api/configapi/install_command_test.go
+++ b/internal/api/configapi/install_command_test.go
@@ -175,7 +175,7 @@ exit "${FAKE_CURL_EXIT:-0}"
`)
writeExecutable(t, filepath.Join(bin, "sudo"), `#!/bin/sh
printf '%s\n' "$@" >> "$FAKE_ROOT/argv"
-if [ "$1" = "-v" ]; then exit "${FAKE_SUDO_EXIT:-0}"; fi
+if [ "$1" = "-v" ] || { [ "$#" -eq 2 ] && [ "$1" = "-n" ] && [ "$2" = "true" ]; }; then exit "${FAKE_SUDO_EXIT:-0}"; fi
exec "$@"
`)
writeExecutable(t, filepath.Join(bin, "id"), `#!/bin/sh