Repository navigation
pkg/machine: apply ro mount option to virtiofs and 9p shares - #29898
AdamMagued wants to merge 2 commits into
Conversation
Luap99
left a comment
There was a problem hiding this comment.
This will need proper machine e2e tests. Also the same fix must be added to the 9p mount code on windows as readonly does not seem to be set there either.
Then as noted on the issue ideally the read only option should be enforced on the hypervisor side not the potential untrusted VM, though I see no option being exposed there today in vfkit/krunkit either so I guess it is not possible.
| case vmconfigs.VirtIOFS: | ||
| virtioMount := machine.NewVirtIoFsMount(source, target, readOnly) | ||
| mount = virtioMount.ToMount() | ||
| mount.OriginalInput = volume |
There was a problem hiding this comment.
what is the point of setting this? It is never read anywhere so I think the logical thing is to drop that.
| mountUnit.Add("Mount", "Options", fmt.Sprintf("context=\"%s\"", NFSSELinuxContext)) | ||
| mountOptions := fmt.Sprintf("context=\"%s\"", NFSSELinuxContext) | ||
| if mnt.ReadOnly { | ||
| mountOptions = fmt.Sprintf("ro,context=\"%s\"", NFSSELinuxContext) |
There was a problem hiding this comment.
This is duplicating the line above with the nfs mount option, the branch should only append "ro" to the string
| tests := []struct { | ||
| name string | ||
| vfs VirtIoFs | ||
| readOnly bool |
There was a problem hiding this comment.
having an extra readOnly bool makes no sense here and just duplicates the VirtIoFs.ReadOnly field which is the one being tested/used
| tests := []struct { | ||
| name string | ||
| mount *vmconfigs.Mount | ||
| readOnly bool |
There was a problem hiding this comment.
same here, the duplicated readonly field makes no sense here as Mount.ReadOnly is being used
|
see https://github.com/podman-container-tools/community/blob/main/CONTRIBUTING.md#dco-sign-off for a proper DCO sign off |
|
And in general please follow the PR template in the future |
cbc12cc to
822c43b
Compare
|
I updated the PR with the following changes:
|
|
[NON-BLOCKING] Packit jobs failed. @podman-container-tools/packit-jobs please check. Everyone else, feel free to ignore. |
1 similar comment
|
[NON-BLOCKING] Packit jobs failed. @podman-container-tools/packit-jobs please check. Everyone else, feel free to ignore. |
822c43b to
15e9ed3
Compare
| Expect(sshSession.outputToString()).To(ContainSubstring("example")) | ||
| }) | ||
|
|
||
| It("machine init with read-only volume", func() { |
There was a problem hiding this comment.
I think this overlaps with podman volume read-only mount test. I think it should be dropped to reduce CI time.
There was a problem hiding this comment.
Agree, we should only test this once, machine tests are quite expensive
|
@mheon prob want your eyes on this too given the history. |
|
|
||
| flags := client9pCommand.Flags() | ||
| flags.BoolVar(&client9pReadOnly, "read-only", false, "mount directory read-only") | ||
| flags.BoolVar(&client9pReadOnly, "ro", false, "mount directory read-only") |
There was a problem hiding this comment.
Is the duplication necessary? This command should never be called by hand
Luap99
left a comment
There was a problem hiding this comment.
Also please fix the linter errors as pointed out in the CI failure.
| Expect(ls.outputToString()).To(ContainSubstring(testString)) | ||
| }) | ||
|
|
||
| It("podman volume read-only mount", func() { |
There was a problem hiding this comment.
in addition to dropping the other please inline that test into podman volume on non-standard path by adding a second mount path for the ro mount as part of the same machine.
That way we only need to boot one VM and keep the test time about the same, in CI a sign le boot cycle can take up to 60s so we really need to avoid a lot of unnecessary starts
15e9ed3 to
10203cb
Compare
|
@Luap99 I formatted pkg/machine/volume_systemd_test.go with gofumpt and verified the check passes. |
10203cb to
c51bf6c
Compare
|
@Honny1 Tracked down the failure. In Windows Hyper-V CI, the guest VM runs the pre-installed system podman binary from the base image. That binary lacks the new To maintain backwards compatibility with existing guest VM images, host I updated |
c51bf6c to
bca7a7d
Compare
|
@Honny1 Following up on the Hyper-V CI failure in basic_test.go and init_test.go (mount: /var/mnt/ro-test: mount point is busy): The Linux 9p filesystem driver does not implement superblock remount (reconfigure_super), causing mount -o remount,ro to return EBUSY. Passing the bind option via mount -o remount,ro,bind directs the kernel VFS do_remount path into do_reconfigure_mnt. This reconfigures the VFS mount flags directly (setting MNT_READONLY) without invoking driver-level superblock reconfigure. This cleanly enforces read-only semantics on guest 9p mounts across all kernel versions. I updated startShareMountArgs and its unit tests in pkg/machine/hyperv to use remount,ro,bind, verified tests and lint, and force-pushed the branch. |
|
@AdamMagued You have not addressed any of the review comments we have given
A remount seems unnecessary complicated, backwards compat is certainly important but could we instead of using a cli option use an env variable for now? We can always pass the env as the old client binary will ignore it and the new one can use it just fine. |
When mounting volumes in virtual machines (virtiofs on macOS/Linux or 9p on Windows Hyper-V), volume configurations containing the :ro flag were parsed into vmconfigs.Mount with ReadOnly: true, but the read-only option was omitted from guest mount configurations. As a result, the guest mounted the shares read-write. Translate the ReadOnly flag into the ro mount option in GenerateSystemDFilesForVirtiofsMounts, support CONTAINERS_MACHINE_9P_READ_ONLY in client9p and pass it from Windows Hyper-V startShares for backwards compatibility with existing guest VM images, and add unit and machine e2e tests. Fixes: podman-container-tools#29897 Signed-off-by: Adam Magued <adamismailmageud@gmail.com>
bca7a7d to
e0c73b2
Compare
|
@Luap99 @mheon @Honny1 I have addressed all review feedback across the PR:
All unit tests and |
|
he CI failure seems related and unusual. Also, please review our LLM policy. Avoid adding AI-generated summaries to your comments so we can keep the PR thread clean. |
Honny1
left a comment
There was a problem hiding this comment.
This failure seems to be related:
D:/a/podman/podman/pkg/machine/e2e/basic_test.go:27
podman volume on non-standard path
D:/a/podman/podman/pkg/machine/e2e/basic_test.go:271
> Enter [BeforeEach] TOP-LEVEL - D:/a/podman/podman/pkg/machine/e2e/machine_test.go:218 @ 10/12/26 09:02:41.985
< Exit [BeforeEach] TOP-LEVEL - D:/a/podman/podman/pkg/machine/e2e/machine_test.go:218 @ 10/12/26 09:02:41.986 (1ms)
> Enter [It] podman volume on non-standard path - D:/a/podman/podman/pkg/machine/e2e/basic_test.go:271 @ 10/12/26 09:02:41.986
D:\a\podman\podman\bin\windows\podman.exe machine init --disk-size 11 --image C:\Users\RUNNER~1\AppData\Local\Temp\podman-machine.x86_64.hyperv.vhdx --volume C:\Users\RUNNER~1\AppData\Local\Temp\machine-volume2578504670:/does/not/exist --volume C:\Users\RUNNER~1\AppData\Local\Temp\machine-volume-ro2177619695:/mnt/ro-test:ro --now 47fb387c762c
Machine init complete
Starting machine "47fb387c762c"
This machine is currently configured in rootless mode. If your containers
require root permissions (e.g. ports < 1024), or if you run into compatibility
issues with non-podman clients, you can switch using the following command:
podman machine set --rootful 47fb387c762c
API forwarding listening on: npipe:////./pipe/podman-47fb387c762c
Another process was listening on the default Docker API socket address.
You can still connect Docker API clients by setting DOCKER_HOST using the
following command in your terminal session:
$Env:DOCKER_HOST="npipe:////./pipe/podman-47fb387c762c"
Machine "47fb387c762c" started successfully
D:\a\podman\podman\bin\windows\podman.exe machine ssh 47fb387c762c cat /does/not/exist/testfile
abcdefg1234567D:\a\podman\podman\bin\windows\podman.exe machine ssh 47fb387c762c cat /mnt/ro-test/ro-testfile
readonly-volume-contentD:\a\podman\podman\bin\windows\podman.exe machine ssh 47fb387c762c touch /mnt/ro-test/fail-write
[FAILED] Expected
<int>: 0
not to match exit code:
<int>: 0
In [It] at: D:/a/podman/podman/pkg/machine/e2e/basic_test.go:319 @ 10/12/26 09:03:32.508
Full Stack Trace
go.podman.io/podman/v6/pkg/machine/e2e_test.init.func6.5()
D:/a/podman/podman/pkg/machine/e2e/basic_test.go:319 +0xea3
< Exit [It] podman volume on non-standard path - D:/a/podman/podman/pkg/machine/e2e/basic_test.go:271 @ 10/12/26 09:03:32.508 (50.522s)
…s true Signed-off-by: Adam Magued <adamismailmageud@gmail.com>
|
@Honny1 @Luap99 The root cause of the Hyper-V CI failure was that the Windows CI runner uses a pre-built guest VM image containing an existing released Podman binary. That guest binary mounts 9p shares without To ensure read-only enforcement works reliably across both existing VM images and new builds, I updated |
| args = append(args, "sudo", "chattr", "-i", "/", "; ") | ||
| } | ||
| args = append(args, "sudo", "mkdir", "-p", strconv.Quote(cleanTarget), "; ") | ||
| if requiresChattr { | ||
| args = append(args, "sudo", "chattr", "+i", "/", "; ") |
There was a problem hiding this comment.
I would join all commands with && instead of ;.
Luap99
left a comment
There was a problem hiding this comment.
thanks we are almost there now
| if !readOnly { | ||
| readOnly, _ = strconv.ParseBool(os.Getenv("PODMAN_9P_READ_ONLY")) | ||
| } | ||
| if err := client9p(cmd.Context(), uint32(port), args[1], readOnly); err != nil { |
There was a problem hiding this comment.
this should not use two different env vars, there is no need for this at all
since this is podman specific just use PODMAN_9P_READ_ONLY
| if mount.ReadOnly { | ||
| args = append(args, "; ", "sudo", "mount", "-o", "remount,ro", strconv.Quote(cleanTarget)) | ||
| } |
There was a problem hiding this comment.
please add a comment here that the remount should be removed in the future when the client inside is new enough to do this by default
When mounting volumes in virtual machines (virtiofs on macOS/Linux or 9p on Windows Hyper-V), volume configurations containing the
:roflag were parsed intovmconfigs.MountwithReadOnly: true, but the read-only flag was omitted when configuring mounts in the guest. This caused guest VMs to mount the shares read-write.This change:
roto virtiofs systemd mount options inGenerateSystemDFilesForVirtiofsMountswhenmnt.ReadOnlyis true.--read-onlytoclient9pfor Windows Hyper-V 9p shares, adding,roto kernel 9p mount options.OriginalInputacross volume mappings.Fixes: #29897
Checklist
Ensure you have completed the following checklist for your pull request to be reviewed:
commits. (
git commit -s). (If needed, usegit commit -s --amend). The author email must matchthe sign-off email address. See CONTRIBUTING.md
for more information.
Fixes: #00000in commit message (if applicable)make validatepr(format/lint checks)Noneif no user-facing changes)Does this PR introduce a user-facing change?