Skip to main content

Triage and Remediation

Remediation

Using Console

To remediate the misconfiguration of API keys not being created for a project in GCP, you can follow the below steps using the GCP console:
  1. Go to the GCP console and select the project for which you want to remediate the misconfiguration.
  2. Navigate to the “APIs & Services” section from the left-hand side menu.
  3. Click on the “Credentials” tab from the top menu.
  4. On the Credentials page, you will see a list of all the existing credentials for the project.
  5. Look for any API keys that have been created for the project. If you find any, select them and click on the “Delete” button to remove them.
  6. If there are no API keys, then the misconfiguration is already remediated.
  7. To prevent API keys from being created in the future, you can go to the “APIs & Services” section and click on the “Restrict keys” button.
  8. On the Restrict keys page, select the “Do not restrict key” option and click on the “Save” button.
  9. This will prevent any API keys from being created for the project in the future.
By following these steps, you can remediate the misconfiguration of API keys not being created for a project in GCP.

To remediate the misconfiguration “Ensure API Keys Are Not Created For A Project” for GCP using GCP CLI, follow these steps:
  1. Open the Cloud Shell in the GCP Console.
  2. Run the following command to list all the projects in your GCP account:
  1. Select the project for which you want to ensure that API keys are not created.
  2. Run the following command to check if any API keys are created for the selected project:
Note: Replace [SA-NAME] with the name of the service account and [PROJECT-ID] with the ID of the selected project.
  1. If any API keys are listed, delete them using the following command:
Note: Replace [KEY-ID] with the ID of the API key you want to delete, [SA-NAME] with the name of the service account and [PROJECT-ID] with the ID of the selected project.
  1. Repeat steps 4 and 5 for all the service accounts in the selected project.
  2. Once all the API keys are deleted, ensure that the service accounts are not granted any unnecessary permissions.
  3. Verify that no API keys are created for the selected project using the following command:
Note: Replace [SA-NAME] with the name of the service account and [PROJECT-ID] with the ID of the selected project.
  1. If no API keys are listed, the remediation is complete.
To remediate the issue of ensuring API keys are not created for a project in GCP, you can use the following steps using Python:
  1. First, authenticate to your GCP project using the google-auth library. You can install it using pip:
  1. Next, use the google-cloud-resource-manager library to retrieve the list of all projects in your GCP account. You can install it using pip:
  1. Once you have the list of projects, loop through each project and check if there are any active API keys associated with it. You can use the google-cloud-kms library to list the keys associated with a project:
  1. If you find any active API keys associated with a project, you can delete them using the google-cloud-kms library:
  1. Finally, you can revoke the API key using the google-auth library:
By following these steps, you can ensure that API keys are not created for a project in GCP and remediate any existing misconfigurations.
This uses the apikeys.allowedKeyCreators organization policy at the project level to block creation of any new API keys in the project; existing API keys are not automatically deleted by this policy.This change does not force replacement of the project itself, only creates/updates the org policy.Verification: terraform plan should show a single google_org_policy_policy.no_api_keys_for_project resource being created (or updated) with deny_all = true for the apikeys.allowedKeyCreators constraint.