Skip to main content

Triage and Remediation

Remediation

Using Console

To remediate the misconfiguration “Disable User-Managed Key Creation for Service Accounts” for GCP using GCP console, please follow the below steps:
  1. Open the GCP Console and navigate to the IAM & Admin page.
  2. Click on the “Service Accounts” tab.
  3. Select the Service Account for which you want to disable User-Managed Key Creation.
  4. Click on the “Edit” button in the Service Account details page.
  5. Scroll down to the “Key Management” section and click on the “Show More” link.
  6. Under the “Key Management” section, you will see an option “User-managed keys”. Disable this option.
  7. Click on the “Save” button to save the changes.
By following these steps, you will successfully remediate the misconfiguration “Disable User-Managed Key Creation for Service Accounts” for GCP using GCP console.

To remediate the misconfiguration “Disable User-Managed Key Creation for Service Accounts” for GCP using GCP CLI, follow the below steps:Step 1: Open the Google Cloud Shell or Terminal window.Step 2: Run the following command to check the current status of User-Managed Key Creation for Service Accounts:
Replace [SERVICE_ACCOUNT_EMAIL] with the email address of the service account for which you want to check the User-Managed Key Creation status.Step 3: Open the policy.json file in an editor and check the “bindings” section for the following entry:
If this entry is present, it means that User-Managed Key Creation is enabled for the service account.Step 4: To disable User-Managed Key Creation, run the following command:
Replace [SERVICE_ACCOUNT_EMAIL] with the email address of the service account for which you want to disable User-Managed Key Creation.Step 5: Open the policy.json file in an editor and remove the following entry from the “bindings” section:
Step 6: Save the policy.json file and run the following command to update the policy for the service account:
Replace [SERVICE_ACCOUNT_EMAIL] with the email address of the service account for which you want to update the policy.After following these steps, User-Managed Key Creation will be disabled for the specified service account.
To remediate the misconfiguration “Disable User-Managed Key Creation for Service Accounts” in GCP using Python, follow these steps:
  1. Import the required libraries:
  1. Set up the credentials for the service account that has the necessary permissions to make changes to the GCP project:
  1. Create a ServiceUsage client object:
  1. Retrieve the current state of the iam.googleapis.com service:
  1. Check if user-managed keys are currently allowed for service accounts:
  1. If user-managed keys are currently allowed, update the service configuration to disable them:
Note: Replace PROJECT_ID with the ID of the GCP project you want to remediate. Also, make sure that the service account key file (service_account_key.json) has the necessary permissions to make changes to the GCP project.
This change is in-place and does not force replacement of existing projects/folders/organizations, but it will immediately block creation of new user-managed service account keys in the scoped resources.Verification: terraform plan should show a new google_*_organization_policy resource with constraint = "constraints/iam.disableServiceAccountKeyCreation" and boolean_policy.enforced = true.