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
16 changes: 16 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,21 @@ 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 as read-only (use install)
exec.Command("install", "-m", "444", mb.imagePath, img).Run()

// Step 3: 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 pulled image %s: %w", d.finalPath.GetPath(), err)
}

return nil
}

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