nsjail/README.md

382 lines
18 KiB
Markdown
Raw Normal View History

2017-05-07 04:48:24 +08:00
- [What is it](#what-is-it)
2017-05-07 10:10:19 +08:00
- [What forms of isolation does it provide](#what-forms-of-isolation-does-it-provide)
2017-05-07 04:48:24 +08:00
- [Which use-cases are supported](#which-use-cases-are-supported)
2017-05-07 10:15:42 +08:00
* [Isolation of network services (inetd style)](#isolation-of-network-services-inetd-style)
* [Isolation with access to a private, cloned interface (requires root/setuid)](#isolation-with-access-to-a-private-cloned-interface-requires-rootsetuid)
2017-01-16 05:17:14 +08:00
* [Isolation of local processes](#isolation-of-local-processes)
2017-05-07 10:15:42 +08:00
* [Isolation of local processes (and re-running them, if necessary)](#isolation-of-local-processes-and-re-running-them-if-necessary)
* [Bash in a minimal file-system with uid==0 and access to /dev/urandom only](#bash-in-a-minimal-file-system-with-uid0-and-access-to-devurandom-only)
* [Even more contrained shell (with seccomp-bpf policies)](#even-more-contrained-shell-with-seccomp-bpf-policies)
2017-05-07 04:46:09 +08:00
- [More info](#more-info)
2017-05-07 04:33:13 +08:00
- [Launching in Docker](#launching-in-docker)
2017-01-16 05:17:14 +08:00
2017-05-07 10:00:39 +08:00
This is NOT an official Google product.
2017-05-07 04:46:09 +08:00
2017-05-07 10:20:23 +08:00
***
2017-05-07 04:48:24 +08:00
### What is it
2017-05-07 10:03:25 +08:00
NsJail is a process isolation tool for Linux. It utilizes Linux namespace subsystem, resource limits, and the seccomp-bpf syscall filters from the Linux kernel.
2015-05-16 11:18:23 +08:00
2017-05-07 10:03:25 +08:00
It can help with (among other things):
2017-05-08 23:39:29 +08:00
* Isolating __networking services__ (e.g. web, time, DNS), by isolating them from the rest of the OS
* Hosting computer security challenges (so-called __CTFs__)
* Containing invasive syscall-level OS __fuzzers__
2015-05-15 05:44:48 +08:00
2017-05-07 04:33:13 +08:00
Features:
2017-05-08 23:39:29 +08:00
- [x] It offers three __distinct operational modes__. See [this section](#which-use-cases-are-supported) for more info.
- [x] Uses [kafel seccomp-bpf configuration language](https://github.com/google/kafel/) for __flexible syscall policy definitions__.
- [x] It's __rock-solid__.
2015-05-15 08:08:13 +08:00
2017-05-07 10:20:23 +08:00
***
2017-05-07 10:10:19 +08:00
### What forms of isolation does it provide
2017-05-08 23:39:29 +08:00
1. Linux __namespaces__: UTS (hostname), MOUNT (chroot), PID (separate PID tree), IPC, NET (separate networking context), USER
2. __FS constraints__: chroot(), pivot_root(), RO-remounting
3. __Resource limits__ (wall-time/CPU time limits, VM/mem address space limits, etc.)
4. Programmable seccomp-bpf __syscall filters__ (with the [kafel language](https://github.com/google/kafel/))
5. Cloned and separated __Ethernet interfaces__
6. __Cgroups__ for memory and PID utilization control
2015-05-15 05:44:48 +08:00
2017-05-07 10:20:23 +08:00
***
2017-05-07 04:48:24 +08:00
### Which use-cases are supported
#### Isolation of network services (inetd style)
2015-05-15 08:25:55 +08:00
+ Server:
2017-05-07 04:37:01 +08:00
<pre>
2015-05-15 05:44:48 +08:00
$ ./nsjail -Ml --port 9000 --chroot /chroot/ --user 99999 --group 99999 -- /bin/sh -i
2017-05-07 04:37:01 +08:00
</pre>
2015-05-15 05:44:48 +08:00
2015-05-15 08:25:55 +08:00
+ Client:
2017-05-07 04:37:01 +08:00
<pre>
2015-05-16 11:10:13 +08:00
$ nc 127.0.0.1 9000
/ $ ifconfig
/ $ ifconfig -a
lo Link encap:Local Loopback
LOOPBACK MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
/ $ ps wuax
PID USER COMMAND
1 99999 /bin/sh -i
2015-05-16 11:18:23 +08:00
3 99999 {busybox} ps wuax
2015-07-08 01:54:36 +08:00
/ $
2015-05-16 11:10:13 +08:00
2017-05-07 04:37:01 +08:00
</pre>
2015-05-15 05:44:48 +08:00
2017-05-07 10:10:19 +08:00
#### Isolation with access to a private, cloned interface (requires root/setuid)
2017-05-07 04:37:01 +08:00
<pre>
2017-05-11 23:22:32 +08:00
$ sudo ./nsjail --user 9999 --group 9999 --macvlan_iface eth0 --chroot /chroot/ -Mo --macvlan_vs_ip 192.168.0.44 --macvlan_vs_nm 255.255.255.0 --macvlan_vs_gw 192.168.0.1 -- /bin/sh -i
2016-03-02 10:16:50 +08:00
/ $ id
uid=9999 gid=9999
/ $ ip addr sh
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: vs: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue
link/ether ca:a2:69:21:33:66 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.44/24 brd 192.168.0.255 scope global vs
valid_lft forever preferred_lft forever
inet6 fe80::c8a2:69ff:fe21:cd66/64 scope link
valid_lft forever preferred_lft forever
/ $ nc 217.146.165.209 80
GET / HTTP/1.0
HTTP/1.0 302 Found
Cache-Control: private
Content-Type: text/html; charset=UTF-8
Location: http://www.google.ch/?gfe_rd=cr&ei=cEzWVrG2CeTI8ge88ofwDA
Content-Length: 258
Date: Wed, 02 Mar 2016 02:14:08 GMT
2017-05-07 10:03:25 +08:00
...
...
2016-03-02 10:16:50 +08:00
/ $
2017-05-07 04:37:01 +08:00
</pre>
2016-03-02 10:16:50 +08:00
2015-05-16 07:55:25 +08:00
#### Isolation of local processes
2017-05-07 04:37:01 +08:00
<pre>
2015-05-15 05:44:48 +08:00
$ ./nsjail -Mo --chroot /chroot/ --user 99999 --group 99999 -- /bin/sh -i
2015-05-16 11:10:13 +08:00
/ $ ifconfig -a
lo Link encap:Local Loopback
LOOPBACK MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
2015-05-15 05:44:48 +08:00
/ $ id
uid=99999 gid=99999
2015-05-16 11:10:13 +08:00
/ $ ps wuax
PID USER COMMAND
1 99999 /bin/sh -i
2015-05-16 11:18:23 +08:00
4 99999 {busybox} ps wuax
2015-05-15 05:44:48 +08:00
/ $exit
$
2017-05-07 04:37:01 +08:00
</pre>
2015-05-15 05:44:48 +08:00
2017-05-07 10:10:19 +08:00
#### Isolation of local processes (and re-running them, if necessary)
2017-05-07 04:37:01 +08:00
<pre>
2015-05-15 05:44:48 +08:00
$ ./nsjail -Mr --chroot /chroot/ --user 99999 --group 99999 -- /bin/sh -i
BusyBox v1.21.1 (Ubuntu 1:1.21.0-1ubuntu1) built-in shell (ash)
Enter 'help' for a list of built-in commands.
2015-05-16 11:10:13 +08:00
/ $ ps wuax
PID USER COMMAND
1 99999 /bin/sh -i
2 99999 {busybox} ps wuax
2015-05-15 05:44:48 +08:00
/ $ exit
BusyBox v1.21.1 (Ubuntu 1:1.21.0-1ubuntu1) built-in shell (ash)
Enter 'help' for a list of built-in commands.
2015-05-16 11:10:13 +08:00
/ $ ps wuax
PID USER COMMAND
1 99999 /bin/sh -i
2 99999 {busybox} ps wuax
2015-05-15 05:44:48 +08:00
/ $
2017-05-07 04:37:01 +08:00
</pre>
2015-05-15 05:44:48 +08:00
2017-05-07 10:10:19 +08:00
#### Bash in a minimal file-system with uid==0 and access to /dev/urandom only
2017-05-07 04:37:01 +08:00
<pre>
2016-12-11 00:11:55 +08:00
$ ./nsjail -Mo --user 0 --group 99999 -R /bin/ -R /lib -R /lib64/ -R /usr/ -R /sbin/ -T /dev -R /dev/urandom --keep_caps -- /bin/bash -i
[2017-05-24T17:08:02+0200] Mode: STANDALONE_ONCE
[2017-05-24T17:08:02+0200] Jail parameters: hostname:'NSJAIL', chroot:'(null)', process:'/bin/bash', bind:[::]:0, max_conns_per_ip:0, time_limit:0, personality:0, daemonize:false, clone_newnet:true, clone_newuser:true, clone_newns:true, clone_newpid:true, clone_newipc:true, clonew_newuts:true, clone_newcgroup:false, keep_caps:true, tmpfs_size:4194304, disable_no_new_privs:false, pivot_root_only:false
[2017-05-24T17:08:02+0200] Mount point: src:'none' dst:'/' type:'tmpfs' flags:MS_RDONLY|0 options:'' isDir:True
[2017-05-24T17:08:02+0200] Mount point: src:'none' dst:'/proc' type:'proc' flags:MS_RDONLY|0 options:'' isDir:True
[2017-05-24T17:08:02+0200] Mount point: src:'/bin/' dst:'/bin/' type:'' flags:MS_RDONLY|MS_BIND|MS_REC|0 options:'' isDir:True
[2017-05-24T17:08:02+0200] Mount point: src:'/lib' dst:'/lib' type:'' flags:MS_RDONLY|MS_BIND|MS_REC|0 options:'' isDir:True
[2017-05-24T17:08:02+0200] Mount point: src:'/lib64/' dst:'/lib64/' type:'' flags:MS_RDONLY|MS_BIND|MS_REC|0 options:'' isDir:True
[2017-05-24T17:08:02+0200] Mount point: src:'/usr/' dst:'/usr/' type:'' flags:MS_RDONLY|MS_BIND|MS_REC|0 options:'' isDir:True
[2017-05-24T17:08:02+0200] Mount point: src:'/sbin/' dst:'/sbin/' type:'' flags:MS_RDONLY|MS_BIND|MS_REC|0 options:'' isDir:True
[2017-05-24T17:08:02+0200] Mount point: src:'none' dst:'/dev' type:'tmpfs' flags:0 options:'size=4194304' isDir:True
[2017-05-24T17:08:02+0200] Mount point: src:'/dev/urandom' dst:'/dev/urandom' type:'' flags:MS_RDONLY|MS_BIND|MS_REC|0 options:'' isDir:False
[2017-05-24T17:08:02+0200] Uid map: inside_uid:0 outside_uid:69664
[2017-05-24T17:08:02+0200] Gid map: inside_gid:99999 outside_gid:5000
[2017-05-24T17:08:02+0200] Executing '/bin/bash' for '[STANDALONE_MODE]'
bash: cannot set terminal process group (-1): Inappropriate ioctl for device
bash: no job control in this shell
bash-4.3# ls -l
total 28
drwxr-xr-x 2 65534 65534 4096 May 15 14:04 bin
drwxrwxrwt 2 0 99999 60 May 24 15:08 dev
drwxr-xr-x 28 65534 65534 4096 May 15 14:10 lib
drwxr-xr-x 2 65534 65534 4096 May 15 13:56 lib64
dr-xr-xr-x 391 65534 65534 0 May 24 15:08 proc
drwxr-xr-x 2 65534 65534 12288 May 15 14:16 sbin
drwxr-xr-x 17 65534 65534 4096 May 15 13:58 usr
2016-06-19 20:32:27 +08:00
bash-4.3# id
uid=0 gid=99999 groups=65534,99999
bash-4.3# exit
exit
[2017-05-24T17:08:05+0200] PID: 129839 exited with status: 0, (PIDs left: 0)
</pre>
#### /usr/bin/find in a minimal file-system (only /usr/bin/find accessible from /usr/bin)
<pre>
$ ./nsjail -Mo --user 99999 --group 99999 -R /lib/x86_64-linux-gnu/ -R /lib/x86_64-linux-gnu -R /lib64 -R /usr/bin/find -R /dev/urandom --keep_caps -- /usr/bin/find / | wc -l
[2017-05-24T17:04:37+0200] Mode: STANDALONE_ONCE
[2017-05-24T17:04:37+0200] Jail parameters: hostname:'NSJAIL', chroot:'(null)', process:'/usr/bin/find', bind:[::]:0, max_conns_per_ip:0, time_limit:0, personality:0, daemonize:false, clone_newnet:true, clone_newuser:true, clone_newns:true, clone_newpid:true, clone_newipc:true, clonew_newuts:true, clone_newcgroup:false, keep_caps:true, tmpfs_size:4194304, disable_no_new_privs:false, pivot_root_only:false
[2017-05-24T17:04:37+0200] Mount point: src:'none' dst:'/' type:'tmpfs' flags:MS_RDONLY|0 options:'' isDir:True
[2017-05-24T17:04:37+0200] Mount point: src:'none' dst:'/proc' type:'proc' flags:MS_RDONLY|0 options:'' isDir:True
[2017-05-24T17:04:37+0200] Mount point: src:'/lib/x86_64-linux-gnu/' dst:'/lib/x86_64-linux-gnu/' type:'' flags:MS_RDONLY|MS_BIND|MS_REC|0 options:'' isDir:True
[2017-05-24T17:04:37+0200] Mount point: src:'/lib/x86_64-linux-gnu' dst:'/lib/x86_64-linux-gnu' type:'' flags:MS_RDONLY|MS_BIND|MS_REC|0 options:'' isDir:True
[2017-05-24T17:04:37+0200] Mount point: src:'/lib64' dst:'/lib64' type:'' flags:MS_RDONLY|MS_BIND|MS_REC|0 options:'' isDir:True
[2017-05-24T17:04:37+0200] Mount point: src:'/usr/bin/find' dst:'/usr/bin/find' type:'' flags:MS_RDONLY|MS_BIND|MS_REC|0 options:'' isDir:False
[2017-05-24T17:04:37+0200] Mount point: src:'/dev/urandom' dst:'/dev/urandom' type:'' flags:MS_RDONLY|MS_BIND|MS_REC|0 options:'' isDir:False
[2017-05-24T17:04:37+0200] Uid map: inside_uid:99999 outside_uid:69664
[2017-05-24T17:04:37+0200] Gid map: inside_gid:99999 outside_gid:5000
[2017-05-24T17:04:37+0200] Executing '/usr/bin/find' for '[STANDALONE_MODE]'
[2017-05-24T17:04:37+0200] PID: 129525 exited with status: 1, (PIDs left: 0)
2017-05-07 04:37:01 +08:00
</pre>
2016-06-19 20:32:27 +08:00
2017-01-16 05:00:55 +08:00
#### Even more contrained shell (with seccomp-bpf policies)
2017-05-07 04:37:01 +08:00
<pre>
2017-01-16 05:00:55 +08:00
$ ./nsjail --chroot / --seccomp_string 'POLICY a { ALLOW { write, execve, brk, access, mmap, open, newfstat, close, read, mprotect, arch_prctl, munmap, getuid, getgid, getpid, rt_sigaction, geteuid, getppid, getcwd, getegid, ioctl, fcntl, newstat, clone, wait4, rt_sigreturn, exit_group } } USE a DEFAULT KILL' -- /bin/sh -i
[2017-01-15T21:53:08+0100] Mode: STANDALONE_ONCE
[2017-01-15T21:53:08+0100] Jail parameters: hostname:'NSJAIL', chroot:'/', process:'/bin/sh', bind:[::]:0, max_conns_per_ip:0, uid:(ns:1000, global:1000), gid:(ns:1000, global:1000), time_limit:0, personality:0, daemonize:false, clone_newnet:true, clone_newuser:true, clone_newns:true, clone_newpid:true, clone_newipc:true, clonew_newuts:true, clone_newcgroup:false, keep_caps:false, tmpfs_size:4194304, disable_no_new_privs:false, pivot_root_only:false
[2017-01-15T21:53:08+0100] Mount point: src:'/' dst:'/' type:'' flags:0x5001 options:''
[2017-01-15T21:53:08+0100] Mount point: src:'(null)' dst:'/proc' type:'proc' flags:0x0 options:''
[2017-01-15T21:53:08+0100] PID: 18873 about to execute '/bin/sh' for [STANDALONE_MODE]
/bin/sh: 0: can't access tty; job control turned off
$ set
IFS='
'
OPTIND='1'
PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
PPID='0'
PS1='$ '
PS2='> '
PS4='+ '
PWD='/'
$ id
Bad system call
$ exit
[2017-01-15T21:53:17+0100] PID: 18873 exited with status: 159, (PIDs left: 0)
2017-05-07 04:37:01 +08:00
</pre>
2017-01-16 05:00:55 +08:00
2017-05-07 10:20:23 +08:00
***
2017-05-07 04:46:09 +08:00
### More info
2017-05-07 10:10:19 +08:00
The options should be self-explanatory, and these are available with:
2017-05-07 04:46:09 +08:00
2017-05-07 04:37:01 +08:00
<pre>
2016-12-11 03:47:20 +08:00
./nsjail --help
2017-05-07 04:37:01 +08:00
</pre>
2016-12-11 00:17:01 +08:00
2017-05-07 04:37:01 +08:00
<pre>
2015-05-16 07:55:25 +08:00
Usage: ./nsjail [options] -- path_to_command [args]
Options:
2016-03-02 10:10:08 +08:00
--help|-h
2015-05-16 07:55:25 +08:00
Help plz..
2016-06-19 20:32:27 +08:00
--mode|-M VALUE
2016-12-11 00:17:01 +08:00
Execution mode (default: o [MODE_STANDALONE_ONCE]):
2016-03-02 10:10:08 +08:00
l: Wait for connections on a TCP port (specified with --port) [MODE_LISTEN_TCP]
2017-05-07 10:10:19 +08:00
o: Immediately launch a single process on the console using clone/execve [MODE_STANDALONE_ONCE]
e: Immediately launch a single process on the console using execve [MODE_STANDALONE_EXECVE]
r: Immediately launch a single process on the console, keep doing it forever [MODE_STANDALONE_RERUN]
2016-06-19 20:32:27 +08:00
--chroot|-c VALUE
2016-12-11 00:17:01 +08:00
Directory containing / of the jail (default: none)
2016-03-02 10:10:08 +08:00
--rw
2017-05-07 10:10:19 +08:00
Mount / and /proc as RW (default: RO)
2016-06-19 20:32:27 +08:00
--user|-u VALUE
2017-05-07 10:10:19 +08:00
Username/uid of processess inside the jail (default: your current uid). You can also use inside_ns_uid:outside_ns_uid convention here. Can be specified multiple times
2016-06-19 20:32:27 +08:00
--group|-g VALUE
2017-05-07 10:10:19 +08:00
Groupname/gid of processess inside the jail (default: your current gid). You can also use inside_ns_gid:global_ns_gid convention here. Can be specified multiple times
2016-06-19 20:32:27 +08:00
--hostname|-H VALUE
2015-05-16 07:55:25 +08:00
UTS name (hostname) of the jail (default: 'NSJAIL')
2016-06-19 20:32:27 +08:00
--cwd|-D VALUE
2016-03-02 10:10:08 +08:00
Directory in the namespace the process will run (default: '/')
2016-06-19 20:32:27 +08:00
--port|-p VALUE
2016-12-11 00:17:01 +08:00
TCP port to bind to (enables MODE_LISTEN_TCP) (default: 0)
2016-06-19 20:32:27 +08:00
--bindhost VALUE
IP address port to bind to (only in [MODE_LISTEN_TCP]), '::ffff:127.0.0.1' for locahost (default: '::')
--max_conns_per_ip|-i VALUE
2015-05-16 07:55:25 +08:00
Maximum number of connections per one IP (default: 0 (unlimited))
2016-06-19 20:32:27 +08:00
--log|-l VALUE
2016-03-02 10:10:08 +08:00
Log file (default: /proc/self/fd/2)
2016-06-19 20:32:27 +08:00
--time_limit|-t VALUE
2015-07-08 04:17:44 +08:00
Maximum time that a jail can exist, in seconds (default: 600)
2016-03-02 10:10:08 +08:00
--daemon|-d
Daemonize after start
--verbose|-v
Verbose output
2017-05-07 10:10:19 +08:00
--quiet|-q
Only output warning and more important messages
2016-03-02 10:10:08 +08:00
--keep_env|-e
Should all environment variables be passed to the child?
2016-06-19 20:32:27 +08:00
--env|-E VALUE
2016-03-02 10:10:08 +08:00
Environment variable (can be used multiple times)
--keep_caps
Don't drop capabilities (DANGEROUS)
--silent
Redirect child's fd:0/1/2 to /dev/null
--skip_setsid
Don't call setsid(), allows for terminal signal handling in the sandboxed process
2016-06-19 20:32:27 +08:00
--pass_fd VALUE
Don't close this FD before executing child (can be specified multiple times), by default: 0/1/2 are kept open
2016-12-11 00:17:01 +08:00
--pivot_root_only
Only perform pivot_root, no chroot. This will enable nested namespaces
--disable_no_new_privs
Don't set the prctl(NO_NEW_PRIVS, 1) (DANGEROUS)
2016-06-19 20:32:27 +08:00
--rlimit_as VALUE
2015-05-16 07:55:25 +08:00
RLIMIT_AS in MB, 'max' for RLIM_INFINITY, 'def' for the current value (default: 512)
2016-06-19 20:32:27 +08:00
--rlimit_core VALUE
2015-05-16 07:55:25 +08:00
RLIMIT_CORE in MB, 'max' for RLIM_INFINITY, 'def' for the current value (default: 0)
2016-06-19 20:32:27 +08:00
--rlimit_cpu VALUE
2015-05-16 07:55:25 +08:00
RLIMIT_CPU, 'max' for RLIM_INFINITY, 'def' for the current value (default: 600)
2016-06-19 20:32:27 +08:00
--rlimit_fsize VALUE
2015-05-16 07:55:25 +08:00
RLIMIT_FSIZE in MB, 'max' for RLIM_INFINITY, 'def' for the current value (default: 1)
2016-06-19 20:32:27 +08:00
--rlimit_nofile VALUE
2015-05-16 07:55:25 +08:00
RLIMIT_NOFILE, 'max' for RLIM_INFINITY, 'def' for the current value (default: 32)
2016-06-19 20:32:27 +08:00
--rlimit_nproc VALUE
2015-05-16 07:55:25 +08:00
RLIMIT_NPROC, 'max' for RLIM_INFINITY, 'def' for the current value (default: 'def')
2016-06-19 20:32:27 +08:00
--rlimit_stack VALUE
2015-05-16 07:55:25 +08:00
RLIMIT_STACK in MB, 'max' for RLIM_INFINITY, 'def' for the current value (default: 'def')
2016-03-02 10:10:08 +08:00
--persona_addr_compat_layout
personality(ADDR_COMPAT_LAYOUT)
--persona_mmap_page_zero
personality(MMAP_PAGE_ZERO)
--persona_read_implies_exec
personality(READ_IMPLIES_EXEC)
--persona_addr_limit_3gb
personality(ADDR_LIMIT_3GB)
--persona_addr_no_randomize
personality(ADDR_NO_RANDOMIZE)
--disable_clone_newnet|-N
Don't use CLONE_NEWNET. Enable networking inside the jail
--disable_clone_newuser
Don't use CLONE_NEWUSER. Requires euid==0
--disable_clone_newns
Don't use CLONE_NEWNS
--disable_clone_newpid
Don't use CLONE_NEWPID
--disable_clone_newipc
Don't use CLONE_NEWIPC
--disable_clone_newuts
Don't use CLONE_NEWUTS
2016-06-19 20:32:27 +08:00
--enable_clone_newcgroup
Use CLONE_NEWCGROUP
2016-12-11 00:17:01 +08:00
--uid_mapping|-U VALUE
Add a custom uid mapping of the form inside_uid:outside_uid:count. Setting this requires newuidmap to be present
--gid_mapping|-G VALUE
Add a custom gid mapping of the form inside_gid:outside_gid:count. Setting this requires newuidmap to be present
2016-06-19 20:32:27 +08:00
--bindmount_ro|-R VALUE
2016-03-02 10:10:08 +08:00
List of mountpoints to be mounted --bind (ro) inside the container. Can be specified multiple times. Supports 'source' syntax, or 'source:dest'
2016-06-19 20:32:27 +08:00
--bindmount|-B VALUE
2016-03-02 10:10:08 +08:00
List of mountpoints to be mounted --bind (rw) inside the container. Can be specified multiple times. Supports 'source' syntax, or 'source:dest'
2016-06-19 20:32:27 +08:00
--tmpfsmount|-T VALUE
2016-03-02 10:10:08 +08:00
List of mountpoints to be mounted as RW/tmpfs inside the container. Can be specified multiple times. Supports 'dest' syntax
2016-06-19 20:32:27 +08:00
--tmpfs_size VALUE
2016-03-02 10:10:08 +08:00
Number of bytes to allocate for tmpfsmounts (default: 4194304)
--disable_proc
Disable mounting /proc in the jail
2016-12-11 00:17:01 +08:00
--seccomp_policy|-P VALUE
Path to file containing seccomp-bpf policy (see kafel/)
--seccomp_string VALUE
String with kafel seccomp-bpf policy (see kafel/)
2016-06-21 03:54:05 +08:00
--cgroup_mem_max VALUE
Maximum number of bytes to use in the group (default: '0' - disabled)
2016-06-19 20:32:27 +08:00
--cgroup_mem_mount VALUE
2016-06-21 03:54:05 +08:00
Location of memory cgroup FS (default: '/sys/fs/cgroup/memory')
2016-06-20 01:41:11 +08:00
--cgroup_mem_parent VALUE
2016-06-21 03:54:05 +08:00
Which pre-existing memory cgroup to use as a parent (default: 'NSJAIL')
2017-05-07 10:10:19 +08:00
--cgroup_pids_max VALUE
Maximum number of pids in a cgroup (default: '0' - disabled)
--cgroup_pids_mount VALUE
Location of pids cgroup FS (default: '/sys/fs/cgroup/pids')
--cgroup_pids_parent VALUE
Which pre-existing pids cgroup to use as a parent (default: 'NSJAIL')
2016-03-02 10:10:08 +08:00
--iface_no_lo
Don't bring up the 'lo' interface
2017-05-11 23:22:32 +08:00
--macvlan_iface|-I VALUE
2016-06-19 20:32:27 +08:00
Interface which will be cloned (MACVLAN) and put inside the subprocess' namespace as 'vs'
2017-05-11 23:22:32 +08:00
--macvlan_vs_ip VALUE
2016-03-02 10:10:08 +08:00
IP of the 'vs' interface
2017-05-11 23:22:32 +08:00
--macvlan_vs_nm VALUE
2016-03-02 10:10:08 +08:00
Netmask of the 'vs' interface
2017-05-11 23:22:32 +08:00
--macvlan_vs_gw VALUE
2016-03-02 10:10:08 +08:00
Default GW for the 'vs' interface
2016-06-19 20:32:27 +08:00
Examples:
Wait on a port 31337 for connections, and run /bin/sh
nsjail -Ml --port 31337 --chroot / -- /bin/sh -i
Re-run echo command as a sub-process
nsjail -Mr --chroot / -- /bin/echo "ABC"
Run echo command once only, as a sub-process
nsjail -Mo --chroot / -- /bin/echo "ABC"
2016-06-21 03:54:05 +08:00
Execute echo command directly, without a supervising process
nsjail -Me --chroot / --disable_proc -- /bin/echo "ABC"
2017-05-07 04:37:01 +08:00
</pre>
2017-04-21 21:35:50 +08:00
2017-05-07 10:20:23 +08:00
***
2017-05-07 04:46:09 +08:00
### Launching in Docker
2017-04-21 21:35:50 +08:00
To launch nsjail in a docker container clone the repository and build the docker image:
2017-05-07 04:37:01 +08:00
<pre>
2017-04-21 21:35:50 +08:00
docker build . -t nsjail
2017-05-07 04:37:24 +08:00
</pre>
2017-04-21 21:35:50 +08:00
This will build up an image containing njsail and kafel.
From now you can either use it in another Dockerfile (`FROM nsjail`) or directly:
2017-05-07 04:37:01 +08:00
<pre>
2017-04-21 21:35:50 +08:00
docker run --rm -it nsjail nsjail --user 99999 --group 99999 --disable_proc --chroot / --time_limit 30 /bin/bash
2017-05-07 04:37:01 +08:00
</pre>