Skip to content

Commit

Permalink
perf(set_passwords): Run module in Network stage (#5395)
Browse files Browse the repository at this point in the history
Cloud-init blocks login until Config stage completes[1] to prevent users
from connecting to the instance via ssh prior to user configuration[2].
To enable faster ssh, cloud-init can simply move the set_passwords
module sooner in boot. This follows precedent of previous races of this
kind[3], and it effectively reverts b3c9b6a and while moving the set_passwords
module into Network stage.

The snap and grub_dpkg modules take a significant amount of time due to
runtime of external commands. This should improve time to ssh for all
users of those modules.

This will make both chpasswd and passwd run earlier in boot than before.
This should be safe, since chpasswd and passwd both use PAM, which to my
knowledge just requires r/w access to /etc/.


Probably the biggest noticeable effect will be for snapd users, which will
no longer have to wait an extra ~13s for snapd to start before they can ssh
into the instance.

graphical.target @27.796s
└─multi-user.target @27.796s
  └─snapd.seeded.service @14.658s +13.135s
    └─basic.target @14.207s
      └─sockets.target @14.197s
        └─snapd.socket @14.121s +61ms
          └─sysinit.target @14.006s
            └─cloud-init.service @11.135s +2.506s
              └─systemd-networkd-wait-online.service @9.670s +1.448s
                └─systemd-networkd.service @9.575s +71ms
                  └─network-pre.target @9.561s
                    └─cloud-init-local.service @5.564s +3.983s
                      └─systemd-remount-fs.service @1.581s +150ms
                        └─systemd-fsck-root.service @1.299s +195ms
                          └─systemd-journald.socket @1.011s
                            └─-.mount @880ms
                              └─-.slice @880ms.

[1] #2111
[2] https://bugs.launchpad.net/ubuntu/+source/cloud-init/+bug/2013403
[3] https://bugs.launchpad.net/ubuntu/+source/cloud-init/+bug/781101
  • Loading branch information
holmanb committed Jun 28, 2024
1 parent 8a4730b commit e7d8328
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion config/cloud.cfg.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ cloud_init_modules:
- rsyslog
- users_groups
- ssh
- set_passwords

# The modules that run in the 'config' stage
cloud_config_modules:
Expand All @@ -156,7 +157,6 @@ cloud_config_modules:
{% endif %}
- locale
{% endif %}
- set_passwords
{% if variant == "alpine" %}
- apk_configure
{% elif variant in ["debian", "ubuntu", "unknown"] %}
Expand Down
1 change: 0 additions & 1 deletion systemd/cloud-config.service.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# https://cloudinit.readthedocs.io/en/latest/explanation/boot.html
Description=Cloud-init: Config Stage
After=network-online.target cloud-config.target
Before=systemd-user-sessions.service
Wants=network-online.target cloud-config.target
ConditionPathExists=!/etc/cloud/cloud-init.disabled
ConditionKernelCommandLine=!cloud-init=disabled
Expand Down
1 change: 1 addition & 0 deletions systemd/cloud-init.service.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ After=dbus.service
Before=network-online.target
Before=sshd-keygen.service
Before=sshd.service
Before=systemd-user-sessions.service
{% if variant in ["ubuntu", "unknown", "debian"] %}
Before=sysinit.target
Before=shutdown.target
Expand Down

0 comments on commit e7d8328

Please sign in to comment.