lxd/device: Disable virtiofsd idmap for shifted volumes - #18709
lxd/device: Disable virtiofsd idmap for shifted volumes#18709jonathan-conder wants to merge 1 commit into
Conversation
6abc738 to
a226aa9
Compare
There was a problem hiding this comment.
Pull request overview
Adjusts VM virtio-fs behavior so virtiofsd does not apply instance raw.idmap when serving shifted storage volumes, aligning file ownership semantics between VMs and containers and addressing the ownership mismatch described in #18686.
Changes:
- Update VM disk device setup to avoid parsing/applying
raw.idmapforsecurity.shiftedvolumes when startingvirtiofsd. - Add an integration test ensuring shifted volumes in VMs preserve on-disk ownership (i.e. do not appear as
nobody:nogroup) even whenraw.idmapis set.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
lxd/device/disk.go |
Skips applying raw.idmap to virtiofsd for security.shifted volumes during VM disk setup. |
test/suites/vm.sh |
Adds a regression test validating ownership consistency for shifted volumes shared into VMs over virtio-fs. |
Without this, file ownership in VMs doesn't match containers. This is technically a breaking change, but I suspect not many people are using raw.idmap together with shifted volumes, otherwise canonical#18561 probably would have been discovered sooner. If it's an issue I'm happy to gate this behind a new config option though. Signed-off-by: Jonathan Conder <jonathan.conder@canonical.com>
a226aa9 to
03fd41d
Compare
|
@tomponline Another approach would be to keep running |
Yes, effectively I think you're proposing to sandbox virtiofsd to give it permission to write/read files as root, but not to be able to run code as root. Right? |
Yeah. It would be limited to reading/writing those files within the shifted mount as well, can't touch /etc/shadow, etc. That said, virtiofsd is already sandboxed. So the change would be to add shifting to the mount (reducing the level of security but matching how things work for containers) |
|
Right. Lets focus on getting the behaviours aligned and then work on sandboxing separately once the correct behaviour is established. Thanks |
tomponline
left a comment
There was a problem hiding this comment.
Thanks for this PR.
I've been thinking about this, and I think it'd be worth exploring always running virtiofsd in a userns, rather than only doing it in certain scenarios.
The difference being that in the scenarios today where we dont run virtiofsd in a userns (as well as the new one you're adding here) we would pass through a full unrestricted idmap, e.g.
// Map UIDs 0 to 4294967295 1:1 with the host UIDs
UidMappings: []syscall.SysProcIDMap{
{
ContainerID: 0,
HostID: 0,
Size: maxIDRange,
},
},
// Map GIDs 0 to 4294967295 1:1 with the host GIDs
GidMappings: []syscall.SysProcIDMap{
{
ContainerID: 0,
HostID: 0,
Size: maxIDRange,
},
},This way virtiofsd is always restricted without CAP_SYS_ADMIN, Host Kernel Module Loading, and anything protected by init_user_ns checks.
Virtiofsd uses
So I don't think we need to introduce another mount namespace. |
Although it wouldn't hurt to make that explicit in LXD's calling code, as currently its relying on the default option of virtiofsd. |
I have to admit I didn't realise that unrestricting the idmap like this was still a meaningful security boundary. Certainly seems fine to just drop all caps but remain UID 0 (although maybe file operations still need something like CAP_CHOWN, for example). This approach seems fine to me, although I don't know that I can implement it myself without taking time away from my main tasks. |
|
WIP is over here #18918 |
|
Closing in favour of #18918 |
Partially fixes #18686. My rationale is described there.
Without this, file ownership in VMs doesn't match containers. This is technically a breaking change, but I suspect not many people are using raw.idmap together with shifted volumes, otherwise #18561 probably would have been discovered sooner. If it's an issue I'm happy to gate this behind a new config option though.
Checklist