Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Changing Root Password in OpenStack Cloud Images

Tech May 10 4

Overview

After uploading a cloud image to the OpenStack Glance service and creating an instance, you may find that the default password remains unchanged. This guide documents the process of modifying the root password within a cloud image file.

Environment and Image Preparation

First, list all available images in Glance:

openstack image list
# +--------------------------------------+-------------------------+--------+
# | ID                                   | Name                    | Status |
# +--------------------------------------+-------------------------+--------+
# | 170481aa-4221-4d19-b657-201b23b8be47 | Arch                    | active |
# | f4c3c588-49dc-42ff-a8dc-6ceb1f74b14b | CentOS-7.9.2009-minimal | active |
# | d05dea62-2440-43df-a80f-ae8ce303d08f | Rocky                   | active |
# | bd649513-8d66-4e90-a8f2-c873c32c82be | Windows Server 2019     | active |
# | fb1d339a-59d8-4e3d-bb5f-57b87dd015f6 | freebsd-14              | active |
# +--------------------------------------+-------------------------+--------+

Locate the image file in the /var/lib/glance/images/ directory on the Glance host, using the image ID from the list above. In this environment, the storage is mounted via iSCSI, so the image must be downloaded locally for modification.

openstack image save --file cloud-image.qcow2 Rocky
# --file specifies the local filename, followed by the image name.
# root@node1:~# ls -l
# ...
# -rw-r--r-- 1 root root 1092812800 Apr 11 02:28 cloud-image.qcow2

Install the libguestfs tools required for image modification:

apt install libguestfs-tools -y

Modifying the Password

Option 1: Generate a Random Password

virt-customize -a cloud-image.qcow2 --root-password random
# [   0.0] Examining the guest ...
# [   6.6] Setting a random seed
# [   6.7] Setting passwords
# virt-customize: Setting random password of root to X9kP7mNvL4qW2rTz
# [   8.6] Finishing off

The randomly generated password is X9kP7mNvL4qW2rTz.

Option 2: Set a Specific Password

virt-customize -a cloud-image.qcow2 --root-password password:MySecurePass2024
# [   0.0] Examining the guest ...
# [   6.6] Setting a random seed
# [   6.7] Setting passwords
# [   8.6] Finishing off

Option 3: Modify Password for Non-Root Users

Note: This command only modifies an existing user's password; it does not create new users.

virt-customize -a cloud-image.qcow2 --password deployuser:password:Deploy@2024
# [   0.0] Examining the guest ...
# [   6.6] Setting a random seed
# [   6.7] Setting passwords
# [   8.6] Finishing off

Uploading the Modified Image

Remove the old image from Glance and upload the modified version:

openstack image delete Rocky

openstack image create --file ./cloud-image.qcow2 --disk-format qcow2 --public RockyOS9

Alternative: OpenStack Script Enjection

Note: The following method was not verified in this environment (deployed via Docker). Use as reference only.

Modify the Nova configuration file at /etc/nova/nova.conf:

inject_password=true

When creating an instance, navigate to Create Instance → Configuration → Customization Script and enter the following shell script. Replace MySecurePass2024 with your desired password:

#!/bin/bash
echo 'MySecurePass2024' | passwd --stdin root

Insure the "Configuration Drive" opsion is checked.

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.