Skip to main content

Triage and Remediation

Remediation

Using Console

To remediate the misconfiguration “Ensure Legacy Compute Engine Instance Metadata APIs Are Disabled” for GCP using GCP console, follow the below steps:
  1. Open the Google Cloud Console and select your project.
  2. Navigate to the Compute Engine page from the left-hand menu.
  3. From the Compute Engine page, select the “Metadata” tab.
  4. Under the “Metadata” tab, click on the “Edit” button.
  5. Scroll down to the “Legacy Metadata Access” section.
  6. Select the “Disallow” option to disable the legacy metadata access.
  7. Click on the “Save” button to save the changes.
Once you have completed these steps, the legacy Compute Engine instance metadata APIs will be disabled, and your GCP environment will be more secure.

To remediate the misconfiguration “Ensure Legacy Compute Engine Instance Metadata APIs Are Disabled” for GCP using GCP CLI, follow the below steps:
  1. Open the GCP Cloud Shell and run the following command to disable the legacy metadata APIs:
Here, replace [INSTANCE_NAME] with the name of the instance for which you want to disable the legacy metadata APIs.
  1. Verify the change by running the following command:
This should output “true” which indicates that the legacy metadata APIs are now disabled.
  1. Repeat the above steps for all the instances in your GCP project to ensure that the legacy metadata APIs are disabled for all instances.
Note: It is recommended to use the latest metadata APIs instead of the legacy ones for better security and performance.
To remediate the misconfiguration “Ensure Legacy Compute Engine Instance Metadata APIs Are Disabled” for GCP using Python, you can use the following steps:
  1. Import the necessary Python libraries:
  1. Authenticate and authorize your credentials:
  1. Get the project ID:
  1. Get the instance name:
  1. Get the instance metadata:
  1. Check if the legacy metadata APIs are enabled:
  1. If the legacy metadata APIs are enabled, remove the ‘enable-guest-attributes’ key from the metadata and update the instance metadata with the new metadata:
  1. If the legacy metadata APIs are already disabled, print a message indicating that they are already disabled:
Note: Replace YOUR_PROJECT_ID and YOUR_INSTANCE_NAME with your actual project ID and instance name respectively. Also, replace the zone variable with the appropriate zone for your instance.
If you manage node pools separately instead of using the default pool on google_container_cluster, put the setting on each google_container_node_pool instead:
Changing node_config.metadata in this way causes the nodes in the affected node pool(s) to be recreated (a rolling node replacement; pods will be rescheduled but the cluster itself is not destroyed).Verification: terraform plan should show an update to the relevant google_container_cluster and/or google_container_node_pool resources adding metadata.disable-legacy-endpoints = "true" and no other unexpected changes.