Skip to content

Commit

Permalink
Virt-v2v: read LUKS keys
Browse files Browse the repository at this point in the history
This patch will read the given LUKS key provided to the container and
add them as arguments to the virt-v2v command. Since virt-v2v supports
this feature only since 2.2, it applies only for cold migrations.
It uses the `all` selector to each passphrase.

Signed-off-by: Liran Rotenberg <[email protected]>
  • Loading branch information
liranr23 authored and ahadas committed Jun 9, 2024
1 parent 8e35a72 commit 5b83355
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions virt-v2v/cold/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const (
FS = "/mnt/disks/disk[0-9]*"
Block = "/dev/block[0-9]*"
VDDK = "/opt/vmware-vix-disklib-distrib"
LUKSDIR = "/etc/luks"
)

var (
Expand Down Expand Up @@ -128,6 +129,23 @@ func buildCommand() []string {
virtV2vArgs = append(virtV2vArgs, "--mac", macToIp)
}
}
// Adds LUKS keys, if exist.
if _, err := os.Stat(LUKSDIR); os.IsNotExist(err) {
// do nothing
} else {
if err != nil {
fmt.Println("Error accessing the LUKS directory ", err)
os.Exit(1)
}
files, err := getFilesInPath(LUKSDIR)
if err != nil {
fmt.Println("Error reading files in LUKS directory ", err)
os.Exit(1)
}
for _, file := range files {
virtV2vArgs = append(virtV2vArgs, "--key", fmt.Sprintf("all:file:%s", file))
}
}

if info, err := os.Stat(VDDK); err == nil && info.IsDir() {
virtV2vArgs = append(virtV2vArgs,
Expand All @@ -141,6 +159,20 @@ func buildCommand() []string {
return virtV2vArgs
}

func getFilesInPath(rootPath string) (paths []string, err error) {
files, err := os.ReadDir(rootPath)
if err != nil {
fmt.Println("Error reading the files in the directory ", err)
return
}
for _, file := range files {
if !file.IsDir() && !strings.HasPrefix(file.Name(), "..") {
paths = append(paths, fmt.Sprintf("%s/%s", rootPath, file.Name()))
}
}
return
}

func checkEnvVariablesSet(envVars ...string) bool {
for _, v := range envVars {
if os.Getenv(v) == "" {
Expand Down

0 comments on commit 5b83355

Please sign in to comment.