Subject: bug#37967: guix environment -CN: Operation not permitted mounting host's /var/run/nscd

From: Ivan Vilata i Balaguer <[email-masked]>
Date: Mon, 4 Nov 2019 16:23:12 -0500

Ludovic Courtès (2019-11-04 18:07:05 +0100) wrote:

> Ivan Vilata i Balaguer <[email-masked]> skribis:
> 
> > BTW, I ran that under strace and it looks like the read-only remount fails
> > after mounting `/var/run/nscd` in the new namespace has succeeded:
> >
> >     $ strace -f unshare -mUr mount --bind -o ro /var/run/nscd /tmp/tt
> >     […]
> >     access("/run/mount", R_OK|W_OK)         = -1 EACCES (Permission denied)
> >     mount("/run/nscd", "/tmp/tt", 0x14c25b0, MS_RDONLY|MS_BIND, NULL) = 0
> >     mount("none", "/tmp/tt", NULL, MS_RDONLY|MS_REMOUNT|MS_BIND, NULL) = -1 EPERM (Operation not permitted)
> >     write(2, "mount: ", 7mount: )                  = 7
> >     write(2, "/tmp/tt: filesystem was mounted,"..., 89/tmp/tt: filesystem was mounted, but any subsequent operation failed: Unknown error 5005.) = 89
> >     write(2, "\n", 1
> >     […]
> 
> Weird, why does it remount it?
> 
> What does:
> 
>   mount | grep /run

    $ mount | grep /run
    tmpfs on /run type tmpfs (rw,nosuid,nodev,noexec,relatime,size=1641444k,mode=755)
    […]

> returns?  I just tried on a Debian 10 image with Linux 4.19.0 and /run
> is a tmpfs, which may be the reason why read-only bind-mounts fail (or
> at least there’s a bug in that area.)
> 
> Anyway, below is a patch for you to test.  Let me know how it goes.  :-)
> 
> Thanks,
> Ludo’.

I applied your patch on top of bf7b08c4, pulled Guix and did successfully
start `guix environment -CN`, with network support and all.

Cool! `:)`

> diff --git a/gnu/system/file-systems.scm b/gnu/system/file-systems.scm
> index 6cf6ccc53e..6cdb2b749d 100644
> --- a/gnu/system/file-systems.scm
> +++ b/gnu/system/file-systems.scm
> @@ -507,7 +507,8 @@ a bind mount."
>                   ;; XXX: On some GNU/Linux systems, /etc/resolv.conf is a
>                   ;; symlink to a file in a tmpfs which, for an unknown reason,
>                   ;; cannot be bind mounted read-only within the container.
> -                 (writable? (string=? file "/etc/resolv.conf"))))
> +                 (writable? (or (string=? file "/etc/resolv.conf")
> +                                (string=? file "/var/run/nscd")))))
>                (cons "/var/run/nscd" %network-configuration-files)))
>  
>  (define (file-system-type-predicate type)

-- 
Ivan Vilata i Balaguer -- https://elvil.net/