fix(homelab): cmd_sync missing the geteuid guard every other command has

Every other mutating subcommand (secret, refresh-creds, client add/remove)
already re-execs via sudo only when os.geteuid() != 0. cmd_sync was the
one exception, calling sudo unconditionally — fails with "No such file or
directory: 'sudo'" on minimal root-only images (no sudo binary at all),
hit live running `homelab sync` on strong over root SSH.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-01 14:02:07 +02:00
parent dee08b97a4
commit abb1476fc8

View File

@@ -1031,14 +1031,19 @@ def cmd_refresh_creds(args: argparse.Namespace) -> int:
def cmd_sync(args: argparse.Namespace) -> int: def cmd_sync(args: argparse.Namespace) -> int:
# Unlike every other mutating command here, this one had no os.geteuid()
# guard — always shelled out to sudo. Fails outright with "No such file
# or directory: 'sudo'" on minimal root-only Linux images (no sudo
# binary installed at all) reached via `ssh root@host`, e.g. strong.
needs_sudo = os.geteuid() != 0
if sys.platform == "darwin": if sys.platform == "darwin":
return subprocess.call( cmd = ["launchctl", "kickstart", "-k",
["sudo", "launchctl", "kickstart", "-k", "system/network.hubris.homelab-context-sync"]
"system/network.hubris.homelab-context-sync"] else:
) cmd = ["systemctl", "start", "homelab-context-sync.service"]
return subprocess.call( if needs_sudo:
["sudo", "systemctl", "start", "homelab-context-sync.service"] cmd = ["sudo"] + cmd
) return subprocess.call(cmd)
def cmd_mcp(args: argparse.Namespace) -> int: def cmd_mcp(args: argparse.Namespace) -> int: