Skip to main content

More Info:

Ensures Kubernetes clusters are created with limited service account access scopes. Kubernetes service accounts should be limited in scope to the services necessary to operate the clusters.

Risk Level

Medium

Address

Security

Compliance Standards

  • CIS GCP

Triage and Remediation

Remediation

Using Console

To remediate the misconfiguration “Cluster Should Have Limited Service Account Access” for GCP using GCP console, follow these steps:
  1. Open the Google Kubernetes Engine (GKE) console.
  2. Select the cluster that needs to be remediated.
  3. Click on the “Security” tab.
  4. Scroll down to the “Service Accounts” section.
  5. Click on the “Edit” button.
  6. In the “Service Accounts” section, select the option “Limit service account access to this cluster”.
  7. Select the service account that needs access to the cluster.
  8. Click on the “Save” button to save the changes.
By following these steps, the cluster will have limited service account access and only the selected service account will have access to the cluster.

To remediate the misconfiguration “Cluster Should Have Limited Service Account Access” for GCP using GCP CLI, you can follow the below steps:Step 1: Open the Cloud Shell from the GCP console or install the GCP CLI on your local machine.Step 2: Authenticate with your GCP account using the below command:
Step 3: Set the project where the cluster is located using the below command:
Step 4: Get the name of the cluster that needs to be remediated using the below command:
Step 5: Fetch the current IAM policy for the cluster using the below command:
Step 6: Identify the service accounts that have access to the cluster and need to be removed from the IAM policy.Step 7: Remove the service accounts from the IAM policy using the below command:
Step 8: Verify the changes by fetching the updated IAM policy using the below command:
By following these steps, you can remediate the misconfiguration “Cluster Should Have Limited Service Account Access” for GCP using GCP CLI.
To remediate the misconfiguration “Cluster Should Have Limited Service Account Access” for GCP using Python, follow these steps:
  1. Install the required libraries:
  2. Authenticate to GCP:
  3. Retrieve the cluster object:
  4. Update the cluster’s master_auth field to limit service account access:
  5. Verify that the update was successful:
Note: The above steps assume that you have a GCP service account with sufficient permissions to access the cluster. Replace the placeholders (<...>) with your own values.
Changing oauth_scopes on the default node configuration forces replacement of the default node pool, which is disruptive and can cause an outage if not coordinated (or the whole cluster if using an in-place default).For verification, terraform plan should show the old broad scope (typically including https://www.googleapis.com/auth/cloud-platform) being removed and only the limited list of oauth_scopes being added, along with a recreate of the affected node pool.

Additional Reading: