canonical / cloud-init

Official upstream for the cloud-init: cloud instance initialization

Home Page:https://cloud-init.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cloud config schema errors: config.0.subnets.1: Additional properties are not allowed ('ipv6' was unexpected)

TomEros opened this issue · comments

Hello !

Bug report

Spawning a new Ubuntu 24.04 with Qemu on Openstack and get some warning in the cloud-init log

2024-02-16 16:29:56,175 - schema.py[WARNING]: Invalid network-config provided: Please run 'sudo cloud-init schema --system' to see the schema errors.

# cloud-init schema --system
Found cloud-config data types: user-data, network-config

1. user-data at /var/lib/cloud/instances/0175e4fe-952d-4ee7-adc5-7982d184d0cf/cloud-config.txt:
Empty 'cloud-config' found at /var/lib/cloud/instances/0175e4fe-952d-4ee7-adc5-7982d184d0cf/cloud-config.txt. Nothing to validate.

2. network-config at /var/lib/cloud/instances/0175e4fe-952d-4ee7-adc5-7982d184d0cf/network-config.json:
  Invalid network-config /var/lib/cloud/instances/0175e4fe-952d-4ee7-adc5-7982d184d0cf/network-config.json
  Error: Cloud config schema errors: config.0.subnets.1: Additional properties are not allowed ('ipv6' was unexpected)

Error: Invalid schema: network-config

cat /var/lib/cloud/instances/0175e4fe-952d-4ee7-adc5-7982d184d0cf/network-config.json

{
 "config": [
  {
   "accept-ra": false,
   "mac_address": "fa:16:3e:7f:1a:62",
   "mtu": 1500,
   "name": "ens3",
   "subnets": [
    {
     "type": "dhcp4"
    },
    {
     "address": "x:x:x:x::x",
     "ipv6": true,
     "netmask": "ffff:ffff:ffff:ff00::",
     "routes": [
      {
       "gateway": "x:x:x:x::1",
       "netmask": "::",
       "network": "::"
      }
     ],
     "type": "static6"
    }
   ],
   "type": "physical"
  },
  {
   "address": "1.1.1.1",
   "type": "nameserver"
  }
 ],
 "version": 1
}

I thought this was fixed by #4632

Steps to reproduce the problem

you can spawn a vm on openstack with the image of Ubuntu 24.04
you need to have ipv4 and ipv6

Environment details

  • Cloud-init version: 24.1~5g1f6eddd5-0ubuntu1
  • Operating System Distribution: Ubuntu 24.04 (Noble)
  • Cloud provider, platform or installer type: Openstack

cloud-init logs

cloud-init.log

Cloud-init isn't complaining about the empty user data. It's complaining about the network configuration. It looks like your network configuration contains an invalid key.

ipv6 isn't a key in network config v1

Hello !
i started having a look from where this comes from and it seems that the "network_json" section from instance-data.json is the same for a previous version of cloud-init ( ubuntu 22.04 )

  "network_json": {
   "links": [
    {
     "ethernet_mac_address": "fa:16:3e:7f:1a:62",
     "id": "tap945ebbab-18",
     "mtu": 1500,
     "type": "phy",
     "vif_id": "945ebbab-18b8-4a87-a1c0-068c263cf6e3"
    }
   ],
   "networks": [
    {
     "id": "network0",
     "link": "tap945ebbab-18",
     "network_id": "bcf59eb2-9d83-41cc-b4f5-0435ed594833",
     "type": "ipv4_dhcp"
    },
    {
     "id": "network1",
     "ip_address": "xxxx:xxxx:xxx:xxx::xxxx",
     "link": "tap945ebbab-18",
     "netmask": "ffff:ffff:ffff:ff00::",
     "network_id": "bcf59eb2-9d83-41cc-b4f5-0435ed594833",
     "routes": [
      {
       "gateway": "[2001:41d0:304:300::1](xxxx:xxxx:xxx:xxx::xxxx)",
       "netmask": "::",
       "network": "::"
      }
     ],
     "services": [],
     "type": "ipv6"
    }
   ],
   "services": [
    {
     "address": "1.1.1.1",
     "type": "dns"
    }
   ]
  }

I will try to provide a way to reproduce easily

This network data comes directly from the cloud, which would be your Openstack fabric in this case. It has likely always contained the invalid key. What is new is that cloud-init is now warning when there is invalid data in the network config. Unless I'm missing something, the fix would need to happen within your Openstack.

Hello!
Looks like the non-conforming json is built in the OpenStack helper of cloud-init:

if network["type"] == "ipv4":
subnet["ipv4"] = True
if network["type"] == "ipv6":
subnet["ipv6"] = True

Subnets get the ipv6 key because the network obtained from metadata has it too in its type.

OpenStack indeed returns this on its network_data.json call (conforming to the json schema they document here [1])

curl -s  http://169.254.169.254/openstack/2018-08-27/network_data.json | jq ".networks.[1]"
{
  "id": "network1",
  "type": "ipv6",
  "link": "tapxxxxxx-xx",
  "ip_address": "2001:XXX:XXX:XXX::XXXX",
  "netmask": "ffff:ffff:ffff:ff00::",
  "routes": [
    {
      "network": "::",
      "netmask": "::",
      "gateway": "2001:XXX:XXX:XXX::1"
    }
  ],
  "network_id": "03715c9b-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "services": []
}

It would work if the network type returned by OpenStack was ipv6_dhcp or something, but since "ipv6" looks like a valid network type, shouldn't cloud-init support it too ?

[1] https://docs.openstack.org/nova/latest/_downloads/9119ca7ac90aa2990e762c08baea3a36/network_data.json

@quatre , thanks for the additional context here. This is a bug in cloud-init.

It looks like the lines on 661-664 simply shouldn't exist. They don't get used in the resulting rendered config and so it seems their presence is entirely superfluous.

My last comment was incorrect. I did find a place in the sysconfig renderer where this is used. Fixed via #5191