GNU bug report logs - #46782
guix environment --expose options cannot be layered onto $PWD

Previous Next

Package: guix;

Reported by: Maxim Cournoyer <maxim.cournoyer <at> gmail.com>

Date: Thu, 25 Feb 2021 21:13:01 UTC

Severity: normal

Tags: patch

Done: Maxim Cournoyer <maxim.cournoyer <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 46782 in the body.
You can then email your comments to 46782 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-guix <at> gnu.org:
bug#46782; Package guix. (Thu, 25 Feb 2021 21:13:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Maxim Cournoyer <maxim.cournoyer <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-guix <at> gnu.org. (Thu, 25 Feb 2021 21:13:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Maxim Cournoyer <maxim.cournoyer <at> gmail.com>
To: bug-guix <bug-guix <at> gnu.org>
Subject: guix environment --expose options cannot be layered onto $PWD
Date: Thu, 25 Feb 2021 16:12:34 -0500
Hello Guix!

I noticed, while trying to expose the SSL environment variable inside a
container and doing things such as:

--8<---------------cut here---------------start------------->8---
guix environment --container --network -E SSL --expose=$SSL_CERT_FILE \
     --expose=$SSL_CERT_DIR --ad-hoc [...]
--8<---------------cut here---------------end--------------->8---

that it wasn't possible to expose things onto the implicitly mounted
current working directory.  No error message would be shown, yet the
--expose arguments wouldn't go through unless using --no-cwd.

Here's a minimal example:

--8<---------------cut here---------------start------------->8---
$ guix environment -C --expose=/tmp=$PWD/tmp \
  --ad-hoc bash coreutils -- bash -c 'stat $PWD/tmp'
stat: cannot statx '/var/lib/jenkins/tmp': No such file or directory
--8<---------------cut here---------------end--------------->8---

but,

--8<---------------cut here---------------start------------->8---
$ guix environment --no-cwd -C --expose=/tmp=$PWD/tmp \
  --ad-hoc bash coreutils -- bash -c 'stat $PWD/tmp'
  File: /var/lib/jenkins/tmp
  Size: 73728           Blocks: 152        IO Block: 4096   directory
Device: fd00h/64768d    Inode: 1966081     Links: 397
Access: (1777/drwxrwxrwt)  Uid: (65534/ UNKNOWN)   Gid: (65534/overflow)
Access: 2021-02-25 20:40:08.534757708 +0000
Modify: 2021-02-25 21:10:49.205636074 +0000
Change: 2021-02-25 21:10:49.205636074 +0000
 Birth: 2016-12-07 20:43:16.029221570 +0000
--8<---------------cut here---------------end--------------->8---

succeeds.

I can't think of a technical reason why layering bind mounts wouldn't
work; in fact it already appear to work for multiple --expose options
touching the same hierarchy of files.

If there's a technical reason this cannot/shouldn't happen, we should
warn the user about it.

Thanks,

Maxim




Information forwarded to bug-guix <at> gnu.org:
bug#46782; Package guix. (Wed, 23 Nov 2022 14:25:02 GMT) Full text and rfc822 format available.

Message #8 received at 46782 <at> debbugs.gnu.org (full text, mbox):

From: bbb ee <blasforr <at> gmail.com>
To: 46782 <at> debbugs.gnu.org
Date: Wed, 23 Nov 2022 15:24:18 +0100
[Message part 1 (text/plain, inline)]
There is a similar issue that is solved: https://issues.guix.gnu.org/59425
[Message part 2 (text/html, inline)]

Information forwarded to bug-guix <at> gnu.org:
bug#46782; Package guix. (Fri, 27 Jan 2023 16:20:02 GMT) Full text and rfc822 format available.

Message #11 received at 46782 <at> debbugs.gnu.org (full text, mbox):

From: Maxim Cournoyer <maxim.cournoyer <at> gmail.com>
To: bbb ee <blasforr <at> gmail.com>
Cc: 46782 <at> debbugs.gnu.org
Subject: Re: bug#46782: guix environment --expose options cannot be layered
 onto $PWD
Date: Fri, 27 Jan 2023 11:19:34 -0500
Hi,

bbb ee <blasforr <at> gmail.com> writes:

> There is a similar issue that is solved: https://issues.guix.gnu.org/59425

I can still reproduce the original problem with:

--8<---------------cut here---------------start------------->8---
guix environment -C --expose=/tmp=$PWD/tmp --ad-hoc bash coreutils \
 -- bash -c 'stat $PWD/tmp'
--8<---------------cut here---------------end--------------->8---

So it seems the issue at hand is unrelated/different.

-- 
Thanks,
Maxim




Information forwarded to bug-guix <at> gnu.org:
bug#46782; Package guix. (Fri, 27 Jan 2023 18:57:01 GMT) Full text and rfc822 format available.

Message #14 received at 46782 <at> debbugs.gnu.org (full text, mbox):

From: Simon Tournier <zimon.toutoune <at> gmail.com>
To: Maxim Cournoyer <maxim.cournoyer <at> gmail.com>, bbb ee <blasforr <at> gmail.com>
Cc: 46782 <at> debbugs.gnu.org
Subject: Re: bug#46782: guix environment --expose options cannot be layered
 onto $PWD
Date: Fri, 27 Jan 2023 18:31:38 +0100
Hi Maxim,

A naive question since it works when using the --no-cwd option.

On ven., 27 janv. 2023 at 11:19, Maxim Cournoyer <maxim.cournoyer <at> gmail.com> wrote:

> --8<---------------cut here---------------start------------->8---
> guix environment -C --expose=/tmp=$PWD/tmp --ad-hoc bash coreutils \
>  -- bash -c 'stat $PWD/tmp'
> --8<---------------cut here---------------end--------------->8---

Is $PWD referring to the same thing?  Because one is outside and the
other is inside.

Cheers,
simon




Information forwarded to bug-guix <at> gnu.org:
bug#46782; Package guix. (Mon, 06 Feb 2023 21:55:01 GMT) Full text and rfc822 format available.

Message #17 received at 46782 <at> debbugs.gnu.org (full text, mbox):

From: Maxim Cournoyer <maxim.cournoyer <at> gmail.com>
To: Simon Tournier <zimon.toutoune <at> gmail.com>
Cc: 46782 <at> debbugs.gnu.org, bbb ee <blasforr <at> gmail.com>
Subject: Re: bug#46782: guix environment --expose options cannot be layered
 onto $PWD
Date: Mon, 06 Feb 2023 16:54:20 -0500
Hi,

Simon Tournier <zimon.toutoune <at> gmail.com> writes:

> Hi Maxim,
>
> A naive question since it works when using the --no-cwd option.
>
> On ven., 27 janv. 2023 at 11:19, Maxim Cournoyer <maxim.cournoyer <at> gmail.com> wrote:
>
>> --8<---------------cut here---------------start------------->8---
>> guix environment -C --expose=/tmp=$PWD/tmp --ad-hoc bash coreutils \
>>  -- bash -c 'stat $PWD/tmp'
>> --8<---------------cut here---------------end--------------->8---
>
> Is $PWD referring to the same thing?  Because one is outside and the
> other is inside.

Yes!  See:

--8<---------------cut here---------------start------------->8---
maxim <at> hurd ~$ echo $PWD/tmp && guix environment \
 -C --expose=/tmp=$PWD/tmp --ad-hoc bash coreutils -- bash -c 'echo $PWD/tmp'
/home/maxim/tmp
/home/maxim/tmp
--8<---------------cut here---------------end--------------->8---

-- 
Thanks,
Maxim




Information forwarded to bug-guix <at> gnu.org:
bug#46782; Package guix. (Tue, 07 Feb 2023 01:25:02 GMT) Full text and rfc822 format available.

Message #20 received at 46782 <at> debbugs.gnu.org (full text, mbox):

From: bokr <at> bokr.com
To: Maxim Cournoyer <maxim.cournoyer <at> gmail.com>
Cc: 46782 <at> debbugs.gnu.org, bbb ee <blasforr <at> gmail.com>,
 Simon Tournier <zimon.toutoune <at> gmail.com>
Subject: Re: bug#46782: guix environment --expose options cannot be layered
 onto $PWD
Date: Tue, 7 Feb 2023 02:24:04 +0100
Hi,

On +2023-02-06 16:54:20 -0500, Maxim Cournoyer wrote:
> Hi,
> 
> Simon Tournier <zimon.toutoune <at> gmail.com> writes:
> 
> > Hi Maxim,
> >
> > A naive question since it works when using the --no-cwd option.
> >
> > On ven., 27 janv. 2023 at 11:19, Maxim Cournoyer <maxim.cournoyer <at> gmail.com> wrote:
> >
> >> --8<---------------cut here---------------start------------->8---
> >> guix environment -C --expose=/tmp=$PWD/tmp --ad-hoc bash coreutils \
> >>  -- bash -c 'stat $PWD/tmp'
> >> --8<---------------cut here---------------end--------------->8---
> >
> > Is $PWD referring to the same thing?  Because one is outside and the
> > other is inside.
> 
> Yes!  See:
> 
> --8<---------------cut here---------------start------------->8---
> maxim <at> hurd ~$ echo $PWD/tmp && guix environment \
>  -C --expose=/tmp=$PWD/tmp --ad-hoc bash coreutils -- bash -c 'echo $PWD/tmp'
> /home/maxim/tmp
> /home/maxim/tmp
> --8<---------------cut here---------------end--------------->8---
> 
> -- 
> Thanks,
> Maxim
>

I imagine the created environment is COW[1]
[1] <https://en.wikipedia.org/wiki/Copy-on-write>

Then your output above,
--8<---------------cut here---------------start------------->8---
> /home/maxim/tmp
> /home/maxim/tmp
--8<---------------cut here---------------end--------------->8---
looks the same, but IIUC they have different '/' root dirs, the one
in the container being like an initrd separate file system.

Or is --expose meant to be a shared rw reference to the caller's memory
(directory content or regular file etc) from the start?
That would seem hard to keep safe, so I doubt that's the design.

How do the two tmp's stat? (Before and after writing content
like $PWD/tmp/foo ?

And foo doesn't appear in the caller $PWD/tmp/* right?

What is your use case goal for --expose=/tmp=$PWD/tmp ?

SFTN if this is useless distraction.
--
Regards,
Bengt Richter




Information forwarded to bug-guix <at> gnu.org:
bug#46782; Package guix. (Mon, 13 Feb 2023 21:18:01 GMT) Full text and rfc822 format available.

Message #23 received at 46782 <at> debbugs.gnu.org (full text, mbox):

From: Josselin Poiret <dev <at> jpoiret.xyz>
To: bokr <at> bokr.com, Maxim Cournoyer <maxim.cournoyer <at> gmail.com>
Cc: 46782 <at> debbugs.gnu.org, bbb ee <blasforr <at> gmail.com>,
 Simon Tournier <zimon.toutoune <at> gmail.com>
Subject: Re: bug#46782: guix environment --expose options cannot be layered
 onto $PWD
Date: Mon, 13 Feb 2023 22:17:09 +0100
[Message part 1 (text/plain, inline)]
Hello everyone,

A quick strace shows that it's actually an ordering issue: /home/user is
mounted in the container after /home/user/tmp.  The fix is pretty
simple, moving the cwd first, before the explicit --expose arguments.

I'm noticing that the --expose option creates an empty tmp folder in the
user's home in that case though, which I don't like, however I don't
think there's any better option.  Patch following.

Best,
-- 
Josselin Poiret
[signature.asc (application/pgp-signature, inline)]

Information forwarded to bug-guix <at> gnu.org:
bug#46782; Package guix. (Mon, 13 Feb 2023 21:32:05 GMT) Full text and rfc822 format available.

Message #26 received at 46782 <at> debbugs.gnu.org (full text, mbox):

From: Josselin Poiret <dev <at> jpoiret.xyz>
To: Josselin Poiret <dev <at> jpoiret.xyz>, bokr <at> bokr.com,
 Maxim Cournoyer <maxim.cournoyer <at> gmail.com>
Cc: 46782 <at> debbugs.gnu.org, bbb ee <blasforr <at> gmail.com>,
 Simon Tournier <zimon.toutoune <at> gmail.com>
Subject: [PATCH] scripts: environment: Mount cwd before user specified
 --expose.
Date: Mon, 13 Feb 2023 22:31:21 +0100
* guix/scripts/environment.scm (launch-environment/container): Put cwd mapping
at front of the file system mappings.

Fixes: #46782
---
 guix/scripts/environment.scm | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/guix/scripts/environment.scm b/guix/scripts/environment.scm
index 46435ae48e..8a1fc3c0ee 100644
--- a/guix/scripts/environment.scm
+++ b/guix/scripts/environment.scm
@@ -767,14 +767,14 @@ (define fhs-mappings
              (append
               (override-user-mappings
                user home
-               (append user-mappings
-                       ;; Share current working directory, unless asked not to.
+               (append ;; Share current working directory, unless asked not to.
                        (if map-cwd?
                            (list (file-system-mapping
                                   (source cwd)
                                   (target cwd)
                                   (writable? #t)))
-                           '())))
+                           '())
+                       user-mappings))
               ;; Mappings for the union closure of all inputs.
               (map (lambda (dir)
                      (file-system-mapping

base-commit: dd724cfad45d76b9dcc5b073876c995715c92a07
-- 
2.39.1





Added tag(s) patch. Request was from Simon Tournier <zimon.toutoune <at> gmail.com> to control <at> debbugs.gnu.org. (Tue, 14 Feb 2023 12:25:02 GMT) Full text and rfc822 format available.

Reply sent to Maxim Cournoyer <maxim.cournoyer <at> gmail.com>:
You have taken responsibility. (Tue, 07 Mar 2023 02:24:01 GMT) Full text and rfc822 format available.

Notification sent to Maxim Cournoyer <maxim.cournoyer <at> gmail.com>:
bug acknowledged by developer. (Tue, 07 Mar 2023 02:24:02 GMT) Full text and rfc822 format available.

Message #33 received at 46782-done <at> debbugs.gnu.org (full text, mbox):

From: Maxim Cournoyer <maxim.cournoyer <at> gmail.com>
To: Josselin Poiret <dev <at> jpoiret.xyz>
Cc: 46782-done <at> debbugs.gnu.org, bokr <at> bokr.com, bbb ee <blasforr <at> gmail.com>,
 Simon Tournier <zimon.toutoune <at> gmail.com>
Subject: Re: bug#46782: guix environment --expose options cannot be layered
 onto $PWD
Date: Mon, 06 Mar 2023 21:23:24 -0500
Hello Josselin,

Josselin Poiret <dev <at> jpoiret.xyz> writes:

> Hello everyone,
>
> A quick strace shows that it's actually an ordering issue: /home/user is
> mounted in the container after /home/user/tmp.  The fix is pretty
> simple, moving the cwd first, before the explicit --expose arguments.

Thanks for the troubleshooting and patch!  I've now applied it.

> I'm noticing that the --expose option creates an empty tmp folder in the
> user's home in that case though, which I don't like, however I don't
> think there's any better option.  Patch following.

At least it's better to be left with an empty directory than with
mysteriously nothing happening and the use case not working as expected
:-).

-- 
Thanks,
Maxim




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 04 Apr 2023 11:24:10 GMT) Full text and rfc822 format available.

This bug report was last modified 1 year and 16 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.