Ensure that Compute Engine virtual machine (VM) instances have the OS Config agent enabled and actively reporting operating system (OS) and patch inventory data to Google Cloud. The OS Config agent is a VM Manager component that, once installed and running inside the guest OS, collects data such as the OS version, kernel details, and installed packages approximately every 10 minutes and reports it through the OS Config Inventory API ("osconfig.googleapis.com"). For a VM instance to report this data, the OS Config API must be enabled for the project, and the "enable-osconfig" metadata key must be set to "TRUE", either at the project level (applies to all instances) or on the individual instance, which overrides the project-level setting.
Without OS Config agent reporting enabled, Google Cloud has no visibility into the operating system version, kernel, or installed packages running on your Compute Engine VM instances, making it impossible to determine whether a VM instance is missing critical OS updates. Enabling and verifying OS/patch inventory reporting is the prerequisite step for patch compliance visibility which calls for confirming that the latest operating system updates are installed across every VM instance in every project.
Note: Confirming that the OS Config agent is enabled and actively reporting inventory data verifies that patch compliance can be evaluated for a VM instance — it does not by itself confirm that the VM instance is already running the latest OS updates. Determining actual patch currency requires the separate Patch Compliance capability of VM Manager, which reads this reported inventory data to identify missing updates.
Audit
To determine if Compute Engine VM instances have the OS Config agent enabled and actively reporting OS inventory data, perform the following operations:
Note: The OS Config agent reports inventory data through the OS Config Inventory API, and the compute os-config inventories describe command used in this audit (step 11 below) reads that data through the same API. This is unaffected by the "Disable Guest Attributes of Compute Engine Metadata" organization policy (the compute.disableGuestAttributesAccess constraint).
If your organization or project enforces that policy, be aware that the older compute instances os-inventory describe command — which reads inventory data through the guest attributes endpoint instead — returns an error, even when the OS Config API is enabled, "enable-osconfig" is set to "TRUE" for the VM instance, and the OS Config agent is installed, running, and actively reporting. Use compute os-config inventories describe for this audit to avoid that error.
Remediation / Resolution
To enable the OS Config API and configure the "enable-osconfig" metadata so that the OS Config agent runs and reports OS inventory data for your Compute Engine VM instances, perform the following operations:
Note: Setting the "enable-osconfig" metadata key to "TRUE" does not, by itself, install the OS Config agent inside a VM instance's guest operating system — it only instructs Compute Engine that the agent should run. Every current Compute Engine public OS image (Debian, Ubuntu, CentOS, RHEL, SLES, Windows, and Container-Optimized OS) ships with the OS Config agent pre-installed, and the agent starts reporting automatically once the API is enabled and "enable-osconfig" is set to "TRUE". VM instances built from older or custom images that don't include the agent must have it installed manually before they can report inventory data.If the "Disable Guest Attributes of Compute Engine Metadata" organization policy (the
compute.disableGuestAttributesAccess constraint) is enforced for the project, organization, or folder, the steps below still resolve the issue — the OS Config agent's reporting mechanism does not depend on the guest attributes endpoint. Verify the result with compute os-config inventories describe (Remediation CLI step 7 below) rather than the older compute instances os-inventory describe command, which continues to return an error under that policy regardless of remediation.VM instances also need a service account attached with sufficient access (at minimum, the
https://www.googleapis.com/auth/cloud-platform scope, or an equivalent narrower scope covering osconfig.googleapis.com) for the OS Config agent to authenticate and report inventory data. Without one, the agent fails to obtain the identity token it needs and never reports, independent of the API/metadata configuration above or the organization policy — check the VM's serial console output for error getting token from metadata if inventory data still doesn't appear after allowing time for the agent's reporting cycle. References
- Google Cloud Platform (GCP) Documentation
- About VM Manager | Compute Engine | Google Cloud Documentation
- Set up VM Manager | Google Cloud Documentation
- OS inventory management | VM Manager | Google Cloud Documentation
- View OS inventory data | VM Manager | Google Cloud Documentation
- Verifying VM Manager setup | Google Cloud Documentation
- Setting and querying guest attributes | Compute Engine | Google Cloud Documentation
- CIS Security Documentation
- CIS Google Cloud Computing Platform Benchmarks
- GCP Command Line Interface (CLI) Documentation
- gcloud projects list | Google Cloud SDK | Google Cloud Documentation
- gcloud services list | Google Cloud SDK | Google Cloud Documentation
- gcloud services enable | Google Cloud SDK | Google Cloud Documentation
- gcloud compute project-info describe | Google Cloud SDK | Google Cloud Documentation
- gcloud compute project-info add-metadata | Google Cloud SDK | Google Cloud Documentation
- gcloud compute instances list | Google Cloud SDK | Google Cloud Documentation
- gcloud compute instances describe | Google Cloud SDK | Google Cloud Documentation
- gcloud compute instances add-metadata | Google Cloud SDK | Google Cloud Documentation
- gcloud compute instances remove-metadata | Google Cloud SDK | Google Cloud Documentation
- gcloud compute os-config inventories describe | Google Cloud SDK | Google Cloud Documentation
- gcloud compute instances os-inventory describe (legacy) | Google Cloud SDK | Google Cloud Documentation