@@ -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"
@@ -54,6 +57,12 @@ func New(driver *driver.BaseDriver) *LimaQemuDriver {
54
57
}
55
58
56
59
func (l * LimaQemuDriver ) Validate () error {
60
+ if runtime .GOOS == "darwin" {
61
+ if err := l .checkBinarySignature (); err != nil {
62
+ return err
63
+ }
64
+ }
65
+
57
66
if * l .Instance .Config .MountType == limayaml .VIRTIOFS && runtime .GOOS != "linux" {
58
67
return fmt .Errorf ("field `mountType` must be %q or %q for QEMU driver on non-Linux, got %q" ,
59
68
limayaml .REVSSHFS , limayaml .NINEP , * l .Instance .Config .MountType )
@@ -241,6 +250,27 @@ func waitFileExists(path string, timeout time.Duration) error {
241
250
return nil
242
251
}
243
252
253
+ // Ask the user to sign the qemu binary with the "com.apple.security.hypervisor" if needed.
254
+ // Workaround for https://github.com/lima-vm/lima/issues/1742
255
+ func (l * LimaQemuDriver ) checkBinarySignature () error {
256
+ macOSProductVersion , err := osutil .ProductVersion ()
257
+ if err != nil {
258
+ return err
259
+ }
260
+ // The codesign --xml option is only available on macOS Monterey and later
261
+ if ! macOSProductVersion .LessThan (* semver .New ("12.0.0" )) {
262
+ qExe , _ , err := Exe (l .BaseDriver .Instance .Arch )
263
+ if err != nil {
264
+ return fmt .Errorf ("failed to find the QEMU binary for the architecture %q: %w" , l .BaseDriver .Instance .Arch , err )
265
+ }
266
+ if accel := Accel (l .BaseDriver .Instance .Arch ); accel == "hvf" {
267
+ entitlementutil .AskToSignIfNotSignedProperly (qExe )
268
+ }
269
+ }
270
+
271
+ return nil
272
+ }
273
+
244
274
func (l * LimaQemuDriver ) changeVNCPassword (password string ) error {
245
275
qmpSockPath := filepath .Join (l .Instance .Dir , filenames .QMPSock )
246
276
err := waitFileExists (qmpSockPath , 30 * time .Second )
0 commit comments