Skip to content

Commit e614168

Browse files
committed
adding docs for checks and daemons
1 parent af2770d commit e614168

5 files changed

Lines changed: 213 additions & 0 deletions

File tree

_data/sidebars/admin_docs.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ entries:
2222
url: /docs-config
2323
output: web, pdf
2424

25+
- title: Container Checks
26+
url: /docs-admin-checks
27+
output: web, pdf
28+
2529
- title: Troubleshooting
2630
url: /docs-troubleshooting
2731
output: web, pdf

_data/sidebars/user_docs.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ entries:
3131
url: /image-content
3232
output: web, pdf
3333

34+
- title: Container Checks
35+
url: /docs-user-checks
36+
output: web, pdf
37+
3438
- title: User Control
3539
url: /user-control
3640
output: web, pdf
@@ -39,6 +43,10 @@ entries:
3943
url: /docs-mount
4044
output: web, pdf
4145

46+
- title: Running Services
47+
url: /docs-instances
48+
output: web, pdf
49+
4250
- title: Environment and Metadata
4351
url: /docs-environment-metadata
4452
output: web, pdf
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
title: Singularity Checks
3+
sidebar: user_docs
4+
permalink: docs-user-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 and [managed by the administration](/docs-admin-checks), however as a user they are accessible to you for use during bootstrap or on demand:
10+
11+
```
12+
# Perform all default checks, these are the same
13+
$ singularity check ubuntu.img
14+
$ singularity check --tag default ubuntu.img
15+
16+
# Perform checks with tag "clean"
17+
$ singularity check --tag clean ubuntu.img
18+
```
19+
20+
## Tags and Organization
21+
Currently, checks are organized by tag and security level. If you know a specific tag that you want to use, for example "docker" deploys checks for containers with Docker imported layers, you can specify the tag:
22+
23+
```
24+
USAGE
25+
26+
-t/--tag tag to filter checks. default is "default"
27+
Available: default, security, docker, clean
28+
29+
30+
EXAMPLE
31+
32+
singularity check --tag docker ubuntu.img
33+
```
34+
35+
If you want to run checks associated with a different security level, you can specify with `--low`, `--med`, or `-high`:
36+
37+
```
38+
USAGE: singularity [...] check [exec options...] <container path>
39+
40+
This command will run security checks for an image.
41+
Note that some checks require sudo.
42+
43+
-l/--low Specify low threshold (all checks, default)
44+
-m/--med Perform medium and high checks
45+
-h/--high Perform only checks at level high
46+
```
47+
48+
Note that some checks will require sudo, and you will be alerted if this is the case and you didn't use it. Finally, if you want to run all default checks, just don't specify a tag or level.
49+
50+
51+
## What checks are available?
52+
Currently, you can view all installable checks [here](https://github.com/singularityware/singularity/blob/development/libexec/helpers/check.sh#L49), and we anticipate adding an ability to view tags that are available, along with your own custom checks. You should also ask your administration if new checks have been added not supported by Singularity. If you want to request adding a new check, please <a href="https://github.com/singularityware/singularity/issues" target="_blank">tell us!</a>.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
---
2+
title: Singularity Container Instances
3+
sidebar: user_docs
4+
permalink: docs-instances
5+
folder: docs
6+
toc: false
7+
---
8+
9+
New to Singularity 2.4 is the ability to clone your image, meaning you create an instance of it that has its own namespace. Why would you want to do this? It means that your container can be instantiated and then serve a process that your computer has control of.
10+
11+
## Why container instances?
12+
Let's say I want to run a web server. With nginx, that is pretty simple, I install nginx and start the service:
13+
14+
```
15+
apt-get update && apt-get install -y nginx
16+
service nginx start
17+
```
18+
19+
With older versions of Singularity, if you were to do something like this, from inside the container you would happily see the service start, and the web server running! But then if you were to log out of the container what would happen?
20+
21+
>> ghost process!!
22+
23+
You would lose control of the process. It would still be running, but you couldn't kill it. This is a called a ghost process, and it means that for running (enduring) services, Singularity was a no starter.
24+
25+
26+
## Cloning containers
27+
With version 2.4, you can do this in a more realistic way. First, let's put the commands of how to start our service into a script. Let's call it a `startscript`. And we can imagine this fitting into a bootstrap recipe file like this:
28+
29+
```
30+
%startscript
31+
32+
service nginx start
33+
```
34+
35+
and we will pretend that we are running with sudo, and we don't specify it above. Now let's say we have a container called `nginx.img` and we want to run it! What do we do?
36+
37+
```
38+
[action] [image] [name of instance]
39+
singularity clone nginx.img service
40+
```
41+
42+
When I do that, I still have my file `nginx.img` sitting on my Desktop, but now you can think about having actually an instance of it running, which I can now control! Heck, I could do that multiple times, if it made sense for my service:
43+
44+
```
45+
singularity clone nginx.img instance1
46+
singularity clone nginx.img instance2
47+
singularity clone nginx.img instance3
48+
```
49+
50+
Once you create this instance, you can't do additional things like binds. So if your service requires a special mount or any other kind of connection, do that at the time of the clone:
51+
52+
```
53+
singularity clone -B /etc/nginx nginx.img instance1
54+
```
55+
56+
## Starting Services
57+
Once you have generated instances, you can start them up! You do that with start, directed to the instance name:
58+
59+
```
60+
singularity start nginx.img instance1
61+
```
62+
63+
## Listing Services
64+
You can then easily list services:
65+
66+
```
67+
singularity list
68+
```
69+
70+
## Important Notes
71+
72+
- The instances are linked with your user. So if you clone and start with sudo, that is going to go under root, and you will be confused to call `singularity list` as your user and then not see your services.
73+
- The only reason to specify the image is because it could be the case that you have two different images with services named equally.
74+
75+
76+
This stuff is completely under development and likely to change! <a href="https://github.com/singularityware/singularity/issues" target="_blank"> Join the conversation!</a>.

0 commit comments

Comments
 (0)