Skip to main content

More Info:

Ensuring that no service accounts have admin privileges.

Risk Level

Critical

Address

Security

Compliance Standards

  • CIS GCP
  • CIS GCP 2.0.0
  • Cloudanix Best Practice

Triage and Remediation

Remediation

Using Console

To remediate the misconfiguration “Service Accounts Admin And User Permissions Should Not Be Assigned At The Same Time” for GCP using GCP console, follow the below steps:
  1. Login to the GCP console (https://console.cloud.google.com/).
  2. Navigate to the IAM & Admin page by clicking on the hamburger menu on the top left corner and selecting “IAM & Admin” from the menu.
  3. Select “Service accounts” from the left-hand menu.
  4. Locate the service account that has both admin and user permissions assigned to it.
  5. Click on the service account to view its details.
  6. Click on the “Permissions” tab to view the permissions assigned to the service account.
  7. Remove the admin permissions from the service account by clicking on the “Edit” button next to the role that has admin permissions assigned to it.
  8. Deselect the admin role and click “Save” to remove the admin permissions.
  9. Verify that the service account now only has user permissions assigned to it.
By following these steps, the misconfiguration “Service Accounts Admin And User Permissions Should Not Be Assigned At The Same Time” will be remediated for GCP.

To remediate the misconfiguration of assigning both Service Accounts Admin and User permissions at the same time in GCP using GCP CLI, follow these steps:
  1. Open the Google Cloud Shell from the GCP console.
  2. Run the following command to list all the IAM policies of the project:
Replace <PROJECT_ID> with the actual project ID.
  1. Identify the service account that has both Service Accounts Admin and User permissions assigned to it.
  2. Run the following command to remove the Service Accounts Admin role from the service account:
Replace <PROJECT_ID> with the actual project ID and <SERVICE_ACCOUNT_EMAIL> with the email address of the service account.
  1. Verify that the Service Accounts Admin role has been removed from the service account by running the following command:
Replace <PROJECT_ID> with the actual project ID and <SERVICE_ACCOUNT_EMAIL> with the email address of the service account.
  1. If the User role is still assigned to the service account, run the following command to remove it:
Replace <PROJECT_ID> with the actual project ID and <SERVICE_ACCOUNT_EMAIL> with the email address of the service account.
  1. Verify that the User role has been removed from the service account by running the following command:
Replace <PROJECT_ID> with the actual project ID and <SERVICE_ACCOUNT_EMAIL> with the email address of the service account.
  1. Repeat steps 3-7 for any other service accounts that have both Service Accounts Admin and User permissions assigned to them.
By following these steps, you will successfully remediate the misconfiguration of assigning both Service Accounts Admin and User permissions at the same time for GCP using GCP CLI.
To remediate the misconfiguration “Service Accounts Admin And User Permissions Should Not Be Assigned At The Same Time” in GCP using Python, follow these steps:
  1. Create a list of all the service accounts in your GCP project using the following code:
  1. For each service account in the list, check if it has both admin and user permissions assigned to it using the following code:
  1. If any service account has both admin and user permissions assigned to it, remove the user permissions using the following code:
Note: Replace “your-project-id” with the ID of your GCP project and “path/to/your/credentials.json” with the path to your GCP service account credentials file. Also, make sure that the credentials have the necessary permissions to manage service accounts in your GCP project.
If you are assigning these roles at the project (or folder/org) level instead of directly on the service account, ensure that any google_project_iam_*, google_folder_iam_*, or google_organization_iam_* resources that currently give roles/iam.serviceAccountAdmin to the same principal are removed, leaving at most roles/iam.serviceAccountUser.This change does not force replacement of the service account itself; it only updates IAM bindings. After editing, terraform plan should show that all roles/iam.serviceAccountAdmin bindings for affected principals are being destroyed and that only the intended roles/iam.serviceAccountUser (or other non-admin roles) remain.