canonical / canonical/cloud-init
DataSourceEC2: Doesn't support the 2009-04-04 version of the EC2 metadata properly
- Dominant language
- Python
- Stars
- 3.8k
- Forks
- 1.1k
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 18
Description
# Bug report
DataSourceEC2 supports a minimal EC2 metadata version of 2009-04-04
https://github.com/canonical/cloud-init/blob/654cb4414b29ab845e0fdad97b5beca8721844df/cloudinit/sources/DataSourceEc2.py#L79
but issues a warning due to the lack of a `network` key. There is no `network` key on that version of metadata. (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html)
This warning causes `cloud-init status` to exit with an exit code of 2, which fails many boot scripts.
There is no test for a 2009-04-04 version of the metadata in the cloud-init data source test scripts.
## Steps to reproduce the problem
The top-level keys for the metadata can be obtained from any EC2 machine
```
$ curl -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/2009-04-04/meta-data/
ami-id
ami-launch-index
ami-manifest-path
block-device-mapping/
hostname
instance-action
instance-id
instance-type
local-hostname
local-ipv4
placement/
profile
public-hostname
public-ipv4
public-keys/
reservation-id
security-groups
```
## Environment details
- Cloud-init version: 24.2-0ubuntu1~24.04.2
- Operating System Distribution: Ubuntu
- Cloud provider, platform or installer type: Brightbox
## cloud-init logs
```
2024-09-17 10:28:22,642 - sources[DEBUG]: Searching for local data source in: ['DataSourceEc2Local']
2024-09-17 10:28:22,642 - handlers.py[DEBUG]: start: init-local/search-Ec2Local: searching for local data from DataSourceEc2Local
2024-09-17 10:28:22,642 - sources[DEBUG]: Seeing if we can get any data from
2024-09-17 10:28:22,644 - DataSourceEc2.py[DEBUG]: Local Ec2 mode only supported on ('aws', 'outscale'), not brightbox
2024-09-17 10:28:22,644 - sources[DEBUG]: Datasource DataSourceEc2Local not updated for events: boot-new-instance
2024-09-17 10:28:22,644 - handlers.py[DEBUG]: finish: init-local/search-Ec2Local: SUCCESS: no local data found from DataSourceEc2Local
2024-09-17 10:28:25,687 - sources[DEBUG]: Searching for network data source in: ['DataSourceEc2', 'DataSourceNone']
2024-09-17 10:28:25,687 - handlers.py[DEBUG]: start: init-network/search-Ec2: searching for network data from DataSourceEc2
2024-09-17 10:28:25,687 - sources[DEBUG]: Seeing if we can get any data from
2024-09-17 10:28:25,688 - sources[DEBUG]: Detected platform: DataSourceEc2. Checking for active instance data
2024-09-17 10:28:25,689 - DataSourceEc2.py[DEBUG]: strict_mode: warn, cloud_name=brightbox cloud_platform=ec2
2024-09-17 10:28:25,813 - DataSourceEc2.py[DEBUG]: Removed the following from metadata urls: ['http://instance-data.:8773']
2024-09-17 10:28:25,868 - DataSourceEc2.py[DEBUG]: Using metadata source: 'http://169.254.169.254'
2024-09-17 10:28:25,877 - DataSourceEc2.py[DEBUG]: url http://169.254.169.254/2021-03-23/meta-data/instance-id raised exception 404 Client Error: Not Found for url: http://169.254.169.254/2021-03-23/meta-data/instance-id
2024-09-17 10:28:25,885 - DataSourceEc2.py[DEBUG]: url http://169.254.169.254/2018-09-24/meta-data/instance-id raised exception 404 Client Error: Not Found for url: http://169.254.169.254/2018-09-24/meta-data/instance-id
2024-09-17 10:28:25,894 - DataSourceEc2.py[DEBUG]: url http://169.254.169.254/2016-09-02/meta-data/instance-id raised exception 404 Client Error: Not Found for url: http://169.254.169.254/2016-09-02/meta-data/instance-id
2024-09-17 10:28:26,568 - handlers.py[DEBUG]: finish: init-network/search-Ec2: SUCCESS: found network data from DataSourceEc2
2024-09-17 10:28:26,568 - stages.py[INFO]: Loaded datasource DataSourceEc2 - DataSourceEc2
2024-09-17 10:28:26,616 - DataSourceEc2.py[WARNING]: Metadata 'network' key not valid: None.
2024-09-17 10:28:32,536 - util.py[DEBUG]: Cloud-init v. 24.2-0ubuntu1~24.04.2 finished at Tue, 17 Sep 2024 10:28:32 +0000. Datasource DataSourceEc2. Up 18.53 seconds
```
Contributor guide
Assessment
This issue has not been assessed yet.