@@ -21,12 +21,15 @@ import (
21
21
"text/template"
22
22
"time"
23
23
24
+ "github.com/coreos/go-semver/semver"
24
25
"github.com/digitalocean/go-qemu/qmp"
25
26
"github.com/digitalocean/go-qemu/qmp/raw"
26
27
"github.com/lima-vm/lima/pkg/driver"
27
28
"github.com/lima-vm/lima/pkg/executil"
28
29
"github.com/lima-vm/lima/pkg/limayaml"
29
30
"github.com/lima-vm/lima/pkg/networks/usernet"
31
+ "github.com/lima-vm/lima/pkg/osutil"
32
+ "github.com/lima-vm/lima/pkg/qemu/entitlementutil"
30
33
"github.com/lima-vm/lima/pkg/store"
31
34
"github.com/lima-vm/lima/pkg/store/filenames"
32
35
"github.com/sirupsen/logrus"
@@ -47,6 +50,10 @@ func New(driver *driver.BaseDriver) *LimaQemuDriver {
47
50
}
48
51
49
52
func (l * LimaQemuDriver ) Validate () error {
53
+ if runtime .GOOS == "darwin" {
54
+ l .checkBinarySignature ()
55
+ }
56
+
50
57
if * l .Instance .Config .MountType == limayaml .VIRTIOFS && runtime .GOOS != "linux" {
51
58
return fmt .Errorf ("field `mountType` must be %q or %q for QEMU driver on non-Linux, got %q" ,
52
59
limayaml .REVSSHFS , limayaml .NINEP , * l .Instance .Config .MountType )
@@ -233,6 +240,27 @@ func waitFileExists(path string, timeout time.Duration) error {
233
240
return nil
234
241
}
235
242
243
+ // Ask the user to sign the qemu binary with the "com.apple.security.hypervisor" if needed.
244
+ // Workaround for https://github.com/lima-vm/lima/issues/1742
245
+ func (l * LimaQemuDriver ) checkBinarySignature () error {
246
+ macOSProductVersion , err := osutil .ProductVersion ()
247
+ if err != nil {
248
+ return err
249
+ }
250
+ // The codesign --xml option is only available on macOS Monterey and later
251
+ if ! macOSProductVersion .LessThan (* semver .New ("12.0.0" )) {
252
+ qExe , _ , err := Exe (l .BaseDriver .Instance .Arch )
253
+ if err != nil {
254
+ return fmt .Errorf ("failed to find the QEMU binary for the architecture %q: %w" , l .BaseDriver .Instance .Arch , err )
255
+ }
256
+ if accel := Accel (l .BaseDriver .Instance .Arch ); accel == "hvf" {
257
+ entitlementutil .AskToSignIfNotSignedProperly (qExe )
258
+ }
259
+ }
260
+
261
+ return nil
262
+ }
263
+
236
264
func (l * LimaQemuDriver ) changeVNCPassword (password string ) error {
237
265
qmpSockPath := filepath .Join (l .Instance .Dir , filenames .QMPSock )
238
266
err := waitFileExists (qmpSockPath , 30 * time .Second )
0 commit comments