cloudbase / cloudbase-init

Cross-platform instance initialization
http://openstack.org
Apache License 2.0
414 stars 150 forks source link

Cloud-config user 'inactive' option can't be set due to 'no_create_home' bug #76

Open nullptr0000 opened 2 years ago

nullptr0000 commented 2 years ago

If cloud-config userdata tries to configure a user with the 'inactive' option set to True, the creation of that user fails with the exception "_The user is required to be enabled if public_keys or createhome are set".

This is due to the undocumented option '_no_createhome' also having to be set to True for the 'inactive' option to work.

Unfortunately this isn't possible as an error in cloudbaseinit/plugins/common/userdataplugins/cloudconfigplugins/users.py (line 118) means that the code checks the value of '_no_createhome ' (with an extra space added to the end) not the proper option '_no_createhome'. This means the option cannot be set by the userdata and always remains at the default value of False, which in turn makes it impossible to use the 'inactive' option.

Replacing the incorrect item.get('no_create_home ', False)) with item.get('no_create_home', False)) makes the code function as expected.

Extra comments:

jf commented 2 years ago

thank you for putting in the work to diagnose this, @nullptr0000 ! I've been thinking no_create_home was a working thing until I actually looked and saw that the home directory was still being created for my users...