diff --git a/pkgs/clan-cli/clan_cli/ssh/__init__.py b/pkgs/clan-cli/clan_cli/ssh/__init__.py index 27d0a8c47..3ac8ec17b 100644 --- a/pkgs/clan-cli/clan_cli/ssh/__init__.py +++ b/pkgs/clan-cli/clan_cli/ssh/__init__.py @@ -845,6 +845,10 @@ def parse_deployment_address( meta = {} parts = host.split("@") user: str | None = None + # count the number of : in the hostname + if host.count(":") > 1 and not host.startswith("["): + msg = f"Invalid hostname: {host}. IPv6 addresses must be enclosed in brackets , e.g. [::1]" + raise ClanError(msg) if len(parts) > 1: user = parts[0] hostname = parts[1] diff --git a/pkgs/clan-cli/tests/test_ssh_remote.py b/pkgs/clan-cli/tests/test_ssh_remote.py index 04dd2e3fd..3516c1476 100644 --- a/pkgs/clan-cli/tests/test_ssh_remote.py +++ b/pkgs/clan-cli/tests/test_ssh_remote.py @@ -1,5 +1,7 @@ import subprocess +import pytest +from clan_cli.errors import ClanError from clan_cli.ssh import Host, HostGroup, HostKeyCheck, parse_deployment_address @@ -11,6 +13,10 @@ def test_parse_ipv6() -> None: assert host.host == "fe80::1%eth0" assert host.port is None + with pytest.raises(ClanError): + # We instruct the user to use brackets for IPv6 addresses + host = parse_deployment_address("foo", "fe80::1%eth0", HostKeyCheck.STRICT) + def test_run(host_group: HostGroup) -> None: proc = host_group.run("echo hello", stdout=subprocess.PIPE)