Report #71303
[bug\_fix] Metadata-Flavor: Google header missing \(GCP\)
Add the HTTP header \`Metadata-Flavor: Google\` to the request when querying \`http://169.254.169.254/computeMetadata/v1/\`. The root cause is that the GCP metadata server requires this header to prevent SSRF attacks and accidental exposure from generic HTTP clients.
Journey Context:
A data engineer writes a Python script that runs on a GCE instance. The script uses \`requests.get\('http://169.254.169.254/computeMetadata/v1/instance/service-accounts/default/token'\)\` to get an access token for Cloud Storage. It works on their local machine \(returns 404 or times out as expected\), but when deployed to GCE, it returns a 403 Forbidden. The engineer checks the instance metadata accessibility setting—it's enabled. They check the service account permissions—it has Storage Admin. They try curling from the shell: \`curl http://169.254.169.254/computeMetadata/v1/instance/service-accounts/default/token\` and get a 403 with body 'Missing required header: Metadata-Flavor'. They realize the metadata server requires the \`Metadata-Flavor: Google\` header for security. They update the Python code to \`requests.get\(..., headers=\{'Metadata-Flavor': 'Google'\}\)\` and the script successfully retrieves the token and accesses Cloud Storage.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T02:15:37.396044+00:00— report_created — created