<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jul 28, 2020 at 3:13 PM Vivek Goyal <<a href="mailto:vgoyal@redhat.com">vgoyal@redhat.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Tue, Jul 28, 2020 at 12:00:20PM +0200, Roman Mohr wrote:<br>
> On Tue, Jul 28, 2020 at 3:07 AM <a href="mailto:misono.tomohiro@fujitsu.com" target="_blank">misono.tomohiro@fujitsu.com</a> <<br>
> <a href="mailto:misono.tomohiro@fujitsu.com" target="_blank">misono.tomohiro@fujitsu.com</a>> wrote:<br>
> <br>
> > > Subject: [PATCH v2 3/3] virtiofsd: probe unshare(CLONE_FS) and print an<br>
> > error<br>
> > ><br>
> > > An assertion failure is raised during request processing if<br>
> > > unshare(CLONE_FS) fails. Implement a probe at startup so the problem can<br>
> > > be detected right away.<br>
> > ><br>
> > > Unfortunately Docker/Moby does not include unshare in the seccomp.json<br>
> > > list unless CAP_SYS_ADMIN is given. Other seccomp.json lists always<br>
> > > include unshare (e.g. podman is unaffected):<br>
> > ><br>
> > <a href="https://raw.githubusercontent.com/seccomp/containers-golang/master/seccomp.json" rel="noreferrer" target="_blank">https://raw.githubusercontent.com/seccomp/containers-golang/master/seccomp.json</a><br>
> > ><br>
> > > Use "docker run --security-opt seccomp=path/to/seccomp.json ..." if the<br>
> > > default seccomp.json is missing unshare.<br>
> ><br>
> > Hi, sorry for a bit late.<br>
> ><br>
> > unshare() was added to fix xattr problem:<br>
> ><br>
> > <a href="https://github.com/qemu/qemu/commit/bdfd66788349acc43cd3f1298718ad491663cfcc#" rel="noreferrer" target="_blank">https://github.com/qemu/qemu/commit/bdfd66788349acc43cd3f1298718ad491663cfcc#</a><br>
> > In theory we don't need to call unshare if xattr is disabled, but it is<br>
> > hard to get to know<br>
> > if xattr is enabled or disabled in fv_queue_worker(), right?<br>
> ><br>
> ><br>
> In kubevirt we want to run virtiofsd in containers. We would already not<br>
> have xattr support for e.g. overlayfs in the VM after this patch series (an<br>
> acceptable con at least for us right now).<br>
> If we can get rid of the unshare (and potentially of needing root) that<br>
> would be great. We always assume that everything which we run in containers<br>
> should work for cri-o and docker.<br>
<br>
But cri-o and docker containers run as root, isn't it? (or atleast have<br>
the capability to run as root). Havind said that, it will be nice to be able<br>
to run virtiofsd without root. <br></blockquote><div><br></div><div>Yes they can run as root. I can tell you what we plan to do with the containerized virtiofsd: We run it as part of the user-owned pod (a set of containers).<br>One of our main goals at the moment is to run VMs in a user-owned pod without additional privileges.</div><div>So that in case the user (VM-creator/owner) enters the pod or something breaks out of the VM they are just in the unprivileged container sandbox.</div><div>As part of that we try to get also rid of running containers in the user-context with the root user.<br><br>One possible scenario which I could think of as being desirable from a kubevirt perspective: </div><div>We would run the VM in one container and have an unprivileged virtiofsd container in parallel.<br>This container already has its own mount namespace and it is not that critical if something manages to enter this sandbox.<br><br>But we are not as far yet as getting completely rid of root right now in kubevirt, so if as a temporary step it needs root, the current proposed changes would still be very useful for us.<br><br>Best Regards,</div><div>Roman<br><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
There are few hurdles though.<br>
<br>
- For file creation, we switch uid/gid (seteuid/setegid) and that seems<br>
  to require root. If we were to run unpriviliged, probably all files<br>
  on host will have to be owned by unpriviliged user and guest visible<br>
  uid/gid will have to be stored in xattrs. I think virtfs supports<br>
  something similar. </blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
I am sure there are other restrictions but this probably is the biggest<br>
one to overcome.<br>
<br>
 > <br>
> "Just" pointing docker to a different seccomp.json file is something which<br>
> k8s users/admin in many cases can't do.<br>
<br>
Or may be issue is that standard seccomp.json does not allow unshare()<br>
and hence you are forced to use a non-standar seccomp.json.<br>
<br>
Vivek<br>
<br>
> <br>
> Best Regards,<br>
> Roman<br>
> <br>
> <br>
> > So, it looks good to me.<br>
> > Reviewed-by: Misono Tomohiro <<a href="mailto:misono.tomohiro@jp.fujitsu.com" target="_blank">misono.tomohiro@jp.fujitsu.com</a>><br>
> ><br>
> > Regards,<br>
> > Misono<br>
> ><br>
> > ><br>
> > > Cc: Misono Tomohiro <<a href="mailto:misono.tomohiro@jp.fujitsu.com" target="_blank">misono.tomohiro@jp.fujitsu.com</a>><br>
> > > Signed-off-by: Stefan Hajnoczi <<a href="mailto:stefanha@redhat.com" target="_blank">stefanha@redhat.com</a>><br>
> > > ---<br>
> > >  tools/virtiofsd/fuse_virtio.c | 16 ++++++++++++++++<br>
> > >  1 file changed, 16 insertions(+)<br>
> > ><br>
> > > diff --git a/tools/virtiofsd/fuse_virtio.c<br>
> > b/tools/virtiofsd/fuse_virtio.c<br>
> > > index 3b6d16a041..9e5537506c 100644<br>
> > > --- a/tools/virtiofsd/fuse_virtio.c<br>
> > > +++ b/tools/virtiofsd/fuse_virtio.c<br>
> > > @@ -949,6 +949,22 @@ int virtio_session_mount(struct fuse_session *se)<br>
> > >  {<br>
> > >      int ret;<br>
> > ><br>
> > > +    /*<br>
> > > +     * Test that unshare(CLONE_FS) works. fv_queue_worker() will need<br>
> > it. It's<br>
> > > +     * an unprivileged system call but some Docker/Moby versions are<br>
> > known to<br>
> > > +     * reject it via seccomp when CAP_SYS_ADMIN is not given.<br>
> > > +     *<br>
> > > +     * Note that the program is single-threaded here so this syscall<br>
> > has no<br>
> > > +     * visible effect and is safe to make.<br>
> > > +     */<br>
> > > +    ret = unshare(CLONE_FS);<br>
> > > +    if (ret == -1 && errno == EPERM) {<br>
> > > +        fuse_log(FUSE_LOG_ERR, "unshare(CLONE_FS) failed with EPERM. If<br>
> > "<br>
> > > +                "running in a container please check that the container<br>
> > "<br>
> > > +                "runtime seccomp policy allows unshare.\n");<br>
> > > +        return -1;<br>
> > > +    }<br>
> > > +<br>
> > >      ret = fv_create_listen_socket(se);<br>
> > >      if (ret < 0) {<br>
> > >          return ret;<br>
> > > --<br>
> > > 2.26.2<br>
> ><br>
> ><br>
<br>
</blockquote></div></div>