Skip to content

Commit a209cfb

Browse files
authored
Merge pull request #16714 from spowelljr/unblock
qemu on maos :Auto unblock bootpd from firewall for socket_vmnet network driver
2 parents 3c72c78 + 29a3258 commit a209cfb

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

cmd/minikube/cmd/start.go

+70
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,8 @@ func provisionWithDriver(cmd *cobra.Command, ds registry.DriverState, existing *
339339
return node.Starter{}, errors.Wrap(err, "Failed to generate config")
340340
}
341341

342+
unblockBootpdFirewall(cc)
343+
342344
if driver.IsVM(cc.Driver) && runtime.GOARCH == "arm64" && cc.KubernetesConfig.ContainerRuntime == "crio" {
343345
exit.Message(reason.Unimplemented, "arm64 VM drivers do not currently support the crio container runtime. See https://github.com/kubernetes/minikube/issues/14146 for details.")
344346
}
@@ -414,6 +416,74 @@ func vmwareUnsupported(driverName string) {
414416
`)
415417
}
416418

419+
// isBootpdBlocked returns true if the built-in macOS firewall is on and bootpd is not unblocked
420+
func isBootpdBlocked(cc config.ClusterConfig) bool {
421+
// only applies to qemu, on macOS, with socket_vmnet
422+
if cc.Driver != driver.QEMU2 || runtime.GOOS != "darwin" || cc.Network != "socket_vmnet" {
423+
return false
424+
}
425+
out, err := exec.Command("/usr/libexec/ApplicationFirewall/socketfilterfw", "--getglobalstate").Output()
426+
if err != nil {
427+
klog.Warningf("failed to get firewall state: %v", err)
428+
return false
429+
}
430+
if !strings.Contains(string(out), "Firewall is enabled") {
431+
return false
432+
}
433+
out, err = exec.Command("/usr/libexec/ApplicationFirewall/socketfilterfw", "--listapps").Output()
434+
if err != nil {
435+
klog.Warningf("failed to list firewall apps: %v", err)
436+
return false
437+
}
438+
if !strings.Contains(string(out), "/usr/libexec/bootpd") {
439+
return true
440+
}
441+
parts := strings.Split(string(out), `/usr/libexec/bootpd
442+
( `)
443+
// if bootpd is not in application list it's blocked
444+
if len(parts) == 1 {
445+
return true
446+
}
447+
448+
return strings.HasPrefix(parts[1], "Block")
449+
}
450+
451+
// unblockBootpdFirewall adds bootpd to the built-in macOS firewall and then unblocks it
452+
func unblockBootpdFirewall(cc config.ClusterConfig) {
453+
if !isBootpdBlocked(cc) {
454+
return
455+
}
456+
457+
cmds := []*exec.Cmd{
458+
exec.Command("sudo", "/usr/libexec/ApplicationFirewall/socketfilterfw", "--add", "/usr/libexec/bootpd"),
459+
exec.Command("sudo", "/usr/libexec/ApplicationFirewall/socketfilterfw", "--unblock", "/usr/libexec/bootpd"),
460+
}
461+
462+
var cmdString strings.Builder
463+
for _, c := range cmds {
464+
cmdString.WriteString(fmt.Sprintf(" $ %s \n", strings.Join(c.Args, " ")))
465+
}
466+
467+
out.Styled(style.Permissions, "Your firewall is blocking bootpd which is required for socket_vmnet. The following commands will be executed to unblock bootpd:\n\n{{.commands}}\n", out.V{"commands": cmdString.String()})
468+
469+
for _, c := range cmds {
470+
testArgs := append([]string{"-n"}, c.Args[1:]...)
471+
test := exec.Command("sudo", testArgs...)
472+
klog.Infof("testing: %s", test.Args)
473+
if err := test.Run(); err != nil {
474+
klog.Infof("%v may require a password: %v", c.Args, err)
475+
if !viper.GetBool("interactive") {
476+
klog.Warningf("%s requires a password, and --interactive=false", c.Args)
477+
}
478+
}
479+
klog.Infof("running: %s", c.Args)
480+
err := c.Run()
481+
if err != nil {
482+
klog.Warningf("running %s failed: %v", c.Args, err)
483+
}
484+
}
485+
}
486+
417487
func validateBuiltImageVersion(r command.Runner, driverName string) {
418488
if driver.IsNone(driverName) {
419489
return

0 commit comments

Comments
 (0)