Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions pkg/machine/e2e/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package e2e_test
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"runtime"
"strconv"
Expand Down Expand Up @@ -733,6 +734,24 @@ var _ = Describe("podman machine init", func() {
Expect(p).To(Equal(l.VMType))
}
})

It("init with read-only image should succeed", func() {
// Step 1: create temp image
img := filepath.Join(GinkgoT().TempDir(),"test.qcow2")

// Step 2: copy existing image
exec.Command("cp", mb.imagePath, img).Run()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe using install here is more efficient?


// Step 3: make it read-only
exec.Command("chmod", "444", img).Run()

// Step 4: run podman machine init
i := new(initMachine)
session, err := mb.setCmd(i.withImage(img)).run()

Expect(err).To(BeNil())
Expect(session).To(Exit(0))
})
})

var p4Config = []byte(`{
Expand Down
14 changes: 13 additions & 1 deletion pkg/machine/stdpull/local.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package stdpull

import (
"fmt"
"os"

"github.com/containers/podman/v6/pkg/machine/compression"
"github.com/containers/podman/v6/pkg/machine/define"
"github.com/sirupsen/logrus"
Expand All @@ -26,5 +29,14 @@ func (s *StdDiskPull) Get() error {
return err
}
logrus.Debugf("decompressing (if needed) %s to %s", s.inputPath.GetPath(), s.finalPath.GetPath())
return compression.Decompress(s.inputPath, s.finalPath.GetPath())
if err := compression.Decompress(s.inputPath, s.finalPath.GetPath()); err != nil {
return err
}

// Ensure image is writable
if err := os.Chmod(s.finalPath.GetPath(), 0600); err != nil {
return fmt.Errorf("failed to set permissions on machine image: %w", err)
}
return nil

}
11 changes: 10 additions & 1 deletion pkg/machine/stdpull/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,16 @@ func (d *DiskFromURL) Get() error {
}

logrus.Debugf("decompressing (if needed) %s to %s", d.tempLocation.GetPath(), d.finalPath.GetPath())
return compression.Decompress(d.tempLocation, d.finalPath.GetPath())
if err := compression.Decompress(d.tempLocation, d.finalPath.GetPath()); err != nil {
return err
}

// Ensure image is writable
if err := os.Chmod(d.finalPath.GetPath(), 0600); err != nil {
return fmt.Errorf("failed to set permissions on machine image: %w", err)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would like it if you made this error message slightly different so anyone debugging could tell which path immediately they are on? so maybe failed to set permissions on pulled image %s ?

}

return nil
}

func (d *DiskFromURL) pull() error {
Expand Down