Allow opening LUKS containers inside linsk ls

This commit is contained in:
AlexSSD7 2023-09-27 16:57:23 +01:00
commit 0fea76d273
4 changed files with 135 additions and 52 deletions

View file

@ -35,24 +35,13 @@ var runCmd = &cobra.Command{
Short: "Start a VM and expose an FTP file share.",
Args: cobra.RangeArgs(1, 3),
Run: func(cmd *cobra.Command, args []string) {
var luksContainerDevice string
configureVMRuntimeFlags()
vmMountDevName := "vdb"
if luksContainerFlag != "" {
if luksContainerEntireDriveFlag {
slog.Error("--luks-container and --luks-container-entire-drive (-c) cannot be both specified at once")
os.Exit(1)
}
luksContainerDevice = luksContainerFlag
} else if luksContainerEntireDriveFlag {
luksContainerDevice = vmMountDevName
}
vmMountDevName := defaultVMMountDevName
if len(args) > 1 {
vmMountDevName = args[1]
} else if luksContainerDevice != "" {
} else if vmRuntimeLUKSContainerDevice != "" {
slog.Error("Cannot use the default (entire) device with a LUKS container. Please specify the in-VM device name to mount as a second positional argument.")
}
@ -84,16 +73,6 @@ var runCmd = &cobra.Command{
os.Exit(1)
}
if (luksFlag || luksContainerDevice != "") && !allowLUKSLowMemoryFlag {
if vmMemAllocFlag < defaultMemAllocLUKS {
if vmMemAllocFlag != defaultMemAlloc {
slog.Warn("Enforcing minimum LUKS memory allocation. Please add --allow-luks-low-memory to disable this.", "min", vmMemAllocFlag, "specified", vmMemAllocFlag)
}
vmMemAllocFlag = defaultMemAllocLUKS
}
}
os.Exit(runVM(args[0], func(ctx context.Context, i *vm.VM, fm *vm.FileManager, tapCtx *share.NetTapRuntimeContext) int {
fsToLog := "<auto>"
if fsTypeOverride != "" {
@ -103,7 +82,7 @@ var runCmd = &cobra.Command{
slog.Info("Mounting the device", "dev", vmMountDevName, "fs", fsToLog, "luks", luksFlag)
err := fm.Mount(vmMountDevName, vm.MountOptions{
LUKSContainerPreopen: luksContainerDevice,
LUKSContainerPreopen: vmRuntimeLUKSContainerDevice,
FSTypeOverride: fsTypeOverride,
LUKS: luksFlag,
@ -157,24 +136,20 @@ var runCmd = &cobra.Command{
}
var (
luksFlag bool
luksContainerFlag string
luksContainerEntireDriveFlag bool
allowLUKSLowMemoryFlag bool
shareListenIPFlag string
ftpExtIPFlag string
shareBackendFlag string
smbUseExternAddrFlag bool
debugShellFlag bool
luksFlag bool
shareListenIPFlag string
ftpExtIPFlag string
shareBackendFlag string
smbUseExternAddrFlag bool
debugShellFlag bool
)
func init() {
runCmd.Flags().BoolVarP(&luksFlag, "luks", "l", false, "Use cryptsetup to open a LUKS volume (password will be prompted).")
runCmd.Flags().StringVar(&luksContainerFlag, "luks-container", "", `Specifies a device path (without "dev/" prefix) to preopen as a LUKS container (password will be prompted). Useful for accessing LVM partitions behind LUKS.`)
runCmd.Flags().BoolVarP(&luksContainerEntireDriveFlag, "luks-container-entire-drive", "c", false, `Similar to --luks-container, but this assumes that the entire passed-through volume is a LUKS container (password will be prompted).`)
runCmd.Flags().BoolVar(&allowLUKSLowMemoryFlag, "allow-luks-low-memory", false, "Allow VM memory allocation lower than 2048 MiB when LUKS is enabled.")
runCmd.Flags().BoolVar(&debugShellFlag, "debug-shell", false, "Start a VM shell when the network file share is active.")
initVMRuntimeFlags(runCmd.Flags())
var defaultShareType string
switch {
case osspecifics.IsMacOS():