chef / ohai

Ohai profiles your system and emits JSON
https://docs.chef.io/ohai.html
Apache License 2.0
681 stars 450 forks source link

Detect QEMU virtualization on Darwin. #1813

Closed williamtheaker closed 1 year ago

williamtheaker commented 1 year ago

This PR adds a check for whether a Darwin machine is running as a QEMU guest.

Description

Apple added a Virtualization Framework based on QEMU to recent releases of macOS. This has resulted in many more options, such as UTM for organizations looking to run virtual macOS machines on Apple hardware.

One such organization appears to be Github, which seems to be adding Veertu VMs to their Github Actions runners. Unfortunately, Chef's virtual? helper fails to detect these machines as guests, since ohai isn't setting the role for QEMU VMs.

The XNU kernel added an Object ID named kern.hv_vmm_present, which returns 0 for physical hardware and 1 for virtual machines. This OID is present on x86 devices running macOS Big Sur (version 11) and all Apple ARM macOS devices. By shelling out to sysctl, we can use this OID to detect VMs.

Types of changes

Checklist:

sonarcloud[bot] commented 1 year ago

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication