GCP Introduction
GCP Pricing
GCP Threats
GCP Misconfigurations
- Getting Started with GCP Audit
- CloudSql Audit
- Cloud Tasks Monitoring
- Dataflow Monitoring
- Function Monitoring
- Monitoring Compliance
- PubSubLite Monitoring
- Spanner Monitoring
- NoSQL Monitoring
- Compute Audit
- IAM Audit
- BigQuery Monitoring
- CDN Monitoring
- DNS Monitoring
- KMS Monitoring
- Kubernetes Audit
- Load Balancer Monitoring
- Log Monitoring
- Storage Audit
- Pub/Sub Monitoring
- VPC Audit
- IAM Deep Dive
GCP Threats
Service Account User Should Not Have Service Account Token Creator Role
More Info:
Ensures that no users have the Service Account User role. The Service Account User role gives users the access to all service accounts of a project. This can result in an elevation of privileges and is not recommended.
Risk Level
Medium
Address
Security
Compliance Standards
CISGCP, CBP, HIPAA, ISO27001
Triage and Remediation
Remediation
To remediate the issue “Service Account User Should Not Have Service Account Token Creator Role” for GCP using GCP console, follow these steps:
- Login to your GCP console.
- Navigate to the IAM & admin page.
- Click on the “IAM” tab.
- Find the user account that has the “Service Account Token Creator” role assigned to it.
- Click on the edit icon (pencil) next to the user account.
- Scroll down to the “Service Account Actor” section.
- Find the service account that the user account is associated with.
- Click on the edit icon (pencil) next to the service account.
- Scroll down to the “Role” section.
- Find the “Service Account Token Creator” role and remove it from the list of assigned roles.
- Click on “Save” to save the changes.
After completing these steps, the user account will no longer have the “Service Account Token Creator” role assigned to it, which will remediate the misconfiguration.
To remediate the misconfiguration “Service Account User Should Not Have Service Account Token Creator Role” for GCP using GCP CLI, you can follow the below steps:
-
Open the GCP Cloud Shell by clicking on the Activate Cloud Shell button on the top right corner of the GCP console.
-
Run the following command to list all the service accounts in your GCP project:
gcloud iam service-accounts list
-
Select the service account that you want to remediate and note its email address.
-
Run the following command to list all the roles assigned to the service account:
gcloud projects get-iam-policy <project-id> --flatten="bindings[].members" --format='table(bindings.role)' --filter="bindings.members:<service-account-email>"
Replace <project-id>
with your GCP project ID and <service-account-email>
with the email address of the service account that you want to remediate.
-
Check if the service account has the
roles/iam.serviceAccountTokenCreator
role assigned to it. If yes, then it needs to be removed. -
Run the following command to remove the
roles/iam.serviceAccountTokenCreator
role from the service account:
gcloud projects remove-iam-policy-binding <project-id> --member="serviceAccount:<service-account-email>" --role="roles/iam.serviceAccountTokenCreator"
Replace <project-id>
with your GCP project ID and <service-account-email>
with the email address of the service account that you want to remediate.
- Verify that the
roles/iam.serviceAccountTokenCreator
role has been removed from the service account by running the command in step 4 again.
By following these steps, you can remediate the misconfiguration “Service Account User Should Not Have Service Account Token Creator Role” for GCP using GCP CLI.
To remediate the misconfiguration “Service Account User Should Not Have Service Account Token Creator Role” for GCP using Python, follow these steps:
-
First, you need to identify the service account user who has the Service Account Token Creator role. You can do this by running the following command in the Cloud Shell:
gcloud iam service-accounts list
-
Once you have identified the service account user, you need to remove the Service Account Token Creator role from the user. You can do this by running the following command in the Cloud Shell:
from google.oauth2 import service_account from googleapiclient.discovery import build credentials = service_account.Credentials.from_service_account_file('<path_to_service_account_key_file>') service = build('iam', 'v1', credentials=credentials) user_email = '<service_account_user_email>' project_id = '<project_id>' role_name = 'roles/iam.serviceAccountTokenCreator' policy = service.projects().getIamPolicy(resource=project_id, body={}).execute() for binding in policy['bindings']: if binding['role'] == role_name and user_email in binding['members']: binding['members'].remove(user_email) service.projects().setIamPolicy(resource=project_id, body={'policy': policy}).execute()
Note: Replace
<path_to_service_account_key_file>
,<service_account_user_email>
and<project_id>
with the appropriate values. -
Once you have run the above command, verify that the Service Account Token Creator role has been removed from the service account user by running the following command in the Cloud Shell:
gcloud projects get-iam-policy <project_id> --flatten="bindings[].members" --format='table(bindings.role)' --filter="bindings.members:<service_account_user_email>"
This should return an empty table, indicating that the user no longer has the Service Account Token Creator role.
-
Finally, you should review your organization’s IAM policies and best practices to ensure that service account users are not granted unnecessary permissions in the future.