canonical / canonical/cloud-init
Device configuration ID is translated into name match rule
- Dominant language
- Python
- Stars
- 3.8k
- Forks
- 1.1k
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 18
Description
# Bug report
We have been adding the following as a file into `/etc/cloud/cloud.cfg.d/`
```
---
network:
version: 2
ethernets:
enp:
match:
driver: mlx5_core
dhcp4: yes
dhcp4-overrides:
use-dns: no
use-mtu: yes
```
The intention of this configuration is to ignore the DNS servers passed by DHCP for all interfaces using the Mellanox "mlx5_core" driver.
However, it seems that `cloud-init` translates this into a `systemd-networkd` file like this:
```
[DHCPv4]
UseDNS=False
UseMTU=True
[Match]
Driver=mlx5_core
Name=enp
[Network]
DHCP=ipv4
```
That is the Device Configuration ID (`enp` in this example) is being added to the [Match] conditions as the name of the interface. I believe this to be unexpected (i.e. undocumented) and undesirable behaviour.
The documentation states that:
> If there are match: rules, then the ID field is a purely opaque name which is only being used for references from definitions of compound devices in the config.
This doesn't seem to be the case, in fact the ID is being used as the literal name of the physical device in the translated match conditions.
Moreover, attempting to force the name in the [Match] condition:
```
---
network:
version: 2
ethernets:
enp:
match:
driver: mlx5_core
name: enp*
dhcp4: yes
dhcp4-overrides:
use-dns: no
use-mtu: yes
```
Doesn't work because the specified name in the `match` dictionary is replaced by the Device Configuration ID.
Another attempt was this:
```
---
network:
version: 2
ethernets:
enp*:
match:
driver: mlx5_core
dhcp4: yes
dhcp4-overrides:
use-dns: no
use-mtu: yes
```
And this results in a `networkd` file that looks promising in that the `[Match]` block contains a name with globbing, but `cloud-init` on Ubuntu 24.04 complains that:
```
# sudo cloud-init schema --system
Found cloud-config data types: user-data, network-config
1. user-data at /var/lib/cloud/instances/6eeae579-e89f-4f21-831c-659eafb6907f/cloud-config.txt:
Valid schema user-data
2. network-config at /var/lib/cloud/instances/6eeae579-e89f-4f21-831c-659eafb6907f/network-config.json:
Invalid network-config /var/lib/cloud/instances/6eeae579-e89f-4f21-831c-659eafb6907f/network-config.json
Error: Cloud config schema errors: format-l4.c9: Invalid netplan schema. Error in network definition: Definition ID 'enp*' must not use globbing
enp*:
```
Whilst `cloud-init` in Ubuntu 22.04 thinks there's no Netplan API.
This behaviour - i.e. the translation of the Device Configuration ID into the [Match] name field - negates the ability to properly use globbing since the only way of forcing the name field in the [Match] block causes an apparent syntax error. Moreover, the documentation isn't clear that both a Driver and Name parameter are needed together. It is therefore reasonable to assume that having only the Driver would be sufficient.
## Steps to reproduce the problem
```
$ cat /etc/cloud/cloud.cfg.d/10-demo.cfg
---
network:
version: 2
ethernets:
enp:
match:
driver: mlx5_core
dhcp4: yes
dhcp4-overrides:
use-dns: no
use-mtu: yes
$ cloud-init clean --logs --reboot
$ cat /etc/systemd/network/10-demo.network
[DHCPv4]
UseDNS=False
UseMTU=True
[Match]
Driver=mlx5_core
Name=enp
[Network]
DHCP=ipv4
```
## Environment details
- Cloud-init version:
```
# cloud-init --version
/usr/bin/cloud-init 25.1.2-0ubuntu0~22.04.2
3 cloud-init --version
/usr/bin/cloud-init 25.1.2-0ubuntu0~24.04.1
```
- Operating System Distribution:
Ubuntu 22.04 and Ubuntu 22.04
- Cloud provider, platform or installer type:
Openstack Caracal
## cloud-init logs
I am unable to provide logs at this time.
Contributor guide
Assessment
This issue has not been assessed yet.