Page MenuHomeVyOS Platform

cloud-init fails to handle "::" as a netmask for routes
Open, WishlistPublicBUG

Description

Hello,

I'm trying to use cloud-init with the OVH Public Cloud (Openstack) but it fails to initialize. I built the image using vyos-build and vyos-vm-images.

This is my network config:

---
version: 1
config:
- type: physical
  mtu: 1500
  accept-ra: false
  subnets:
  - type: dhcp4
  - type: static6
    netmask: 'ffff:ffff:ffff:ff00::'
    routes:
    - network: "::"
      netmask: "::"
      gateway: <SECRET GATEWAY IPV6>
    address: <SECRET IPV6>
    ipv6: true
  mac_address: fa:16:3e:ee:27:8a
  name: eth0
- type: physical
  mtu: 9000
  subnets:
  - type: static
    netmask: 255.255.240.0
    routes:
    - network: 0.0.0.0
      netmask: 0.0.0.0
      gateway: 172.28.0.2
    address: 172.28.0.2
    ipv4: true
  mac_address: fa:16:3e:09:9a:43
  name: eth1
- type: nameserver
  address: 213.186.33.99

Because the netmask is not in CIDR notation, cc_vyos.py fails at ipaddress.ip_network('{}/{}'.format(item['network'], item['netmask'])) (github link) with the error:

2022-10-28 22:09:16,878 - handlers.py[DEBUG]: finish: modules-config/config-vyos: FAIL: running config-vyos with frequency once-per-instance
2022-10-28 22:09:16,878 - util.py[WARNING]: Running module vyos (<module 'cloudinit.config.cc_vyos' from '/usr/lib/python3/dist-packages/cloudinit/config/cc_vyos.py'>) failed
2022-10-28 22:09:16,880 - util.py[DEBUG]: Running module vyos (<module 'cloudinit.config.cc_vyos' from '/usr/lib/python3/dist-packages/cloudinit/config/cc_vyos.py'>) failed
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/cloudinit/stages.py", line 1086, in _run_modules
    ran, _r = cc.run(
  File "/usr/lib/python3/dist-packages/cloudinit/cloud.py", line 55, in run
    return self._runners.run(name, functor, args, freq, clear_on_fail)
  File "/usr/lib/python3/dist-packages/cloudinit/helpers.py", line 185, in run
    results = functor(*args)
  File "/usr/lib/python3/dist-packages/cloudinit/config/cc_vyos.py", line 1089, in handle
    set_config_interfaces_v1(config, interface_config)
  File "/usr/lib/python3/dist-packages/cloudinit/config/cc_vyos.py", line 437, in set_config_interfaces_v1
    _configure_subnets_v1(config, 'ethernet', iface_name, iface_config['subnets'])
  File "/usr/lib/python3/dist-packages/cloudinit/config/cc_vyos.py", line 401, in _configure_subnets_v1
    ip_network = ipaddress.ip_network('{}/{}'.format(
  File "/usr/lib/python3.9/ipaddress.py", line 83, in ip_network
    raise ValueError('%r does not appear to be an IPv4 or IPv6 network' %
ValueError: '::/::' does not appear to be an IPv4 or IPv6 network

This problem has already been seen on the cloud-init repo: github.com/canonical/cloud-init/pull/1215

The solution would be to use the ipv6_mask_to_net_prefix function from the cloudinit.net.network_state package when the mask is an ipv6 address.

To reproduce the bug:

  • Use the function _configure_subnets_v1 with the parameters:
config = {}  # I actually don't know
subnets = [
    {
        "type": "static6",
        "netmask": "ffff:ffff:ffff:ff00::",
        "routes": [
            {
                "network": "::",
                "netmask": "::",
                "gateway": "5c81:e18b:b9b3:5b1f:c79b:7b60:e735:1dde",
            }
        ],
        "address": "fb72:ce1c:9552:90ed:5dfa:01db:fd1b:934e",
        "ipv6": True,
    },
]

type = "ipv6"
iface_name = "eth0"
  • Then call the function:
_configure_subnets_v1(config, type, iface_name, subnets)

This is the cloud-init.log

EDIT: It also seems that ipv6 gateways are not well handled?

Details

Difficulty level
Easy (less than an hour)
Version
1.4-current
Why the issue appeared?
Will be filled on close
Is it a breaking change?
Behavior change
Issue type
Bug (incorrect behavior)