Professional Cloud Security Engineer
Prepare and test your skills
Prepare and test your skills
The Compute Engine metadata server provides virtual machines with critical configuration data and short-lived identity credentials at the link-local address 169.254.169.254. Securing this server requires strict network boundaries because unmonitored access can allow compromised workloads or external attackers to steal authorization tokens and exfiltrate data. Network administrators implement firewall rules and network policies to block unauthorized outbound pathways, keeping traffic strictly contained within the virtual private network. These network controls ensure that only authorized local processes can reach the metadata server to retrieve runtime attributes.
A Google Cloud architecture diagram showing a VM inside a VPC network querying the metadata server at link-local address 169.254.169.254, while firewall rules block SSRF attempts from the internet and a VPC Service Controls perimeter prevents stolen tokens from exfiltrating data to BigQuery or databases, with Security Command Center and Cloud Audit Logs monitoring access.
Validating connections to the metadata endpoint is necessary to prevent communication disruptions and defend against traffic redirection. Virtual machines use the default hostname metadata.google.internal, which must resolve directly to the link-local IP address 169.254.169.254 via the internal Domain Name System (DNS). Administrators verify network files such as /etc/resolv.conf and /etc/hosts to ensure name server settings remain correctly pointed to the internal metadata service. Properly validating these endpoints guarantees that metadata queries resolve securely without risk of routing tampering or service interception.
In addition to network protections, securing metadata requires enforcing strict identity boundaries and preventing credential misuse. Organizations apply the principle of least privilege by granting service accounts only the minimal permissions necessary for their workloads and disabling exportable service account keys. Cloud architects combine these controls with token exchange mechanisms and VPC Service Controls to establish secure perimeters around sensitive data. Restricting identity delegation and managing perimeter access prevents stolen metadata tokens from being used to access resources outside authorized project boundaries.
Security teams must maintain comprehensive visibility across their compute instances to detect metadata abuse and security policy deviations. Services such as Security Command Center and Cloud Audit Logs continuously monitor anomalous API calls, credential leaks, and modifications to network perimeters. Administrators track policy adherence by setting automated guardrails that prevent workloads from disabling sidecar proxies or bypassing firewall rules. Establishing continuous auditing and automated enforcement ensures that instance metadata configurations remain compliant and protected against data exfiltration.
Instance metadata is a critical component of cloud computing that provides compute instances with essential information about themselves and their environment. In Google Cloud, the metadata service is accessible at the reserved IP address 169.254.169.254 and contains sensitive data such as service account credentials, SSH keys, startup scripts, and network configuration. This metadata endpoint is designed to be accessed only by the instance itself, but misconfigurations or vulnerabilities can expose this sensitive information to unauthorized parties, leading to serious security breaches.
One of the most significant risks associated with instance metadata is credential theft, which occurs when attackers gain access to service account tokens stored in the metadata service. Attackers often use Server-Side Request Forgery (SSRF) techniques to trick applications into making requests to the metadata endpoint, allowing them to retrieve service account credentials. Once attackers obtain these credentials, they can impersonate service accounts, access other cloud resources, and potentially move laterally across the cloud environment. Security Command Center can detect anomalous access to the metadata service, such as the “Credential Access: Agent Engine Anomalous Access to Metadata Service” finding, which alerts administrators when an AI agent fetches a service account token from the metadata server.

A five-step process flow showing an attacker sending an SSRF request that tricks a vulnerable VM application into querying the metadata server at 169.254.169.254, which returns a service account token the attacker steals for impersonation, while Security Command Center and Cloud Audit Logs flag the anomalous access. The animation moves a request dot through the steps in order, highlighting each stage as it is reached.
Exploiting instance metadata can lead to privilege escalation and data breaches by allowing attackers to gain higher-level access than they originally had. When service account tokens are compromised, attackers can use them to perform actions with the privileges assigned to that service account, potentially accessing sensitive data or modifying cloud resources. Additionally, misconfigured firewall rules that allow internal access to the metadata service can enable attackers who have already gained some access to the network to reach the metadata endpoint. This creates a path for attackers to escalate their privileges and exfiltrate data from cloud storage or databases connected to the compromised instance.
To protect against metadata-related attacks, organizations should implement several security controls and best practices. Organizations can use VPC Service Controls to define perimeters that restrict access to the metadata service and other sensitive resources, preventing exfiltration of data outside the trusted environment. Additionally, organizations should avoid using long-lived service account keys when possible and instead rely on short-lived credentials obtained directly from the metadata service, which automatically expire and reduce the window of opportunity for attackers. Firewall rules should be configured to deny external access to the metadata endpoint, and applications should be designed to validate URLs and prevent SSRF vulnerabilities that could be used to access metadata.
Compute instance metadata is a critical system that stores configuration and operational data for virtual machines (VMs) in key-value pairs. This data is accessible via a metadata server that every VM can query without additional authorization. While metadata requests are confined to the physical host, any process that can reach the metadata server URL has access to all stored values, including sensitive custom data, client certificates, and private keys. Therefore, implementing robust security controls is essential to prevent unauthorized access and data exfiltration.
The primary security risk stems from the broad default accessibility of the metadata server. Since any application or script running on the VM can query it, a compromised application could leak sensitive information. To mitigate this, you must sandbox any process that should not have metadata access. Furthermore, access from outside the VM can be controlled using Identity and Access Management (IAM) . Key roles like Compute Instance Admin (v1) and Service Account User are required to view or modify custom metadata externally. Applying the principle of least privilege through IAM ensures that only authorized identities can manage metadata.
To protect sensitive data within metadata, you should exercise extreme caution when writing sensitive values like keys or certificates to the server. For enhanced security, especially for Shielded VMs, you can use the HTTPS metadata server endpoint (currently in Preview), which provides an encrypted channel for queries. A critical control is configuring Confidential Computing for VM metadata, which leverages hardware-based security features to protect data in use. Additionally, you can enable and manage metadata concealment to limit the exposure of certain metadata entries to processes on the VM.
For granular control, implement service account permissions to restrict what actions VMs can perform. Attach a dedicated service account with minimal necessary IAM roles to each VM instead of using the broad default service account. Combine this with restricting metadata access using IAM to manage who can set, view, or update metadata at the project, zone, or instance level. When querying metadata programmatically, always include the Metadata-Flavor: Google header. You should also design applications to handle potential metadata server disruptions, such as during host maintenance events, by implementing retry logic for queries that may return transient errors.
Attackers typically target the Compute Engine metadata server through Server-Side Request Forgery (SSRF) techniques or misconfigured internal firewall rules to extract service account credentials, SSH keys, and configuration data. With these retrieved tokens, attackers can impersonate service accounts, escalate privileges, move laterally across cloud resources, and exfiltrate sensitive data.
Managing custom metadata externally requires the Compute Instance Admin (v1) and Service Account User roles. Enforcing the principle of least privilege with these roles ensures that only authorized identities can view, set, or update metadata at the project, zone, or instance level.
Organizations can protect metadata by enforcing VPC Service Controls perimeters, configuring firewall rules to block external access, and sandboxing local processes that do not need access. Additional controls include using the HTTPS metadata server endpoint for Shielded VMs, configuring Confidential Computing for VM metadata, managing metadata concealment, and including the Metadata-Flavor: Google header in programmatic requests.
A financial enterprise is hardening its Compute Engine infrastructure in Google Cloud. Security auditors found that developers have excessive privileges that allow them to view and modify sensitive custom instance metadata keys and deploy instances using privileged workload identities.
The security engineer must implement least-privilege access controls with the following requirements:
iam.serviceAccounts.actAs).Which configuration should the security engineer implement?
Grant developers roles/compute.viewer combined with roles/iam.serviceAccountAdmin on the service account, and enforce access tokens with https://www.googleapis.com/auth/devstorage.read_only scope.
Grant developers roles/compute.securityAdmin on the project, assign iam.serviceAccounts.actAs directly to developers on the project root, and disable the metadata server via firewall rules.
Grant developers a role with compute.instances.get on the VM instances, do not grant roles/iam.serviceAccountUser, and set the https://www.googleapis.com/auth/cloud-platform access scope on instances while restricting workload permissions strictly via IAM roles on the attached service account.
Grant developers the predefined roles/compute.instanceAdmin.v1 and roles/iam.serviceAccountUser roles at the project level, and configure VM instances with the restricted https://www.googleapis.com/auth/compute.readonly access scope.