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 intocontainers: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 intocontainers: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


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

@baude
Copy link
Copy Markdown
Member

baude commented Apr 6, 2026

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

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?

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

podman machine: image override files need user-write access

2 participants