canonical / canonical/cloud-init

DataSourceEc2: all-zero /sys/hypervisor/uuid on Xen dom0 breaks AWS detection and IMDSv2

Open
#6,937 0 comments 0 reactions 0 assignees View on GitHub
bug new
Dominant language
Python
Stars
3.8k
Forks
1.1k
Avg merge
2d 23h
Merged PRs (30d)
18

Description

# Bug report
On a Xen dom0 host, `/sys/hypervisor/uuid` reads all zeros.
`_collect_platform_data()` prefers that file over DMI, all zeros is truthy,
so the DMI fallback never runs and AWS is not identified
([DataSourceEc2.py lines 878-882 at aad14e5d](https://github.com/canonical/cloud-init/blob/aad14e5d8f0343dd39e434715692f2e2a6f4cf9f/cloudinit/sources/DataSourceEc2.py#L878-L882)):

```python
uuid = None
with suppress(OSError, UnicodeDecodeError):
uuid = util.load_text_file("/sys/hypervisor/uuid").strip()

uuid = uuid or dmi.read_dmi_data("system-uuid") or ""
```

```
$ cat /sys/hypervisor/uuid
00000000-0000-0000-0000-000000000000
$ cat /sys/class/dmi/id/product_uuid
ec2... (the DMI fallback would have identified AWS)
```

`_maybe_fetch_api_token()` then returns early
([lines 301-310](https://github.com/canonical/cloud-init/blob/aad14e5d8f0343dd39e434715692f2e2a6f4cf9f/cloudinit/sources/DataSourceEc2.py#L301-L310)),
so no IMDSv2 token is requested; with `HttpTokens=required` the tokenless
IMDSv1 requests fail for the full 240 s wait and the datasource gives up.

## Steps to reproduce the problem
1. Launch a stock Ubuntu 24.04 EC2 instance with
`--metadata-options HttpTokens=required`.
2. Install Xen (dom0 is PV, so no nested virtualization is needed), make it
the grub default, reboot:

```
sudo apt-get update && sudo apt-get install -y xen-system-amd64
echo 'GRUB_DEFAULT="Ubuntu GNU/Linux, with Xen hypervisor"' | sudo tee /etc/default/grub.d/xen.cfg
sudo update-grub && sudo reboot
```

3. On the Xen boot, cloud-init retries the tokenless IMDSv1 path for 240 s,
then falls back to DataSourceNone, regenerating the hostname and SSH
host keys.

## Environment details
- Cloud-init version: 26.1-0ubuntu1~24.04.1. Code unchanged on main at
aad14e5d.
- Operating System Distribution: Ubuntu 24.04 booted as Xen dom0
(xen-system-amd64, m5.large)
- Cloud provider, platform or installer type: AWS EC2 with
`HttpTokens=required`

## cloud-init logs
Serial console from the repro (note the tokenless legacy path):

```
[ 8.5] url_helper.py[WARNING]: Calling 'http://169.254.169.254/2009-04-04/meta-data/instance-id' failed [0/240s]: ...
...
[ 244.1] url_helper.py[WARNING]: Calling 'http://169.254.169.254/2009-04-04/meta-data/instance-id' failed [235/240s]: ...
[ 244.1] DataSourceEc2.py[CRITICAL]: Giving up on md from ['http://169.254.169.254/2009-04-04/meta-data/instance-id', ...] after 235 seconds
[ 244.1] DataSourceEc2.py[ERROR]: Unable to get metadata
[ 257.6] Cloud-init v. 26.1-0ubuntu1~24.04.1 finished ... Datasource DataSourceNone. Up 257.66 seconds
[ 257.6] cc_final_message.py[WARNING]: Used fallback datasource
```

Contributor guide

Open the contributing guide

Research direction

Start in cloudinit/sources/DataSourceEc2.py at _collect_platform_data() lines 878-882, then read _maybe_fetch_api_token() around lines 301-310. Trace how an all-zero Xen UUID prevents the DMI fallback and stops token retrieval; done means AWS is detected and IMDSv2 token requests proceed on the reported Xen dom0 setup.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, linux, python
Domain
cloud
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.