|
| 1 | +--- |
| 2 | +title: Singularity Checks |
| 3 | +sidebar: user_docs |
| 4 | +permalink: docs-admin-checks |
| 5 | +folder: docs |
| 6 | +toc: false |
| 7 | +--- |
| 8 | + |
| 9 | +New to Singularity 2.4 is the ability to, on demand, run container "checks," which can be anything from a filter for sensitive information, to an analysis of content on the filesystem. Checks are installed with Singularity, managed by the administrator, and [available to the user](/docs-user-checks). |
| 10 | + |
| 11 | + |
| 12 | +## What is a check? |
| 13 | +Broadly, a check is a script that is run over a mounted filesystem, primary with the purpose of checking for some security issue. This process is tighly controlled, meaning that the script names in the [checks](https://github.com/singularityware/singularity/tree/development/libexec/helpers/checks) folder are hard coded into the script [check.sh](https://github.com/singularityware/singularity/blob/development/libexec/helpers/check.sh). The flow of checks is the following: |
| 14 | + |
| 15 | + - the user calls `singularity check container.img` to invoke [check.exec](https://github.com/singularityware/singularity/blob/development/libexec/cli/check.exec) |
| 16 | + - specification of `--low` (3), `--med` (2), or `--high` (1) sets the level to perform. The level is a filter, meaning that a level of 3 will include 3,2,1, and a level of 1 (high) will only call checks of high priority. |
| 17 | + - specification of `-t/--tag` will allow the user (or execution script) to specify a kind of check. This is primarily to allow for extending the checks to do other types of things. For example, for this initial batch, these are all considered `default` checks. The [check.help](https://github.com/singularityware/singularity/blob/development/libexec/cli/check.help) displays examples of how the user specifies a tag: |
| 18 | + |
| 19 | +``` |
| 20 | + # Perform all default checks, these are the same |
| 21 | + $ singularity check ubuntu.img |
| 22 | + $ singularity check --tag default ubuntu.img |
| 23 | +
|
| 24 | + # Perform checks with tag "clean" |
| 25 | + $ singularity check --tag clean ubuntu.img |
| 26 | +``` |
| 27 | + |
| 28 | +### Adding a Check |
| 29 | +A check should be a bash (or other) script that will perform some action. The following is required: |
| 30 | + |
| 31 | +**Relative to SINGULARITY_ROOTFS** |
| 32 | +The script must perform check actions relative to `$SINGULARITY_ROOTFS`. For example, in python you might change directory to this location: |
| 33 | + |
| 34 | +``` |
| 35 | +import os |
| 36 | +base = os.environ["SINGULARITY_ROOTFS"] |
| 37 | +os.chdir(base) |
| 38 | +``` |
| 39 | + |
| 40 | +or do the same in bash: |
| 41 | + |
| 42 | +``` |
| 43 | +cd $SINGULARITY_ROOTFS |
| 44 | +ls $SINGULARITY_ROOTFS/var |
| 45 | +``` |
| 46 | + |
| 47 | +Since we are doing a mount, all checks must be static relative to this base, otherwise you are likely checking the host system. |
| 48 | + |
| 49 | +**Verbose** |
| 50 | +The script should indicate any warning/message to the user if the check is found to have failed. If pass, the check's name and status will be printed, with any relevant information. For more thorough checking, you might want to give more verbose output. |
| 51 | + |
| 52 | +**Return Code** |
| 53 | +The script return code of "success" is defined in [check.sh](check.sh), and other return codes are considered not success. When a non success return code is found, the rest of the checks continue running, and no action is taken. We might want to give some admin an ability to specify a check, a level, and prevent continuation of the build/bootstrap given a fail. |
| 54 | + |
| 55 | +**Check.sh** |
| 56 | +The script level, path, and tags should be added to [check.sh](check.sh) in the following format: |
| 57 | + |
| 58 | +``` |
| 59 | +################################################################################## |
| 60 | +# CHECK SCRIPTS |
| 61 | +################################################################################## |
| 62 | +
|
| 63 | +# [SUCCESS] [LEVEL] [SCRIPT] [TAGS] |
| 64 | +execute_check 0 HIGH "bash $SINGULARITY_libexecdir/singularity/helpers/checks/1-hello-world.sh" security |
| 65 | +execute_check 0 LOW "python $SINGULARITY_libexecdir/singularity/helpers/checks/2-cache-content.py" clean |
| 66 | +execute_check 0 HIGH "python $SINGULARITY_libexecdir/singularity/helpers/checks/3-cve.py" security |
| 67 | +``` |
| 68 | + |
| 69 | +The function `execute_check` will compare the level (`[LEVEL]`) with the user specified (or default) `SINGULARITY_CHECKLEVEL` and execute the check only given it is under the specified threshold, and (not yet implemented) has the relevant tag. The success code is also set here with `[SUCCESS]`. Currently, we aren't doing anything with `[TAGS]` and thus perform all checks. |
| 70 | + |
| 71 | + |
| 72 | +## How to tell users? |
| 73 | +If you add a custom check that you want for your users to use, you should tell them about it. Better yet, <a href="https://github.com/singularityware/singularity/issues" target="_blank">tell us </a> about it so it can be integrated into the Singularity software for others to use. |
0 commit comments