cloud-init icon indicating copy to clipboard operation
cloud-init copied to clipboard

Fix ability to set DNS servers via OpenStack network_data.json

Open jcmoore3 opened this issue 1 year ago • 0 comments

Bug report

When using OpenStack with a network_data.json file which specifies DNS server information, that DNS server information is not parsed by cloud-init. There are two issues within cloud-init causing this:

  1. The cloud-init code parsing the DNS service from network_data.json is looking for the data in an incorrect member of the structure: https://github.com/canonical/cloud-init/blob/fc2134bed02571f68678f0fe0457ef06134c94d9/cloudinit/sources/helpers/openstack.py#L649C1-L653C14
  2. The way in which cloud-init parses the per-interface DNS settings as specified in the route section of an OpenStack network_data.json file attempts to propagate the services member of the structure into the route object of cloud-init's cloud-config.json, which is disallowed by the cloud-init v1 network schema: https://github.com/openstack/ironic/blob/8086167054193c94afef830ef9eccd820dd10a14/ironic/api/controllers/v1/network-data-schema.json#L369C1-L392C7 https://github.com/canonical/cloud-init/blob/fc2134bed02571f68678f0fe0457ef06134c94d9/cloudinit/config/schemas/schema-network-config-v1.json#L451C1-L470C10

To resolve this issue, the cloud-init code should be updated to:

  1. Extract the DNS information from but not propagate the services entry of the routes structure
  2. Properly parse the per-interface DNS information from the config.3.subnets.0.routes.0 structure

Steps to reproduce the problem

Create an OpenStack node with the following network_data.json:

{
  "links": [
    {
      "id": "ens1f0np0",
      "name": "ens1f0np0",
      "type": "phy",
      "ethernet_mac_address": "xx:xx:xx:xx:xx:00",
      "mtu": 9000
    },
    {
      "id": "ens1f1np1",
      "name": "ens1f1np1",
      "type": "phy",
      "ethernet_mac_address": "xx:xx:xx:xx:xx:01",
      "mtu": 9000
    },
    {
      "id": "bond0",
      "name": "bond0",
      "type": "bond",
      "bond_links": [
        "ens1f0np0", "ens1f1np1"
      ],
      "mtu": 9000,
      "ethernet_mac_address": "xx:xx:xx:xx:xx:00",
      "bond_mode": "802.3ad",
      "bond_xmit_hash_policy": "layer3+4",
      "bond_miimon": 100
    },
    {
      "id": "bond0.123",
      "name": "bond0.123",
      "type": "vlan",
      "vlan_link": "bond0",
      "vlan_id": 123,
      "vlan_mac_address": "xx:xx:xx:xx:xx:00"
    }
  ],
  "networks": [
    {
      "id": "publicnet-ipv4",
      "type": "ipv4",
      "link": "bond0.123",
      "ip_address": "x.x.x.x",
      "netmask": "255.255.255.0",
      "routes": [
        {
          "network": "0.0.0.0",
          "netmask": "0.0.0.0",
          "gateway": "x.x.x.1",
          "services": [
              {
              "type": "dns",
              "address": "1.1.1.1"
              },
              {
              "type": "dns",
              "address": "8.8.8.8"
              }
          ]
        }
      ],
      "network_id": "00000000-0000-0000-0000-000000000000"
    }
  ],
  "services": [
  ]
}

Cloud-init will emit an error noting that the services element was unexpected within the routes element:

Cloud-init v. 23.4-7.el9_4.0.1 running 'init-local' at Thu, 06 Jun 2024 20:27:54 +0000. Up 9901.87 seconds.
2024-06-06 20:27:54,805 - schema.py[WARNING]: Invalid network-config provided:
config.3.subnets.0.routes.0: Additional properties are not allowed ('services' was unexpected)

Environment details

  • Cloud-init version: 23.4-7.el9_4.0.1
  • Operating System Distribution: Rocky 9
  • Cloud provider, platform or installer type: OpenStack Caracal 2024.1

cloud-init logs

Cloud-init v. 23.4-7.el9_4.0.1 running 'init-local' at Thu, 06 Jun 2024 20:27:54 +0000. Up 9901.87 seconds.
2024-06-06 20:27:54,805 - schema.py[WARNING]: Invalid network-config provided:
config.3.subnets.0.routes.0: Additional properties are not allowed ('services' was unexpected)

jcmoore3 avatar Jun 06 '24 20:06 jcmoore3