Triage and Remediation
Remediation
Using Console
Using Console
To remediate the misconfiguration “Root User Should Not Be Accessible From Any Host” for GCP using GCP console, follow these steps:
- Login to the GCP console at https://console.cloud.google.com/
- Navigate to the IAM & Admin section on the left-hand side of the console.
- Click on the “IAM” tab.
- Search for the “root” user in the list of IAM users.
- Click on the edit icon (pencil) next to the root user.
- In the “Add a member” field, enter the email address of the user you want to grant root user access to.
- Select the “Project” role from the dropdown menu.
- Click the “Save” button.
Using CLI
Using CLI
To remediate the misconfiguration “Root User Should Not Be Accessible From Any Host” for GCP using GCP CLI, follow these steps:Replace
- Open the Google Cloud Console and navigate to the GCP project where the misconfiguration exists.
- Open the Cloud Shell by clicking on the icon in the top right corner of the console.
- Run the following command to list all the users in the project:
-
Identify the root user in the list. The root user will have the email address format
username@<project-id>.iam.gserviceaccount.com
. - Run the following command to remove the root user’s access from all hosts:
- Run the following command to create a new firewall rule that allows access to all users except the root user:
- Run the following command to add the
root-access
tag to the root user’s account:
<instance-name>
with the name of the instance where the root user has access.- Run the following command to remove the
root-access
tag from all other instances:
- Verify that the root user no longer has access to any instances in the project.
Using Python
Using Python
To remediate the misconfiguration “Root User Should Not Be Accessible From Any Host” in GCP using python, follow these steps:Note: This code snippet is just an example and may need to be modified depending on your specific use case. Please refer to the GCP documentation for more information on how to use the
- First, you need to authenticate to GCP using a service account key file. You can create a service account and download the key file from the GCP console.
- Next, you need to use the
google-cloud-iam
library to list all the IAM policies for your GCP project.
- Once you have the IAM policies, you need to find the policy that grants the
roles/owner
role to theuser:root
member.
roles/owner
role to the user:root
member:- Finally, you need to remove the
user:root
member from the policy that grants theroles/owner
role.
user:root
member from the policy that grants the roles/owner
role:google-cloud-iam
library.