Skip to content

machine: ensure disk image is writable before resize (fix read-only image init failure)#28447

Open
jude-ruben wants to merge 1 commit into
podman-container-tools:mainfrom
jude-ruben:fix/machine-image-permissions
Open

machine: ensure disk image is writable before resize (fix read-only image init failure)#28447
jude-ruben wants to merge 1 commit into
podman-container-tools:mainfrom
jude-ruben:fix/machine-image-permissions

Conversation

@jude-ruben

Copy link
Copy Markdown

Problem

Initializing a Podman machine with a read-only disk image (e.g., chmod 444)
fails during the resize step with a permission denied error.

Root Cause

The disk image created from user input may retain read-only permissions.
The resize operation (qemu-img) requires write access but no step ensures
the image is writable before resizing.

Solution

Ensure the disk image is set to writable (0600) before resize operations
using os.Chmod.

Test

Added an e2e test:

  • Copy a valid image
  • Make it read-only (chmod 444)
  • Run podman machine init
  • Verify success

Result

  • Before: resize fails with permission denied
  • After: machine initializes successfully

Fixes #27576

Comment thread pkg/machine/stdpull/url.go Outdated

// 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
Contributor

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 ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

can you check now @baude

@baude

baude commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

did you confirm that any of the other providers also have this problem?

Comment thread pkg/machine/e2e/init_test.go Outdated
img := filepath.Join(GinkgoT().TempDir(),"test.qcow2")

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

Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

can you check now @baude

@jude-ruben jude-ruben force-pushed the fix/machine-image-permissions branch from ee9d0de to 377a27b Compare April 12, 2026 07:54
@jude-ruben

Copy link
Copy Markdown
Author

did you confirm that any of the other providers also have this problem?

@baude ,I verified this behavior only occurs for the QEMU provider. The pulled image is resized during machine init for QEMU, which requires write permissions. Other providers do not resize the pulled image in the same way, so they are not affected.

@ashley-cui

Copy link
Copy Markdown
Contributor

please run make validate or make validatepr locally before you re-push with your changes; this should help with the linter errors.

@Honny1 Honny1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hello @jude-ruben, please rebase on the upstream main branch. We changed import paths recently.
Also please resolve linting issue:

+ ./bin/golangci-lint run --build-tags=apparmor,seccomp,selinux
pkg/machine/e2e/init_test.go:743:62: Error return value of `(*os/exec.Cmd).Run` is not checked (errcheck)
		exec.Command("install", "-m", "444", mb.imagePath, img).Run()
		                                                           ^
pkg/machine/e2e/init_test.go:749:3: ginkgo-linter: wrong error assertion. Consider using `Expect(err).ToNot(HaveOccurred())` instead (ginkgolinter)
		Expect(err).To(BeNil())
		^
pkg/machine/stdpull/local.go:37:1: File is not properly formatted (gofumpt)
	if err := os.Chmod(s.finalPath.GetPath(), 0600); err != nil {
^
pkg/machine/stdpull/url.go:84:1: File is not properly formatted (gofumpt)
	if err := os.Chmod(d.finalPath.GetPath(), 0600); err != nil {
^
pkg/machine/stdpull/local.go:42:1: unnecessary trailing newline (whitespace)
}
^

Thanks.

@github-actions

Copy link
Copy Markdown

A friendly reminder that this PR had no activity for 30 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

podman machine: image override files need user-write access

4 participants