Injecting User Data

Application Scenarios

You can inject user data to configure BMSs.

Constraints

Procedure

  1. Create a user data script. The format must comply with user data script specifications. For details, see Helpful Links.
  2. When creating a BMS, set Advanced Settings to Configure now, and paste the content of the user data script to the User Data text box or upload the user data file.
    Figure 1 Injecting user data
  3. The created BMS automatically runs Cloud-Init or Cloudbase-Init to read the user data script upon startup.

User Data Scripts of Linux BMSs

User data scripts of Linux BMSs are customized by using the open-source Cloud-Init architecture. This architecture uses BMS metadata as the data source for automatically configuring the BMSs. The script types are compatible with open-source Cloud-Init. For details about Cloud-Init, see http://cloudinit.readthedocs.io/en/latest/topics/format.html.

User Data Scripts of Windows BMSs

User data scripts of Windows BMSs are customized by using the open-source Cloudbase-Init architecture. This architecture uses BMS metadata as the data source for initializing and automatically configuring the BMSs. The script types are compatible with open-source Cloudbase-Init. For details about Cloudbase-Init, see https://cloudbase-init.readthedocs.io/en/latest/userdata.html.

Case 1

This case illustrates how to inject user data so as to simplify BMS configuration.

In this example, vim is configured to enable syntax highlighting, display line numbers, and set the tab stop to 4. Configuration file .vimrc is created and injected into the /root/.vimrc directory during BMS creation. After the BMS is created, vim is automatically configured based on your requirements. This helps to improve BMS configuration efficiency, especially when you are creating ECSs in a batch.

The script is as follows:

#cloud-config
write_files:
  - path: /root/.vimrc
    content: |
      syntax on
      set tabstop=4
      set number      

Case 2

This case illustrates how to inject user data so as to reset the password for logging in to a Linux BMS.

In this example, the password of user root will be reset to "******".

The new password must meet the password complexity requirements listed in Table 3.

Table 3 Password requirements

Parameter

Requirements

Example Value

Password

  • Consists of 8 to 26 characters.
  • Must contain at least three of the following character types:
    • Uppercase letters
    • Lowercase letters
    • Digits
    • Special characters !@$%^-_=+[]{}:,./?
  • Cannot contain the username or the username spelled backwards.
  • Cannot contain more than two characters in the same sequence as they appear in the username. (This requirement applies only to Windows BMSs.)

Test12$@

The script is as follows (retain the indentation in the following script):

#cloud-config
chpasswd:
  list: |
    root:******
  expire: False

After the BMS is created, you can use the new password to log in to it. To ensure system security, change the password of user root after logging in to the BMS for the first time.

Case 3

This case illustrates how to inject user data so as to create a user on a Windows BMS and set a password for the user.

In this example, the user's username is abc, its password is ******, and the user is added to the administrators user group.

The new password must meet the password complexity requirements listed in Table 4.

Table 4 Password requirements

Parameter

Requirements

Example Value

Password

  • Consists of 8 to 26 characters.
  • Must contain at least three of the following character types:
    • Uppercase letters
    • Lowercase letters
    • Digits
    • Special characters !@$%^-_=+[]{}:,./?
  • Cannot contain the username or the username spelled backwards.
  • Cannot contain more than two characters in the same sequence as they appear in the username. (This requirement applies only to Windows BMSs.)

Test12$@

The script is as follows:

rem cmd
net user abc ****** /add
net localgroup administrators abc /add

After the BMS is created, you can use its username and password to log in to it.

Case 4

This case illustrates how to inject user data so as to update system software packages for a Linux BMS and enable the HTTPd service. After the user data is injected, you can use the HTTPd service.

The script is as follows:

#!/bin/bash
yum update -y
service httpd start
chkconfig httpd on

Case 5

This case illustrates how to inject user data so as to assign the user root permission for remotely logging in to a Linux BMS. After injecting the file, you can log in to the BMS as user root in SSH key authentication mode.

The script is as follows:

#cloud-config
disable_root: false
runcmd:
- sed -i 's/^PermitRootLogin.*$/PermitRootLogin without-password/' /etc/ssh/sshd_config
- sed -i '/^KexAlgorithms.*$/d' /etc/ssh/sshd_config
- service sshd restart

Helpful Links

For more information about user data injection cases, visit the official Cloud-init/Cloudbase-init website: