cloudbase / cloudbase-init

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

must change password on first boot #59

Closed wywself closed 3 years ago

wywself commented 3 years ago

As shown in the figure below, after the first initialization is completed, the password must be changed,but I have configured first_logon_behaviour=no in cloudbase-init.conf & cloudbase-init-unattend.conf.

image The first text box is the admin_pass value set in meta_data.json, the second text box is the new password to be configured, and the third text box is to confirm the new password. image

Can someone help me please? Thank you.

ader1990 commented 3 years ago

Hello @andia10240,

How did you solve the issue, for further reference?

Thank you.

wywself commented 3 years ago

Problem still exists,I reopen it now. my cloudbase-init.conf: image cloudbase-init-unattend.conf: image

ader1990 commented 3 years ago

The configuration files look good.

To debug the problem, can you please provide the logs located at C:\program files\Cloudbase Solutions\Cloudbase-init\log ? Also, can you share what Windows version are you using and how you created the image? did you use https://github.com/cloudbase/windows-openstack-imaging-tools ?

Thanks.

wywself commented 3 years ago

Cloudbase-init version: 1.1.0 offical Windows version: Windows server 2016 standard logfile: cloudbase-init.log cloudbase-init-unattend.log

wywself commented 3 years ago

I didn't choose "Run cloudbase-init service as LocalSystem",and I didn't select "serial port of logging".

ader1990 commented 3 years ago

From the logs, I saw there is a problem when cloudbase-init service runs under cloudbase-init user.

A fast resolution would be to enable "Run cloudbase-init service as LocalSystem". The difference between running cloudbase-init as LocalSystem or as a dedicated user is that when running under dedicated user, userdata scripts can be used to impersonate other users - similar to su on Linux (useful when automating exchange or sharepoint installs).

The kind of error that showed up in the logs can happen on baremetal servers where some Windows APIs are not available in the early boot process leading to error:

cloudbaseinit.exception.WindowsCloudbaseInitException: Cannot load user profile:

A proper solution might be to add a retry to the user load profile (will make a patch for it).

Thank you, Adrian Vladu

wywself commented 3 years ago

If I enable "Run cloudbase-init service as LocalSystem",windows system cannot boot.So I disable it. Error msg: "The Computer restart unexpectly on encountered an unexpected error.Windows installation cannot proceed...." image

wywself commented 3 years ago

Hi, @ader1990 I add plugins=cloudbaseinit.plugins.common.setuserpassword.SetUserPasswordPlugin in cloudbase-init-unattend.conf for early execution. But when the system is fully booted up successfully, the password is incorrect when logging in with the set password. In cloudbase-init-unattend.log, shows Password succesfully updated for user Administrator,In cloudbase-init.log, shows Plugin 'SetUserPasswordPlugin' execution already done, skipping _exec_plugin C:\Program Files\Cloudbase Solutions\Cloudbase-Init\Python\lib\site-packages\cloudbaseinit\init.py. I can't understand.Can you help me? Thank you.

wywself commented 3 years ago

The problem is solved. Password is changed by CreateUserPlugin, which use random password. So I add CreateUserPlugin in cloudbase-init-unattend.conf.It works fine. My cloudbase-init-unattend.conf as shown below. image

Thank you for your help. @ader1990

ader1990 commented 3 years ago

enable "Run cloudbase-init service as LocalSystem"

Enabling "Run cloudbase-init service as LocalSystem" should not interfere or provoke the problem you have. Are you sure you created the Windows image correctly?

If you get that error, press Shift+F10 and a cmd will appear. Using notepad.exe you can check the cloudbase-init unattend logs for errors.

ader1990 commented 3 years ago

@andia10240 the unattend run of cloudbase-init is supposed to use ConfigDrive and ONLY contain the MTU plugin (http metadata might not be available otherwise) , SetHostname plugin (to save an extra reboot) and ExtendVolume (image partition might be very small and the OS can run out of space on large RAM size, as the pagefile eats the remaining space).

If you add any other plugin, they might fail because not all the Windows APIs / services are available at that stage. Adding CreateUser or SetUserPassword is a NOOP, as sethostname plugin ends the cloudbase-init execution before the other two plugins get executed.

wywself commented 3 years ago

According to the following part of the code, I understand that SetHostnamePlugin will return reboot_required=True, but allow_reboot=false in cloudbase-init-unattend.conf, so CreateUser or SetUserPassword is useful. It's right?

     def _handle_plugins_stage(self, osutils, service, instance_id, stage):
        plugins_shared_data = {}
        reboot_required = False
        stage_success = True
        plugins = plugins_factory.load_plugins(stage)

        LOG.info('Executing plugins for stage %r:', stage)

        for plugin in plugins:
            if self._check_plugin_os_requirements(osutils, plugin):
                success, reboot_required = self._exec_plugin(
                    osutils, service, plugin, instance_id,
                    plugins_shared_data)
                if not success:
                    stage_success = False
                if reboot_required and CONF.allow_reboot:
                        break

        return stage_success, reboot_required
ader1990 commented 3 years ago

Not all the Windows APIs and services are available during the cloudbase-init unattend stage.

CreateUserPlugin/SetUserPasswordPlugin (or any other plugin, excluding the 3 default ones) can be used at your own risk.

Their behaviour is not tested in the unattend stage and they are not supposed to be run on that stage.

chiencq commented 1 year ago

Hi @wywself , please share me all blueprint code for this, i'm a beginer. thanks.