File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package e2e_test
33import (
44 "fmt"
55 "os"
6+ "os/exec"
67 "path/filepath"
78 "runtime"
89 "strconv"
@@ -733,6 +734,24 @@ var _ = Describe("podman machine init", func() {
733734 Expect (p ).To (Equal (l .VMType ))
734735 }
735736 })
737+
738+ It ("init with read-only image should succeed" , func () {
739+ // Step 1: create temp image
740+ img := filepath .Join (GinkgoT ().TempDir (),"test.qcow2" )
741+
742+ // Step 2: copy existing image
743+ exec .Command ("cp" , mb .imagePath , img ).Run ()
744+
745+ // Step 3: make it read-only
746+ exec .Command ("chmod" , "444" , img ).Run ()
747+
748+ // Step 4: run podman machine init
749+ i := new (initMachine )
750+ session , err := mb .setCmd (i .withImage (img )).run ()
751+
752+ Expect (err ).To (BeNil ())
753+ Expect (session ).To (Exit (0 ))
754+ })
736755})
737756
738757var p4Config = []byte (`{
Original file line number Diff line number Diff line change 11package stdpull
22
33import (
4+ "fmt"
5+ "os"
6+
47 "github.com/containers/podman/v6/pkg/machine/compression"
58 "github.com/containers/podman/v6/pkg/machine/define"
69 "github.com/sirupsen/logrus"
@@ -26,5 +29,14 @@ func (s *StdDiskPull) Get() error {
2629 return err
2730 }
2831 logrus .Debugf ("decompressing (if needed) %s to %s" , s .inputPath .GetPath (), s .finalPath .GetPath ())
29- return compression .Decompress (s .inputPath , s .finalPath .GetPath ())
32+ if err := compression .Decompress (s .inputPath , s .finalPath .GetPath ()); err != nil {
33+ return err
34+ }
35+
36+ // Ensure image is writable
37+ if err := os .Chmod (s .finalPath .GetPath (), 0600 ); err != nil {
38+ return fmt .Errorf ("failed to set permissions on machine image: %w" , err )
39+ }
40+ return nil
41+
3042}
Original file line number Diff line number Diff line change @@ -76,7 +76,16 @@ func (d *DiskFromURL) Get() error {
7676 }
7777
7878 logrus .Debugf ("decompressing (if needed) %s to %s" , d .tempLocation .GetPath (), d .finalPath .GetPath ())
79- return compression .Decompress (d .tempLocation , d .finalPath .GetPath ())
79+ if err := compression .Decompress (d .tempLocation , d .finalPath .GetPath ()); err != nil {
80+ return err
81+ }
82+
83+ // Ensure image is writable
84+ if err := os .Chmod (d .finalPath .GetPath (), 0600 ); err != nil {
85+ return fmt .Errorf ("failed to set permissions on machine image: %w" , err )
86+ }
87+
88+ return nil
8089}
8190
8291func (d * DiskFromURL ) pull () error {
You can’t perform that action at this time.
0 commit comments