fix buildhost re-using control socket for updates

this is actually a serious issue because it also would result doing ssh
to the wrong host: https://git.clan.lol/clan/clan-core/issues/3822
This commit is contained in:
Jörg Thalheim
2025-06-03 13:48:24 +02:00
parent c4312bfa18
commit 89b436b8a1

View File

@@ -271,13 +271,6 @@ class Remote:
self, self,
control_master: bool = True, control_master: bool = True,
) -> list[str]: ) -> list[str]:
effective_control_path_dir = self._control_path_dir
if self._control_path_dir is None and not control_master:
effective_control_path_dir = None
elif self._control_path_dir is None and control_master:
msg = "Bug! Control path directory is not set. Please use Remote.ssh_control_master() or set control_master to false."
raise ClanError(msg)
ssh_opts = ["-A"] if self.forward_agent else [] ssh_opts = ["-A"] if self.forward_agent else []
if self.port: if self.port:
ssh_opts.extend(["-p", str(self.port)]) ssh_opts.extend(["-p", str(self.port)])
@@ -287,11 +280,21 @@ class Remote:
if self.private_key: if self.private_key:
ssh_opts.extend(["-i", str(self.private_key)]) ssh_opts.extend(["-i", str(self.private_key)])
if effective_control_path_dir: if control_master:
socket_path = effective_control_path_dir / "socket" if self._control_path_dir is None:
ssh_opts.extend(["-o", "ControlPersist=30m"]) msg = "Bug! Control path directory is not set. Please use Remote.ssh_control_master() or set control_master to False."
ssh_opts.extend(["-o", f"ControlPath={socket_path}"]) raise ClanError(msg)
ssh_opts.extend(["-o", "ControlMaster=auto"]) socket_path = self._control_path_dir / "socket"
ssh_opts.extend(
[
"-o",
"ControlMaster=auto",
"-o",
"ControlPersist=30m",
"-o",
f"ControlPath={socket_path}",
]
)
return ssh_opts return ssh_opts
def ssh_cmd( def ssh_cmd(