Triage and Remediation
Remediation
Using Console
Using Console
To remediate the misconfiguration “OS Login Should Be Enabled” for GCP using GCP console, follow these steps:
- Open the GCP Console and select the project you want to work on.
- In the left-hand menu, select “Compute Engine” and then select “VM instances”.
- Click on the name of the VM instance you want to configure.
- In the VM instance details page, click on the “Edit” button at the top of the page.
- Scroll down to the “Cloud API access scopes” section.
- In the “Cloud API access scopes” section, click on “Allow full access to all Cloud APIs”.
- Scroll down to the “Cloud Identity and Access Management (IAM)” section.
- In the “Cloud Identity and Access Management (IAM)” section, click on “Add item”.
- In the “Add members” dialog box, enter the email address of the user or service account you want to grant access to.
- In the “Role” dropdown menu, select “Compute OS Login”.
- Click “Save” to apply the changes.
Using CLI
Using CLI
To remediate the “OS Login Should Be Enabled” misconfiguration in GCP using GCP CLI, you can follow these steps:Replace Replace This command will return
- Open the Cloud Shell from the GCP Console.
- Run the following command to enable OS Login for all users in your project:
- If you want to enable OS Login for a specific instance, you can use the following command:
INSTANCE_NAME
with the name of the instance for which you want to enable OS Login.- If you want to enable OS Login for a specific user, you can use the following command:
PUBLIC_KEY_FILE
with the path to the public key file, TTL
with the time-to-live for the key (in seconds), and USERNAME
with the username of the user for whom you want to enable OS Login.- Verify that OS Login is enabled by running the following command:
TRUE
if OS Login is enabled for your project.That’s it! By following these steps, you should be able to remediate the “OS Login Should Be Enabled” misconfiguration in GCP using GCP CLI.Using Python
Using Python
To remediate the misconfiguration “OS Login Should Be Enabled” for GCP using Python, follow these steps:Note: Make sure to replace “your-project-id” and “your-zone” with your actual project ID and zone.
- Import the necessary libraries:
- Set the project ID and zone where the VM instances are located:
- Authenticate and authorize the client:
- Retrieve the list of VM instances:
- For each VM instance, check if OS Login is enabled:
- If OS Login is not enabled, enable it:
- Verify that OS Login is now enabled: