From fd19f8017cd844ba6942759ed3a494bec681b790 Mon Sep 17 00:00:00 2001 From: Javier de la Puente Date: Fri, 9 Aug 2024 18:24:22 +0200 Subject: [PATCH] Fix LXD cloud init images and add profiles LXD profiles are useful to define the characteristic of the LXD container, and also to use privileged containers. Regarding sshd_config.d, it is necessary as new cloud images set no password in these images, and ssh with a password does not work. --- spread/lxd.go | 9 ++++++++- spread/project.go | 3 +++ tests/lxd/spread.yaml | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/spread/lxd.go b/spread/lxd.go index 2cbf9974..eb16cf38 100644 --- a/spread/lxd.go +++ b/spread/lxd.go @@ -4,7 +4,6 @@ import ( "bytes" "encoding/json" "fmt" - "gopkg.in/yaml.v2" "io/ioutil" "os" "os/exec" @@ -15,6 +14,8 @@ import ( "syscall" "time" + "gopkg.in/yaml.v2" + "golang.org/x/net/context" ) @@ -111,6 +112,11 @@ func (p *lxdProvider) Allocate(ctx context.Context, system *System) (Server, err if !p.options.Reuse { args = append(args, "--ephemeral") } + if system != nil { + for _, profile := range system.Profiles { + args = append(args, "-p", profile) + } + } output, err := exec.Command("lxc", args...).CombinedOutput() if err != nil { err = outputErr(output, err) @@ -482,6 +488,7 @@ func (p *lxdProvider) serverJSON(name string) (*lxdServerJSON, error) { func (p *lxdProvider) tuneSSH(name string) error { cmds := [][]string{ {"sed", "-i", `s/^\s*#\?\s*\(PermitRootLogin\|PasswordAuthentication\)\>.*/\1 yes/`, "/etc/ssh/sshd_config"}, + {"bash", "-c", `sed -i "s/^\s*#\?\s*\(PermitRootLogin\|PasswordAuthentication\)\>.*/\1 yes/" /etc/ssh/sshd_config.d/* || :`}, {"/bin/bash", "-c", fmt.Sprintf("echo root:'%s' | chpasswd", p.options.Password)}, {"killall", "-HUP", "sshd"}, } diff --git a/spread/project.go b/spread/project.go index e70470f0..730f4beb 100644 --- a/spread/project.go +++ b/spread/project.go @@ -125,6 +125,9 @@ type System struct { // Only for Google so far. SecureBoot bool `yaml:"secure-boot"` + // List of profiles, only for LXD + Profiles []string + // Supported are {"uefi",""}, only for qemu so far. Bios string // Request a specific CPU family, e.g. "Intel Skylake" The diff --git a/tests/lxd/spread.yaml b/tests/lxd/spread.yaml index cb46b05d..4ab6cc95 100644 --- a/tests/lxd/spread.yaml +++ b/tests/lxd/spread.yaml @@ -3,7 +3,7 @@ project: spread backends: lxd: systems: - - ubuntu-16.04 + - ubuntu-24.04 path: /home/test