<div dir="ltr"><div dir="ltr"><div dir="ltr"><p class="MsoNormal"><span style="line-height:107%"><font face="arial, sans-serif" style="">We are using an unprivileged user to run virtiofsd in its own
user namespace. We have a guest VM running on top of QEMU with KVM. We
are sharing files from the host to the guest and we need to make sure only
certain users/groups in the guest can read/write those files. Currently
there is only one uid/gid that’s mapped correctly (the virtiofsd user on
the host is mapped to guest) and everything else is mapped to nobody.</font></span></p>

<p class="MsoNormal"><span style="line-height:107%"><font face="arial, sans-serif">It seems the reason is that unprivileged virtiofsd only maps
current uid/gid when it's running inside its own user namespace. </font></span></p><p class="MsoNormal"><span style="line-height:107%"><font face="arial, sans-serif">Due to some resource limitations that we have in our system, we can't use a
container-engine such as lxc-usernsexec to map a range of uids/gids. So,
I'm trying to figure out if there is a way to patch the
‘setup_id_mappings’ in virtiofsd code to support our specific scenario.<span></span></font></span></p><p class="MsoNormal"><span style="line-height:107%"><font face="arial, sans-serif"><br></font></span></p>

<p class="MsoNormal"><span style="line-height:107%"><font face="arial, sans-serif">The additional mapping that we need is for uid/gid=1000. What I've done:<span></span></font></span></p>

<p class="gmail-MsoListParagraphCxSpFirst"><font face="arial, sans-serif"><span style="line-height:107%">-<span style="font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal">       
</span></span><span style="line-height:107%">Defined 1000:100000:65536 in both /etc/subuid and
/etc/subgid</span></font></p>

<p class="gmail-MsoListParagraphCxSpMiddle"><font face="arial, sans-serif"><span style="line-height:107%">-<span style="font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal">       
</span></span><span style="line-height:107%">Changed this line </span><a href="https://gitlab.com/virtio-fs/virtiofsd/-/blob/main/src/sandbox.rs#L289">src/sandbox.rs
· main · virtio-fs / virtiofsd · GitLab</a><span style="line-height:107%"> to something like:<span></span></span></font></p>

<p class="gmail-MsoListParagraphCxSpLast" style="margin-bottom:0cm;line-height:14.25pt;background:rgb(30,30,30)"><font face="arial, sans-serif"><span style="color:rgb(212,212,212)">-<span style="font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal">        
</span></span><span style="color:rgb(86,156,214)">let</span><span style="color:rgb(212,212,212)">
uid_mapping = </span><span style="color:rgb(86,156,214)">format</span><span style="color:rgb(212,212,212)">!(</span><span style="color:rgb(206,145,120)">"</span><span style="color:rgb(86,156,214)">{}</span><span style="color:rgb(206,145,120)">
</span><span style="color:rgb(86,156,214)">{}</span><span style="color:rgb(206,145,120)"> 1\n1000 1000 1\n"</span><span style="color:rgb(212,212,212)">,
uid, uid);<span></span></span></font></p>

<p class="MsoNormal"><font face="arial, sans-serif"><br></font></p>

<p class="MsoNormal"><span style="line-height:107%"><font face="arial, sans-serif">After running virtiofsd, I’m getting this error:<span></span></font></span></p>

<p class="MsoNormal"><span style="line-height:107%"><font face="arial, sans-serif" style="">Error entering sandbox: WriteUidMap(Os { code: 1,
kind: PermissionDenied, message: “Operation not permitted” })<b style="font-size:12pt"><span></span></b></font></span></p><p class="MsoNormal"><b><span style="font-size:12pt;line-height:107%;font-family:"Times New Roman",serif"><br></span></b></p><p class="MsoNormal">What am I missing here? </p><p class="MsoNormal"><br></p><p class="MsoNormal">Thanks,</p><p class="MsoNormal">Ellie</p></div></div></div>