canonical / cloud-init

Official upstream for the cloud-init: cloud instance initialization
https://cloud-init.io/
Other
3.01k stars 887 forks source link

net.is_ip_address could not solve ipv6 has URL encode %25 #5893

Open volehuy1998 opened 4 days ago

volehuy1998 commented 4 days ago

Bug report

Cloud-init is not possible with IPv6 because the net.is_ip_address function cannot resolve fe80::a9fe:a9fe%25{iface}, instead of fe80::a9fe:a9fe%{iface}. Leading to the removal of IPv6 from the metadata retrieval list.

# cloudinit/sources/DataSourceOpenStack.py
DEF_MD_URLS = [
            "http://[fe80::a9fe:a9fe%25{iface}]".format(
                iface=self.distro.fallback_interface
            ),
            "http://169.254.169.254",
        ]

# cloudinit/util.py
with suppress(ValueError):
            if net.is_ip_address(parsed_url.netloc.strip("[]")):
                return True

Fix by

# cloudinit/sources/DataSourceOpenStack.py
DEF_MD_URLS = [
            "http://[fe80::a9fe:a9fe%{iface}]".format(
                iface=self.distro.fallback_interface
            ),
            "http://169.254.169.254",
        ]

# cloudinit/util.py
with suppress(ValueError):
            if net.is_ip_address(parsed_url.netloc.strip("[]")):
                return True

Steps to reproduce the problem

$ cloud-init init

Environment details