cc-ssh: traceback when openssh-server absent

Bug #1969526 reported by Chad Smith
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
cloud-init
Fix Released
Low
Unassigned

Bug Description

In minimal cloud images without openssh-server, cloud-init will get the following traceback when the following cloud-config is provided:

```
#cloud-config
ssh_pwauth: true
```

2022-04-19 20:42:32,593 - stages.py[DEBUG]: Running module set-passwords (<module 'cloudinit.config.cc_set_passwords' from '/usr/lib/python3.6/site-packages/cloudinit/config/cc_set_passwords.py'>) with frequency once-per-instance
2022-04-19 20:42:32,593 - handlers.py[DEBUG]: start: modules-config/config-set-passwords: running config-set-passwords with frequency once-per-instance
2022-04-19 20:42:32,593 - util.py[DEBUG]: Writing to /var/lib/cloud/instances/rocky-8/sem/config_set_passwords - wb: [644] 24 bytes
2022-04-19 20:42:32,593 - helpers.py[DEBUG]: Running config-set-passwords using lock (<FileLock using file '/var/lib/cloud/instances/rocky-8/sem/config_set_passwords'>)
2022-04-19 20:42:32,594 - ssh_util.py[DEBUG]: line 1: option PasswordAuthentication added with no
2022-04-19 20:42:32,594 - util.py[DEBUG]: Writing to /etc/ssh/sshd_config - wb: [644] 26 bytes
2022-04-19 20:42:32,594 - subp.py[DEBUG]: Running command ['service', 'sshd', 'restart'] with allowed return codes [0] (shell=False, capture=True)
2022-04-19 20:42:32,620 - handlers.py[DEBUG]: finish: modules-config/config-set-passwords: FAIL: running config-set-passwords with frequency once-per-instance
2022-04-19 20:42:32,621 - util.py[WARNING]: Running module set-passwords (<module 'cloudinit.config.cc_set_passwords' from '/usr/lib/python3.6/site-packages/cloudinit/config/cc_set_passwords.py'>) failed
2022-04-19 20:42:32,621 - util.py[DEBUG]: Running module set-passwords (<module 'cloudinit.config.cc_set_passwords' from '/usr/lib/python3.6/site-packages/cloudinit/config/cc_set_passwords.py'>) failed
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/cloudinit/stages.py", line 876, in _run_modules
    freq=freq)
  File "/usr/lib/python3.6/site-packages/cloudinit/cloud.py", line 54, in run
    return self._runners.run(name, functor, args, freq, clear_on_fail)
  File "/usr/lib/python3.6/site-packages/cloudinit/helpers.py", line 185, in run
    results = functor(*args)
  File "/usr/lib/python3.6/site-packages/cloudinit/config/cc_set_passwords.py", line 234, in handle
    service_name=cloud.distro.get_option('ssh_svcname', 'ssh'))
  File "/usr/lib/python3.6/site-packages/cloudinit/config/cc_set_passwords.py", line 131, in handle_ssh_pwauth
    subp.subp(cmd)
  File "/usr/lib/python3.6/site-packages/cloudinit/subp.py", line 295, in subp
    cmd=args)
cloudinit.subp.ProcessExecutionError: Unexpected error while running command.
Command: ['service', 'sshd', 'restart']
Exit code: 5
Reason: -
Stdout:
Stderr: Redirecting to /bin/systemctl restart sshd.service
        Failed to restart sshd.service: Unit sshd.service not found.

While one could argue that cloud images without openssh-server might have limited utility, there are use cases for slim apps/micro-services that may not rely on this stack and cloud-init should probably cope better in the face of this missing dependency.

While working this issue, let's add a Suggests: openssh-server to debian/control for Deb-based systems.

--- Steps to reproduce problem
cat > ssh_needed.yaml << EOF
#cloud-config
ssh_pwauth: true
EOF

lxc launch ubuntu-daily:focal f1 -c user.user-data="$(cat ssh_needed.yaml)"
lxc exec f1 -- cloud-init status --wait
lxc exec f1 apt remove opensssh-server
# reset PasswordAuthentication off again so that cloud-init wants to reset ssh server
lxc exec f1 -- sed -i 's/PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config
# force clean reboot so cloud-init reruns
lxc exec f1 -- cloud-init clean --logs --reboot
lxc exec f1 -- cloud-init status --wait --long

Tags: bitesize
Chad Smith (chad.smith)
Changed in cloud-init:
importance: Undecided → Low
Revision history for this message
Chad Smith (chad.smith) wrote :

Look over our reference behavior when missing an expected binary package in this upstream commit[1] which may inform this work for how to approach this use-case as well

https://github.com/canonical/cloud-init/commit/437cb0a01bc3f8758caa7b87dcd077c101a55675

Chad Smith (chad.smith)
description: updated
Revision history for this message
Brett Holman (holmanb) wrote : Fixed in cloud-init version 22.2.

This bug is believed to be fixed in cloud-init in version 22.2. 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: Triaged → 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.