cloudbase / cloudbase-init

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

authorized_keys not created on Win Server 2022 #85

Open makton-dev opened 2 years ago

makton-dev commented 2 years ago

Platform: Windows Server 2022 on Proxmox VE using configdrive

This was something which was in the Proxmox VE forum, and I happened to get time to play with it while working on the DNS issue for Windows, Proxmox VE, and Cloudbase-init. When first brining up a VM after a sysprep (new VM), the log shows the file was written, but does not exist.

2021-12-17 18:30:45.194 3000 INFO cloudbaseinit.init [-] Executing plugin 'SetUserSSHPublicKeysPlugin' 2021-12-17 18:30:45.194 3000 DEBUG cloudbaseinit.metadata.services.base [-] Using cached copy of metadata: 'openstack/latest/meta_data.json' _get_cache_data C:\Program Files\Cloudbase Solutions\Cloudbase-Init\Python\lib\site-packages\cloudbaseinit\metadata\services\base.py:74 2021-12-17 18:30:45.210 3000 DEBUG cloudbaseinit.metadata.services.base [-] Using cached copy of metadata: 'openstack/latest/meta_data.json' _get_cache_data C:\Program Files\Cloudbase Solutions\Cloudbase-Init\Python\lib\site-packages\cloudbaseinit\metadata\services\base.py:74 2021-12-17 18:30:45.225 3000 DEBUG cloudbaseinit.utils.classloader [-] Loading class 'cloudbaseinit.osutils.windows.WindowsUtils' load_class C:\Program Files\Cloudbase Solutions\Cloudbase-Init\Python\lib\site-packages\cloudbaseinit\utils\classloader.py:27 2021-12-17 18:30:45.225 3000 DEBUG cloudbaseinit.plugins.common.sshpublickeys [-] User home: C:\Users\Administrator execute C:\Program Files\Cloudbase Solutions\Cloudbase-Init\Python\lib\site-packages\cloudbaseinit\plugins\common\sshpublickeys.py:45 2021-12-17 18:30:45.240 3000 INFO cloudbaseinit.plugins.common.sshpublickeys [-] Writing SSH public keys in: C:\Users\Administrator\.ssh\authorized_keys 2021-12-17 18:30:45.256 3000 DEBUG cloudbaseinit.metadata.services.baseconfigdrive [-] Deleting metadata folder: 'C:\\Windows\\TEMP\\tmpq6sa1nu5' cleanup C:\Program Files\Cloudbase Solutions\Cloudbase-Init\Python\lib\site-packages\cloudbaseinit\metadata\services\baseconfigdrive.py:91 2021-12-17 18:30:45.272 3000 INFO cloudbaseinit.init [-] Plugins execution done

If the plugin state is cleared in the registry and the VM is rebooted (no sysprep), the action will be repeated and the authorized_keys will be there and with the wanted keys.

Seems like the profile is not ready at the time the plugin is executed. thoughts?

Was thinking a "pre-login" of the account to prep the profile for the SSH keys to be added.