canonical / canonical/cloud-init

Cloud-init inconsistently uses config

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

Description

This bug was originally filed in Launchpad as [LP: #2009236](https://bugs.launchpad.net/cloud-init/+bug/2009236)

Launchpad details

affected_projects = []

assignee = None
assignee_name = None
date_closed = None
date_created = 2023-03-03T22:59:37.622328+00:00
date_fix_committed = None
date_fix_released = None
id = 2009236
importance = medium
is_complete = False
lp_url = https://bugs.launchpad.net/cloud-init/+bug/2009236
milestone = None
owner = holmanb
owner_name = Brett Holman
private = False
status = triaged
submitter = holmanb
submitter_name = Brett Holman
tags = []
duplicates = []

_Launchpad user **Brett Holman(holmanb)** wrote on 2023-03-03T22:59:37.622328+00:00_

On boot, cloud-init is able to pass cloud-config via userdata_raw, a useful feature when testing behavior on a datasource that doesn't have its own way of retrieving userdata.

system_info:
datasource:
None:
userdata_raw: "#cloud-config\ngrub_dpkg:\n enabled: true"

This works during boot as one might expect:

2023-03-03 21:15:59,255 - modules.py[DEBUG]: Running module grub-dpkg () with frequency once-per-instance
2023-03-03 21:15:59,256 - handlers.py[DEBUG]: start: modules-config/config-grub-dpkg: running config-grub-dpkg with frequency once-per-instance

However, cloud-init's single subcommand clearly uses a different configuration, since the following fails to run the same module with the same config:

```
cloud-init --debug --force single --frequency always --name cc_grub_dpkg
```

Furthermore, this userdata_raw isn't included in /run/cloud-init/instance-data-sensitive.json, nor in cloud-init query -a.

Alarmingly, an invalid config provided via userdata_raw is not warned of by cloud-init schema --system:

```
system_info:
# This will affect which distro class gets used
datasource:
NoCloud:
userdata_raw: |
#cloud-config
grub_dpkg:
enabled: true
invalid-key: true
```

output:
```
# cloud-init schema --system
Found cloud-config data types: user-data, vendor-data

1. user-data at /var/lib/cloud/instances/cloudinit-0302-160255pw859u9h/cloud-config.txt:
Valid cloud-config: user-data

2. vendor-data at /var/lib/cloud/instances/cloudinit-0302-160255pw859u9h/vendor-cloud-config.txt:
Valid cloud-config: vendor-data
```

These details reveal inconsistency in cloud-init config handling, and all contribute to a confusing user experience when using userdata_raw.

There may be other inconsistencies too - configs passed directly on the kernel commandline (cc: end_cc), and configs sourced from a url via the kernel commandline (cloud-config-url=) are both used during boot - but I haven't looked to see whether they behave correctly with (schema|single|query) subcommands or show up in /run/cloud-init/instance-data-sensitive.json, but after this finding we probably aught to audit for other issues like this.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.