Triage and Remediation
Remediation
Using Console
Using Console
To remediate the misconfiguration of “Container-Optimized OS Should Be Enabled” in GCP, you can follow the below steps using the GCP console:
- Open the GCP Console and go to the Compute Engine page.
- Select the instance for which you want to enable Container-Optimized OS.
- Click on the “Edit” button on the top of the page.
- Scroll down to the “Cloud API access scopes” section.
- Expand the “Compute Engine default service account” section.
- Click on the “Set access for each API” button.
- In the “Compute Engine” section, select the “Read Write” access level.
- Click on the “Save” button to save the changes.
- Scroll up to the “Boot disk” section.
- Click on the “Change” button.
- In the “Operating system” section, select “Container-Optimized OS”.
- Click on the “Select” button to save the changes.
- Click on the “Save” button to apply the changes to the instance.
Using CLI
Using CLI
To enable Container-Optimized OS on GCP using GCP CLI, follow these steps:Replace [INSTANCE_NAME] with the name of the instance that you want to enable Container-Optimized OS on, [DISK_SIZE] with the size of the boot disk in GB, and [DEVICE_NAME] with the name of the boot disk device.This command should output information about the OS, including the line “ID=cos”.That’s it! Container-Optimized OS is now enabled on your GCP instance.
- Open the Cloud Shell on the GCP Console.
- Run the following command to enable the Container-Optimized OS:
- Once the instance is created, SSH into the instance and verify that Container-Optimized OS is enabled by running the following command:
Using Python
Using Python
To remediate the misconfiguration of “Container-Optimized OS Should Be Enabled” in GCP using Python, you can follow the below steps:This code will check all the instances in the specified zone of the project and enable the Container-Optimized OS if it is not already enabled.
- Import the necessary libraries:
- Set the project ID and the service account credentials:
- Build the GCP Compute Engine API client:
- Get the list of instances in the project:
- Loop through the instances and check if the Container-Optimized OS is enabled: