Revert "machines update: support --target-host localhost"

This reverts commit a2818d4946cc66a08b9dd7a1ab95dc48ea708fe3.

Setting `--target-host localhost` breaks with:
sudo: no askpass program specified, try setting SUDO_ASKPASS
This commit is contained in:
DavHau
2025-08-12 17:36:57 +07:00
parent f100177df3
commit 89cb22147c
3 changed files with 22 additions and 15 deletions

View File

@@ -174,7 +174,7 @@
############## ##############
print("TEST: update with --build-host localhost --target-host localhost") print("TEST: update with --build-host local")
with open(machine_config_path, "w") as f: with open(machine_config_path, "w") as f:
f.write(""" f.write("""
{ {
@@ -197,6 +197,15 @@
check=True check=True
) )
# allow machine to ssh into itself
subprocess.run([
"ssh",
"-o", "UserKnownHostsFile=/dev/null",
"-o", "StrictHostKeyChecking=no",
f"root@192.168.1.1",
"mkdir -p /root/.ssh && chmod 700 /root/.ssh && echo \"$(cat \"${../assets/ssh/privkey}\")\" > /root/.ssh/id_ed25519 && chmod 600 /root/.ssh/id_ed25519",
], check=True)
# install the clan-cli package into the container's Nix store # install the clan-cli package into the container's Nix store
subprocess.run( subprocess.run(
[ [
@@ -216,7 +225,7 @@
}, },
) )
# Run ssh on the host to run the clan update command via --build-host localhost # Run ssh on the host to run the clan update command via --build-host local
subprocess.run([ subprocess.run([
"ssh", "ssh",
"-o", "UserKnownHostsFile=/dev/null", "-o", "UserKnownHostsFile=/dev/null",
@@ -230,8 +239,8 @@
"--host-key-check", "none", "--host-key-check", "none",
"--upload-inputs", # Use local store instead of fetching from network "--upload-inputs", # Use local store instead of fetching from network
"--build-host", "localhost", "--build-host", "localhost",
"--target-host", "localhost",
"test-update-machine", "test-update-machine",
"--target-host", f"root@localhost",
], check=True) ], check=True)
# Verify the update was successful # Verify the update was successful

View File

@@ -144,14 +144,10 @@ def update_command(args: argparse.Namespace) -> None:
build_host = machine.build_host() build_host = machine.build_host()
# Figure out the target host # Figure out the target host
if args.target_host: if args.target_host:
target_host: Host | None = None target_host = Remote.from_ssh_uri(
if args.target_host == "localhost": machine_name=machine.name,
target_host = LocalHost() address=args.target_host,
else: ).override(host_key_check=host_key_check)
target_host = Remote.from_ssh_uri(
machine_name=machine.name,
address=args.target_host,
).override(host_key_check=host_key_check)
else: else:
target_host = machine.target_host().override( target_host = machine.target_host().override(
host_key_check=host_key_check host_key_check=host_key_check

View File

@@ -18,7 +18,7 @@ class LocalHost:
command_prefix: str = "localhost" command_prefix: str = "localhost"
_user: str = field(default_factory=lambda: os.environ.get("USER", "root")) _user: str = field(default_factory=lambda: os.environ.get("USER", "root"))
_sudo: bool = False _askpass_path: str | None = None
@property @property
def target(self) -> str: def target(self) -> str:
@@ -52,10 +52,11 @@ class LocalHost:
env.update(extra_env) env.update(extra_env)
# Handle sudo if needed # Handle sudo if needed
if self._sudo: if self._askpass_path is not None:
# Prepend sudo command # Prepend sudo command
sudo_cmd = ["sudo", "-A", "--"] sudo_cmd = ["sudo", "-A", "--"]
cmd = sudo_cmd + cmd cmd = sudo_cmd + cmd
env["SUDO_ASKPASS"] = self._askpass_path
# Set options # Set options
opts.env = env opts.env = env
@@ -84,8 +85,9 @@ class LocalHost:
yield self yield self
return return
# This is a simplified version - could be enhanced with sudo askpass proxy. # For local execution, we can use sudo with askpass if GUI is available
yield LocalHost(_sudo=True) # This is a simplified version - could be enhanced with sudo askpass proxy
yield self
@contextmanager @contextmanager
def host_connection(self) -> Iterator["LocalHost"]: def host_connection(self) -> Iterator["LocalHost"]: