Invalid runcmd script format makes it ignored without marking cloud init as failed

Bug #1853146 reported by manuel
16
This bug affects 3 people
Affects Status Importance Assigned to Milestone
cloud-init
Fix Released
Medium
Brett Holman

Bug Description

Info :
- cloud-init version `/usr/bin/cloud-init 19.2-36-g059d049c-0ubuntu2~16.04.1`

Issue:

If user-data script contains a malformed runcmd script, cloud-init fails to parse it but do not mark cloud-init as failed.

Example:

```
runcmd:
- echo "begin runcmd"
- # empty
- echo "end"
```

The second line is empty, and causes the following warning in `/var/log/cloud-init.log`:

```
2019-11-19 12:39:10,124 - helpers.py[DEBUG]: Running config-runcmd using lock (<FileLock using file '/var/lib/cloud/instances/0B44BE6F-81FA-FF44-AB96-A0D9AB8B7171/sem/config_runcmd'>)
2019-11-19 12:39:10,124 - schema.py[DEBUG]: Ignoring schema validation. python-jsonschema is not present
2019-11-19 12:39:10,124 - util.py[WARNING]: Failed to shellify ['echo "begin runcmd"', None, 'echo "end"'] into file /var/lib/cloud/instances/0B44BE6F-81FA-FF44-AB96-A0D9AB8B7171/scripts/runcmd
2019-11-19 12:39:10,124 - util.py[DEBUG]: Failed to shellify ['echo "begin runcmd"', None, 'echo "end"'] into file /var/lib/cloud/instances/0B44BE6F-81FA-FF44-AB96-A0D9AB8B7171/scripts/runcmd
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/cloudinit/config/cc_runcmd.py", line 91, in handle
    content = util.shellify(cmd)
  File "/usr/lib/python3/dist-packages/cloudinit/util.py", line 2117, in shellify
    "Got: %s" % (type_utils.obj_name(args), args))
TypeError: Unable to shellify type 'NoneType'. Expected list, string, tuple. Got: None
2019-11-19 12:39:10,154 - handlers.py[DEBUG]: finish: modules-config/config-runcmd: SUCCESS: config-runcmd ran successfully
```

There is no error log in `/var/log/cloud-init-output.log`

But cloud-init status is "done"

I expect the status to be "error"

manuel (boillodmanuel)
summary: - Invalid runcmd script format make it ignored without marking cloud init
+ Invalid runcmd script format makes it ignored without marking cloud init
as failed
Revision history for this message
Ryan Harper (raharper) wrote :

Thanks for filing the bug.

As it turns out, this results in a null entry in the list, which cloud-init fails to "shellify" when rendering this list of commands to a shell script. This results in not writing any of the commands which is why you don't see an failure in the module status.

That's clearly a bug; so we'll need to make a change so that
we handle null or other entries where shellify fails as errors and log them.

Changed in cloud-init:
importance: Undecided → Medium
status: New → Confirmed
Brett Holman (holmanb)
Changed in cloud-init:
assignee: nobody → Brett Holman (holmanb)
Brett Holman (holmanb)
Changed in cloud-init:
status: Confirmed → Fix Committed
Revision history for this message
James Falcon (falcojr) wrote : Fixed in cloud-init version 21.4.

This bug is believed to be fixed in cloud-init in version 21.4. 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
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers