Skip to content

Commit 31adc47

Browse files
committed
Add functionality to func
Signed-off-by: Ansuman Sahoo <anshumansahoo500@gmail.com>
1 parent b65f1bc commit 31adc47

File tree

3 files changed

+19
-34
lines changed

3 files changed

+19
-34
lines changed

pkg/driver/driver.go

-6
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ type Driver interface {
7171

7272
// GuestAgentConn returns the guest agent connection, or nil (if forwarded by ssh).
7373
GuestAgentConn(_ context.Context) (net.Conn, error)
74-
75-
CheckBinarySignature(_ context.Context, arch string) error
7674
}
7775

7876
type BaseDriver struct {
@@ -154,7 +152,3 @@ func (d *BaseDriver) GuestAgentConn(_ context.Context) (net.Conn, error) {
154152
// use the unix socket forwarded by host agent
155153
return nil, nil
156154
}
157-
158-
func (d *BaseDriver) CheckBinarySignature(_ context.Context, _ string) error {
159-
return errors.New("unimplemented")
160-
}

pkg/instance/start.go

-9
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"os"
1313
"os/exec"
1414
"path/filepath"
15-
"runtime"
1615
"syscall"
1716
"text/template"
1817
"time"
@@ -82,14 +81,6 @@ func Prepare(ctx context.Context, inst *store.Instance) (*Prepared, error) {
8281
Instance: inst,
8382
})
8483

85-
// Ask the user to sign the qemu binary with the "com.apple.security.hypervisor" if needed.
86-
// Workaround for https://github.com/lima-vm/lima/issues/1742
87-
if runtime.GOOS == "darwin" && inst.VMType == limayaml.QEMU {
88-
if err := limaDriver.CheckBinarySignature(ctx, inst.Arch); err != nil {
89-
return nil, err
90-
}
91-
}
92-
9384
if err := limaDriver.Validate(); err != nil {
9485
return nil, err
9586
}

pkg/qemu/qemu_driver.go

+19-19
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,25 @@ func New(driver *driver.BaseDriver) *LimaQemuDriver {
5050
}
5151

5252
func (l *LimaQemuDriver) Validate() error {
53+
// Ask the user to sign the qemu binary with the "com.apple.security.hypervisor" if needed.
54+
// Workaround for https://github.com/lima-vm/lima/issues/1742
55+
if runtime.GOOS == "darwin" && l.BaseDriver.Instance.VMType == limayaml.QEMU {
56+
macOSProductVersion, err := osutil.ProductVersion()
57+
if err != nil {
58+
return err
59+
}
60+
// The codesign --xml option is only available on macOS Monterey and later
61+
if !macOSProductVersion.LessThan(*semver.New("12.0.0")) {
62+
qExe, _, err := Exe(l.BaseDriver.Instance.Arch)
63+
if err != nil {
64+
return fmt.Errorf("failed to find the QEMU binary for the architecture %q: %w", l.BaseDriver.Instance.Arch, err)
65+
}
66+
if accel := Accel(l.BaseDriver.Instance.Arch); accel == "hvf" {
67+
entitlementutil.AskToSignIfNotSignedProperly(qExe)
68+
}
69+
}
70+
}
71+
5372
if *l.Instance.Config.MountType == limayaml.VIRTIOFS && runtime.GOOS != "linux" {
5473
return fmt.Errorf("field `mountType` must be %q or %q for QEMU driver on non-Linux, got %q",
5574
limayaml.REVSSHFS, limayaml.NINEP, *l.Instance.Config.MountType)
@@ -411,25 +430,6 @@ func (l *LimaQemuDriver) GuestAgentConn(ctx context.Context) (net.Conn, error) {
411430
return dialContext, err
412431
}
413432

414-
func (l *LimaQemuDriver) CheckBinarySignature(_ context.Context, arch string) error {
415-
macOSProductVersion, err := osutil.ProductVersion()
416-
if err != nil {
417-
return err
418-
}
419-
// The codesign --xml option is only available on macOS Monterey and later
420-
if !macOSProductVersion.LessThan(*semver.New("12.0.0")) {
421-
qExe, _, err := Exe(arch)
422-
if err != nil {
423-
return fmt.Errorf("failed to find the QEMU binary for the architecture %q: %w", arch, err)
424-
}
425-
if accel := Accel(arch); accel == "hvf" {
426-
entitlementutil.AskToSignIfNotSignedProperly(qExe)
427-
}
428-
}
429-
430-
return nil
431-
}
432-
433433
type qArgTemplateApplier struct {
434434
files []*os.File
435435
}

0 commit comments

Comments
 (0)