Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Isolate singularity containers more thoroughly for better reproducibility. #18628

Open
wants to merge 10 commits into
base: dev
Choose a base branch
from

Conversation

rhpvorderman
Copy link
Contributor

@rhpvorderman rhpvorderman commented Jul 31, 2024

This fixes #18620 and several other issues.

  • singularity exec is now always passed the --contain flag. This ensures only volumes explicitly requested by galaxy are mounted. Singularity mounts $HOME and $PWD by default, but that is redundant since galaxy also mounts the relevant directories.
  • singularity exec is now passed the --ipc and --pid flags that isolate the IPC and PID namespace respectively. This does not matter much for reproducibility but may fix issues that can occur in tools using the Python multiprocessing module, such as cutadapt. This behavior can be turned of by setting singularity_ipc and singularity_pid to false.
  • $HOME is no longer mounted by default, see Mounting home in singularity containers is bad for security, reproducibility and creates race conditions #18620. This can be re-enabled by setting singularity_mount_home to true.
  • By default galaxy ensures a read-only /tmp directory, while simultaneously mounting a specific job temporary directory and setting the appropriate TMP and TMPDIR environment variables. Unfortunately some problematic tools (I am looking at you FastQC!) always write to /tmp and crash as a result. Setting the job tmp_dir variable to true alleviates this problem. This is now documented in the advanced job xml conf sample.
    EDIT
  • The work_directory variable is now actually used, ensuring that the work is executed in the Per-job work directory rather than HOME.
    /EDIT

How to test the changes?

(Select all options that apply)

  • I've included appropriate automated tests.
  • This is a refactoring of components with existing test coverage.
  • Instructions for manual testing are as follows:
    1. [add testing steps and prerequisites here if you didn't write automated tests covering all your changes]

License

  • I agree to license these and all my past contributions to the core galaxy codebase under the MIT license.

@@ -604,6 +604,12 @@
</destination>
<destination id="singularity_local" runner="local">
<param id="singularity_enabled">true</param>
<!--Galaxy requests an isolated /tmp directory from singularity, which means
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the read-only part of this statement true)?

See discussion in #15673 and tests that have been added in #15614

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. No mount /tmp means /tmp is not mounted. There is still a /tmp dir in the container itself though, it is made read-only .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the discussion you shared

instead (by default) provide a writable /tmp via $_GALAXY_JOB_TMP_DIR/:/tmp:rw note that this dir is still also available as $_GALAXY_JOB_TMP_DIR:rw

I found that this /tmp mount is only provided when tmp_dir is set to true. Is that intentional behavior?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found that this /tmp mount is only provided when tmp_dir is set to true. Is that intentional behavior?

Guess so... and if one of TMP, TEMP, TMPDIR is /tmp, or?

Regarding FastQC: we should set --dir in the tool wrapper: https://github.com/s-andrews/FastQC/blob/1faeea0412093224d7f6a07f777fad60a5650795/fastqc#L480 .. the culprit here seems to be JAVA (just another reason to dislike it).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +608 to +609
it will be mounted as read-only. This can cause some problems with tools that
do not use the TMP, TEMP, TMPDIR variable family properly. Setting
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tools that do not use the TMP, TEMP, TMPDIR variable family properly

What does this mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Proper applications create a temporary directory/file in the directory designated by TMPDIR. Shitty applications just hardcode /tmp. Which causes problems when /tmp is mounted read-only if --no-mount tmp is chosen and no other directory is mounted to the /tmp path.

@rhpvorderman
Copy link
Contributor Author

I see now that the mount_home setting is wrong. On newer tool_profiles galaxy will set the $HOME environment variable to point to the correct per job directory. On older tool profiles, home should actually be mounted as this is mentioned in the documentation: https://docs.galaxyproject.org/en/master/dev/schema.html#id2.
So I will fix that.

bernt-matthias added a commit to bernt-matthias/tools-iuc that referenced this pull request Aug 5, 2024
Comment on lines +638 to +649
<!-- Singularity by default inherits the PID namespace, this can give
issues with multiprocessing, hence galaxy passes the `pid` argument
by default to isolate the PID namespace. You can turn this of by setting
singularity_pid to `false`.
-->
<!-- <param id="singularity_pid">true</param> -->
<!-- Singularity by default inherits the IPC namespace, this can give
issues with multiprocessing, hence galaxy passes the `ipc` argument
by default to isolate the PID namespace. You can turn this of by setting
singularity_ipc to `false`.
-->
<!-- <param id="singularity_ipc">true</param> -->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to expose these 2 arguments as options, or should we just always enabled them as you are proposing to do for --contain ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--contain is not an invasive param. You can undo its effects by simply manually adding the volumes.
This is not the case with --ipc and --pid (as far as I can see). So having an option to disable the flags might be very useful if they cause problems in some tools.

We have never experienced problems with --ipc and --pid at our institute, in fact, we experienced problems when they were not used. However I still take the conservative approach here to allow admins to at least turn it off if it gives them problems.

bernt-matthias added a commit to galaxyproject/tools-iuc that referenced this pull request Aug 6, 2024
* fastqc: set tmpdir

xref galaxyproject/galaxy#18628

* Update tools/fastqc/rgFastQC.xml

Co-authored-by: Marius van den Beek <[email protected]>

---------

Co-authored-by: Marius van den Beek <[email protected]>
nilchia pushed a commit to pavanvidem/tools-iuc that referenced this pull request Aug 24, 2024
* fastqc: set tmpdir

xref galaxyproject/galaxy#18628

* Update tools/fastqc/rgFastQC.xml

Co-authored-by: Marius van den Beek <[email protected]>

---------

Co-authored-by: Marius van den Beek <[email protected]>
@mvdbeek mvdbeek requested a review from natefoo November 12, 2024 15:47
@jdavcs jdavcs modified the milestones: 24.2, 25.0 Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mounting home in singularity containers is bad for security, reproducibility and creates race conditions
4 participants