Jammy's cloud-init doesn't work on lxd 4.0

Bug #2001737 reported by Wouter van Bommel
18
This bug affects 4 people
Affects Status Importance Assigned to Milestone
cloud-init
Fix Released
High
Chad Smith

Bug Description

When trying to boot a Jammy container on a host that uses lxd/4.0 the cloud-init there fails to work properly.

The result is, that a ssh key for authentication isn't inserted in the host, denying ssh access.

Upgrading to lxd/5.0 does works around this issue, which provides a newer interface, but isn't a solution as lxd/4.0 is an LTS of only a few years old.

For a complete log see: https://pastebin.canonical.com/p/X9GN5GH8wv/

To reproduce, install the lxd 4.0/stable snap on a machine, configure it to inject a ssh key, and try to launch an jammy container there. One won't be able to ssh into the container.

An extensive thread about this can be found at: https://chat.canonical.com/canonical/pl/c1erobjybt8jzbgxguowxrddrc

Revision history for this message
Alberto Contreras (aciba) wrote :

Reproduced with:

```sh
lxc launch ubuntu-daily:focal fvm --vm
lxc shell fvm

snap list lxd
lxd init --minimal
lxc launch ubuntu-daily:jammy j
lxc exec j -- cloud-init status --wait

$ lxc exec j -- grep -i warning /var/log/cloud-init.log
2023-01-10 10:29:12,936 - util.py[WARNING]: Getting data from <class 'cloudinit.sources.DataSourceLXD.DataSourceLXD'> failed
2023-01-10 10:29:14,169 - activators.py[WARNING]: Running ['netplan', 'apply'] resulted in stderr output: Failed to connect system bus: No such file or directory
2023-01-10 10:29:27,476 - cc_final_message.py[WARNING]: Used fallback datasource

$ lxc exec j -- grep -i exception /var/log/cloud-init.log
     raise sources.InvalidMetaDataException(
cloudinit.sources.InvalidMetaDataException: Invalid HTTP response [404] from http://lxd/1.0/devices: 404 page not found
```

Changed in cloud-init:
status: New → Triaged
importance: Undecided → Critical
Changed in cloud-init:
importance: Critical → Undecided
Changed in cloud-init:
status: Triaged → New
Revision history for this message
Alberto Contreras (aciba) wrote (last edit ):

The problem is that cloud-init expects `/1.0/devices` to be available in the lxc instance socket, but this information was introduced in LXD 4.21, see [1].

This issue is present in focal (lxd 4.0/stable) and bionic (lxd 3 deb package).

As a workaround for focal images, one could perform an upgrade to 4.21:

sudo snap refresh --channel=4.21/stable lxd

A solution for cloud-init could be to only fetch /1.0/devices on compatible lxd versions and enable/disable the lxd hotplug feature depending on that.

[1] https://discuss.linuxcontainers.org/t/lxd-4-21-has-been-released/12860

Changed in cloud-init:
status: New → Triaged
importance: Undecided → High
Revision history for this message
Chad Smith (chad.smith) wrote :

cloudinit.sources.InvalidMetaDataException: Invalid HTTP response [404] from http://lxd/1.0/devices: 404 page not found

Cloud-init can better handle this error in the event that the LXD control plane doesn't fully support the devices endpoint.

Expectation is LXD 4.0 will not get this feature backported, and cloud-init has fallback configuration options when devices don't exist.

Changed in cloud-init:
assignee: nobody → Chad Smith (chad.smith)
Revision history for this message
Chad Smith (chad.smith) wrote :

work in progress pull request which will resolve this problem. Needs unit tests and then cloud-init can support jammy launches from LXD 4.0 hosts.
https://github.com/canonical/cloud-init/pull/1948

Changed in cloud-init:
status: Triaged → Won't Fix
status: Won't Fix → In Progress
Chad Smith (chad.smith)
Changed in cloud-init:
status: In Progress → Fix Committed
Revision history for this message
Chad Smith (chad.smith) wrote :

This fix will be in the next SRU release of cloud-init version 23.1 (mid-february). It will be in the next interim upload to Lunar (23.04) as version 22.4.2-0ubuntu3

Revision history for this message
Alberto Contreras (aciba) wrote : Fixed in cloud-init version 23.1.

This bug is believed to be fixed in cloud-init in version 23.1. If this is still a problem for you, please make a comment and set the state back to New

Thank you.

Changed in cloud-init:
status: Fix Committed → Fix Released
Revision history for this message
James Falcon (falcojr) wrote :
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.