Skip to content

Sandbox script: change handling of TMPDIR#4589

Merged
rjbou merged 6 commits intoocaml:masterfrom
AltGr:sandbox-fix
Mar 10, 2021
Merged

Sandbox script: change handling of TMPDIR#4589
rjbou merged 6 commits intoocaml:masterfrom
AltGr:sandbox-fix

Conversation

@AltGr
Copy link
Copy Markdown
Member

@AltGr AltGr commented Mar 8, 2021

(also: port improvements from bwrap to sandbox_exec, and fix a few
bugs, in particular for detection of the sandbox and newer dune)

The bwrap script now bind-mounts the existing $TMPDIR read-only,
allowing proper communication from outside the sandbox to the inside;
and re-creates a tmpfs someplace else, re-defining TMPDIR.
It might break scripts that accessed /tmp directly (instead of
TMPDIR) though, since it won't be writeable from within the sandbox.

The previous behaviour was to bind-mount $TMPDIR to /tmp within the
sandbox, and re-set TMPDIR accordingly ; however, this meant that absolute
paths within TMPDIR could be incompatible between the outside and the
inside of the sandbox.

This became a visible problem with dune 2.8, which redefines TMPDIR to a
subdirectory (e.g. /tmp/buildXXXX.dune). If you happen to be running
tests with an OPAMROOT within $TMPDIR, your opam root will no longer be
accessible, and packages that run opam commands from within the sandbox
(which is discouraged, but well...) will break.

In our tests, run through dune, OPAMROOT gets created in
/tmp/buildXXXX.dune/OPAM, then packages get installed within a sandbox,
this is relocated to /tmp/OPAM but OPAMROOT and OPAM_SWITCH_PREFIX
remained set to below /tmp/buildXXXX.dune, and things broke.

@rjbou
Copy link
Copy Markdown
Collaborator

rjbou commented Mar 8, 2021

which one is to merge, #4561 or this one ?

@rjbou rjbou added this to the 2.1.0~rc milestone Mar 8, 2021
@AltGr
Copy link
Copy Markdown
Member Author

AltGr commented Mar 9, 2021

Hm, they're probably the same, the merge took too long so I forgot I had already filed it 🤡

AltGr and others added 6 commits March 9, 2021 18:03
The previous behaviour was to bind-mount $TMPDIR to /tmp within the sandbox, and
re-set TMPDIR accordingly ; however, this meant that absolute paths within
TMPDIR could be incompatible between the outside and the inside of the sandbox.

This became a visible problem with dune 2.8, which redefines TMPDIR to a
subdirectory (e.g. `/tmp/buildXXXX.dune`). If you happen to be running tests
with an OPAMROOT within $TMPDIR, your opam root will no longer be accessible,
and packages that run opam commands from within the sandbox (which is
discouraged, but well...) will break.

In our tests, run through dune, OPAMROOT gets created in
`/tmp/buildXXXX.dune/OPAM`, then packages get installed within a sandbox, this
is relocated to `/tmp/OPAM` but `OPAMROOT` and `OPAM_SWITCH_PREFIX` remained set
to below `/tmp/buildXXXX.dune`, and things broke.
this made PWD always rw accessible on remove actions, and was possibly dangerous
@rjbou rjbou mentioned this pull request Mar 9, 2021
@rjbou rjbou merged commit 60434ed into ocaml:master Mar 10, 2021
@rjbou rjbou mentioned this pull request Mar 10, 2021
2 tasks
kit-ty-kate added a commit that referenced this pull request Jun 18, 2021
I'm not sure what was the reason behind having /tmp rw on macos but read-only on linux.
In opam 2.0 it seem to have been the invert at first (rw on linux and ro on macos) however it was synchronized to rw in both in 2.0.8 in see #374.
In opam 2.1~rc a linux-only change was done which made it ro: #4589, but it was never ported to macos.
kit-ty-kate added a commit that referenced this pull request Jul 27, 2021
I'm not sure what was the reason behind having /tmp rw on macos but read-only on linux.
In opam 2.0 it seem to have been the invert at first (rw on linux and ro on macos) however it was synchronized to rw in both in 2.0.8 in see #374.
In opam 2.1~rc a linux-only change was done which made it ro: #4589, but it was never ported to macos.
rjbou pushed a commit to rjbou/opam that referenced this pull request Sep 2, 2021
I'm not sure what was the reason behind having /tmp rw on macos but read-only on linux.
In opam 2.0 it seem to have been the invert at first (rw on linux and ro on macos) however it was synchronized to rw in both in 2.0.8 in see ocaml#374.
In opam 2.1~rc a linux-only change was done which made it ro: ocaml#4589, but it was never ported to macos.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants