Using OBS Buckets to Implement Custom Script Injection During Node Creation
Background
If you need to install some tools or perform custom security hardening on a node in advance, you need to inject some scripts when creating the node. CCE allows you to inject pre-installation and post-installation scripts when creating a node. However, this function has the following restrictions:
- The script characters are limited.
- The injected script content needs be frequently modified to meet various requirements and scenarios. However, CCE node pools have fixed scripts and do not support frequent modifications.
Solution
This section describes how to use CCE and OBS to provide a simplified, scalable, and easy-to-maintain solution so that you can operate CCE nodes as you want.
Store the scripts in the OBS buckets. During node pool creation, CCE automatically pulls and executes the stored scripts based on the configured injection scripts. In this way, the configuration of the CCE node pool does not need to be changed. If there are new requirements, you only need to update the scripts in the OBS buckets.
Suggestions on Maintaining OBS Buckets
- If there is no OBS bucket dedicated for O&M, create an OBS bucket dedicated for O&M.
- Create a multi-level directory tools/cce in the bucket to represent CCE-specific tools for easy maintenance. You can also store other tool scripts in this directory later.
Precautions
- If the custom operation implemented by the script fails, the normal service running is affected. You are advised to add a check program at the end of the script. If the check fails, stop the kubelet process in the post-installation script to prevent services from being scheduled to the node.
systemctl stop kubelet-monit systemctl stop kubelet
- Do not include sensitive information in the scripts to prevent information leakage.
Procedure
- Create an OBS bucket.
- Upload the pre-installation and post-installation scripts. The pre_install.sh and post_install.sh scripts are used as examples.
Figure 1 Uploading scripts
- Configure a read-only security policy for the scripts to ensure that the scripts can be downloaded without entering a password on the CCE nodes but cannot be downloaded from the Internet.
- Configure a policy for the tools/cce directory and select a read-only policy template.
Figure 2 Configuring an object policy
- Modify the configuration information about the anonymous user, specified objects, and conditions.
Figure 3 Anonymous user
Figure 4 Specified objects
Figure 5 Conditions
Two conditions are set: UserAgent and SourceIp.- UserAgent functions in the similar way as a key. The specified User-Agent request header and the corresponding key value must be carried during access.
- SourceIp is used to prevent access from external networks. Set this parameter to 100.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,214.0.0.0/8, among which 100.0.0.0/8 and 214.0.0.0/8 are private IP ranges, among whom 10.0.0.0/8, 172.16.0.0/12, and 192.168.0.0/16 are commonly used.
For details about how to configure an OBS policy, see Configuring an Object Policy and Bucket Policy Parameters.
- Configure a policy for the tools/cce directory and select a read-only policy template.
- Configure the pre-installation script and post-installation script when creating a node pool on CCE.
Enter the following scripts in the Advanced ECS Settings on the Create Node Pool page:
In the scripts below, the curl command is run to download pre_install.sh and post_install.sh from OBS to the /tmp directory, and then pre_install.sh and post_install.sh are executed.
Pre-installation script:
curl -H "User-Agent: ccePrePostInstall" https://ops-cce.obs.ap-southeast-1.myhuaweicloud.com/tools/cce/pre_install.sh -o /tmp/pre_install.sh && bash -x /tmp/pre_install.sh > /tmp/pre_install.log 2>&1
Post-installation script:
curl -H "User-Agent: ccePrePostInstall" https://ops-cce.obs.ap-southeast-1.myhuaweicloud.com/tools/cce/post_install.sh -o /tmp/post_install.sh && bash -x /tmp/post_install.sh > /tmp/post_install.log 2>&1
- The actual value of User-Agent must be configured based on the OBS bucket policy.
- The bucket address in the link must be configured based on site requirements.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot