Restricted VM networking

This commit is contained in:
AlexSSD7 2023-08-26 16:43:04 +01:00
commit 34e66cb01c
5 changed files with 31 additions and 27 deletions

View file

@ -7,7 +7,6 @@ import (
"os"
"os/signal"
"os/user"
"strings"
"sync"
"syscall"
@ -38,7 +37,7 @@ func doRootCheck() {
}
}
func runVM(passthroughArg string, fn func(context.Context, *vm.Instance, *vm.FileManager) int, forwardPorts []vm.PortForwardingConfig) int {
func runVM(passthroughArg string, fn func(context.Context, *vm.Instance, *vm.FileManager) int, forwardPorts []vm.PortForwardingConfig, unrestrictedNetworking bool) int {
doRootCheck()
var passthroughConfig []vm.USBDevicePassthroughConfig
@ -47,26 +46,8 @@ func runVM(passthroughArg string, fn func(context.Context, *vm.Instance, *vm.Fil
passthroughConfig = []vm.USBDevicePassthroughConfig{getDevicePassthroughConfig(passthroughArg)}
}
var forwardPortsConfig []vm.PortForwardingConfig
for i, fp := range strings.Split(forwardPortsFlagStr, ",") {
if fp == "" {
continue
}
fpc, err := vm.ParsePortForwardString(fp)
if err != nil {
slog.Error("Failed to parse port forward string", "index", i, "value", fp, "error", err)
os.Exit(1)
}
forwardPortsConfig = append(forwardPortsConfig, fpc)
}
forwardPortsConfig = append(forwardPortsConfig, forwardPorts...)
// TODO: Alpine image should be downloaded from somewhere.
vi, err := vm.NewInstance(slog.Default().With("caller", "vm"), "alpine-img/alpine.qcow2", passthroughConfig, vmDebugFlag, forwardPortsConfig)
vi, err := vm.NewInstance(slog.Default().With("caller", "vm"), "alpine-img/alpine.qcow2", passthroughConfig, vmDebugFlag, forwardPorts, unrestrictedNetworking)
if err != nil {
slog.Error("Failed to create vm instance", "error", err)
os.Exit(1)