aboutsummaryrefslogtreecommitdiffstats
path: root/test/capabilities
diff options
context:
space:
mode:
Diffstat (limited to 'test/capabilities')
-rwxr-xr-xtest/capabilities/capabilities.sh26
-rwxr-xr-xtest/capabilities/caps-join.exp96
-rwxr-xr-xtest/capabilities/caps-print.exp103
-rwxr-xr-xtest/capabilities/caps.exp115
-rw-r--r--test/capabilities/caps1.profile1
-rw-r--r--test/capabilities/caps2.profile1
-rw-r--r--test/capabilities/caps3.profile1
-rwxr-xr-xtest/capabilities/firemon-caps.exp47
8 files changed, 390 insertions, 0 deletions
diff --git a/test/capabilities/capabilities.sh b/test/capabilities/capabilities.sh
new file mode 100755
index 000000000..2d345025a
--- /dev/null
+++ b/test/capabilities/capabilities.sh
@@ -0,0 +1,26 @@
1#!/bin/bash
2# This file is part of Firejail project
3# Copyright (C) 2014-2023 Firejail Authors
4# License GPL v2
5
6export MALLOC_CHECK_=3
7export MALLOC_PERTURB_=$(($RANDOM % 255 + 1))
8export LC_ALL=C
9
10
11#if grep -q "^CapBnd:\\s0000003fffffffff" /proc/self/status; then
12 echo "TESTING: capabilities (test/filters/caps.exp)"
13 ./caps.exp
14#else
15# echo "TESTING SKIP: other capabilities than expected (test/filters/caps.exp)"
16#fi
17
18echo "TESTING: capabilities print (test/filters/caps-print.exp)"
19./caps-print.exp
20
21echo "TESTING: capabilities join (test/filters/caps-join.exp)"
22./caps-join.exp
23
24echo "TESTING: firemon caps (test/utils/firemon-caps.exp)"
25./firemon-caps.exp
26
diff --git a/test/capabilities/caps-join.exp b/test/capabilities/caps-join.exp
new file mode 100755
index 000000000..ecb43d943
--- /dev/null
+++ b/test/capabilities/caps-join.exp
@@ -0,0 +1,96 @@
1#!/usr/bin/expect -f
2# This file is part of Firejail project
3# Copyright (C) 2014-2023 Firejail Authors
4# License GPL v2
5
6set timeout 10
7match_max 100000
8spawn $env(SHELL)
9set id1 $spawn_id
10spawn $env(SHELL)
11set id2 $spawn_id
12
13send -- "stty -echo\r"
14after 100
15
16#
17# regular run
18#
19set spawn_id $id1
20send -- "firejail --name=jointesting\r"
21expect {
22 timeout {puts "TESTING ERROR 0\n";exit}
23 -re "Child process initialized in \[0-9\]+.\[0-9\]+ ms"
24}
25sleep 1
26
27set spawn_id $id2
28
29send -- "firejail --join=jointesting cat /proc/self/status\r"
30expect {
31 timeout {puts "TESTING ERROR 1\n";exit}
32 "CapBnd: 0000000000000000"
33}
34sleep 1
35
36set spawn_id $id1
37send -- "exit\r"
38sleep 1
39
40#
41# no caps
42#
43set spawn_id $id1
44send -- "firejail --name=jointesting --noprofile\r"
45expect {
46 timeout {puts "TESTING ERROR 10\n";exit}
47 -re "Child process initialized in \[0-9\]+.\[0-9\]+ ms"
48}
49sleep 1
50
51set spawn_id $id2
52
53send -- "firejail --join=jointesting cat /proc/self/status\r"
54expect {
55 timeout {puts "TESTING ERROR 11\n";exit}
56 "CapBnd:"
57}
58expect {
59 timeout {puts "TESTING ERROR 12\n";exit}
60 "fffffffff"
61}
62expect {
63 timeout {puts "TESTING ERROR 13\n";exit}
64 "CapAmb:"
65}
66sleep 1
67
68set spawn_id $id1
69send -- "exit\r"
70after 500
71
72#
73# no caps
74#
75set spawn_id $id1
76send -- "firejail --name=jointesting --noprofile --caps.keep=chown,fowner\r"
77expect {
78 timeout {puts "TESTING ERROR20\n";exit}
79 -re "Child process initialized in \[0-9\]+.\[0-9\]+ ms"
80}
81sleep 1
82
83set spawn_id $id2
84
85send -- "firejail --join=jointesting cat /proc/self/status\r"
86expect {
87 timeout {puts "TESTING ERROR 21\n";exit}
88 "CapBnd: 0000000000000009"
89}
90sleep 1
91
92set spawn_id $id1
93send -- "exit\r"
94after 500
95
96puts "all done\n"
diff --git a/test/capabilities/caps-print.exp b/test/capabilities/caps-print.exp
new file mode 100755
index 000000000..66a7e093b
--- /dev/null
+++ b/test/capabilities/caps-print.exp
@@ -0,0 +1,103 @@
1#!/usr/bin/expect -f
2# This file is part of Firejail project
3# Copyright (C) 2014-2023 Firejail Authors
4# License GPL v2
5
6set timeout 10
7spawn $env(SHELL)
8match_max 100000
9
10send -- "firejail --name=test --noprofile --caps --debug\r"
11expect {
12 timeout {puts "TESTING ERROR 0\n";exit}
13 "Drop CAP_SYS_MODULE"
14}
15expect {
16 timeout {puts "TESTING ERROR 1\n";exit}
17 "Drop CAP_SYS_RAWIO"
18}
19expect {
20 timeout {puts "TESTING ERROR 2\n";exit}
21 "Drop CAP_SYS_BOOT"
22}
23expect {
24 timeout {puts "TESTING ERROR 3\n";exit}
25 "Drop CAP_SYS_NICE"
26}
27expect {
28 timeout {puts "TESTING ERROR 4\n";exit}
29 "Drop CAP_SYS_TTY_CONFIG"
30}
31expect {
32 timeout {puts "TESTING ERROR 5\n";exit}
33 "Drop CAP_SYSLOG"
34}
35expect {
36 timeout {puts "TESTING ERROR 6\n";exit}
37 "Drop CAP_MKNOD"
38}
39expect {
40 timeout {puts "TESTING ERROR 7\n";exit}
41 "Drop CAP_SYS_ADMIN"
42}
43expect {
44 timeout {puts "TESTING ERROR 8\n";exit}
45 -re "Child process initialized in \[0-9\]+.\[0-9\]+ ms"
46}
47sleep 1
48
49spawn $env(SHELL)
50send -- "firejail --caps.print=test\r"
51expect {
52 timeout {puts "TESTING ERROR 9\n";exit}
53 "chown - enabled"
54}
55expect {
56 timeout {puts "TESTING ERROR 10\n";exit}
57 "setgid - enabled"
58}
59expect {
60 timeout {puts "TESTING ERROR 11\n";exit}
61 "setuid - enabled"
62}
63expect {
64 timeout {puts "TESTING ERROR 12\n";exit}
65 "mknod - disabled"
66}
67expect {
68 timeout {puts "TESTING ERROR 13\n";exit}
69 "syslog - disabled"
70}
71after 500
72
73send -- "firejail --debug-caps\r"
74expect {
75 timeout {puts "TESTING ERROR 9\n";exit}
76 "21 - sys_admin"
77}
78expect {
79 timeout {puts "TESTING ERROR 9\n";exit}
80 "22 - sys_boot"
81}
82expect {
83 timeout {puts "TESTING ERROR 9\n";exit}
84 "23 - sys_nice"
85}
86expect {
87 timeout {puts "TESTING ERROR 9\n";exit}
88 "24 - sys_resource"
89}
90after 500
91
92send -- "firejail --caps.keep=\"bla bla bla\"\r"
93expect {
94 timeout {puts "TESTING ERROR 10\n";exit}
95 "capability"
96}
97expect {
98 timeout {puts "TESTING ERROR 11\n";exit}
99 "not found"
100}
101
102after 500
103puts "\nall done\n"
diff --git a/test/capabilities/caps.exp b/test/capabilities/caps.exp
new file mode 100755
index 000000000..bd7ab04eb
--- /dev/null
+++ b/test/capabilities/caps.exp
@@ -0,0 +1,115 @@
1#!/usr/bin/expect -f
2# This file is part of Firejail project
3# Copyright (C) 2014-2023 Firejail Authors
4# License GPL v2
5
6set timeout 10
7spawn $env(SHELL)
8match_max 100000
9
10send -- "firejail --caps.keep=chown,fowner --noprofile cat /proc/self/status\r"
11expect {
12 timeout {puts "TESTING ERROR 1\n";exit}
13 -re "Child process initialized in \[0-9\]+.\[0-9\]+ ms"
14}
15expect {
16 timeout {puts "TESTING ERROR 2\n";exit}
17 "CapBnd: 0000000000000009"
18}
19expect {
20 timeout {puts "TESTING ERROR 3\n";exit}
21 "Seccomp:"
22}
23after 500
24
25send -- "firejail --caps.drop=all --noprofile cat /proc/self/status\r"
26expect {
27 timeout {puts "TESTING ERROR 4\n";exit}
28 -re "Child process initialized in \[0-9\]+.\[0-9\]+ ms"
29}
30expect {
31 timeout {puts "TESTING ERROR 5\n";exit}
32 "CapBnd: 0000000000000000"
33}
34expect {
35 timeout {puts "TESTING ERROR 6\n";exit}
36 "Seccomp:"
37}
38after 500
39
40send -- "firejail --caps.drop=chown,dac_override,dac_read_search,fowner --noprofile cat /proc/self/status\r"
41expect {
42 timeout {puts "TESTING ERROR 7\n";exit}
43 -re "Child process initialized in \[0-9\]+.\[0-9\]+ ms"
44}
45expect {
46 timeout {puts "TESTING ERROR 8\n";exit}
47 "CapBnd:"
48}
49expect {
50 timeout {puts "TESTING ERROR 9\n";exit}
51 "fffffff0"
52}
53expect {
54 timeout {puts "TESTING ERROR 10\n";exit}
55 "Seccomp:"
56}
57after 500
58
59send -- "firejail --profile=caps1.profile --debug ls\r"
60expect {
61 timeout {puts "TESTING ERROR 11\n";exit}
62 "Drop CAP_SYS_MODULE"
63}
64expect {
65 timeout {puts "TESTING ERROR 12\n";exit}
66 "Drop CAP_SYS_ADMIN"
67}
68expect {
69 timeout {puts "TESTING ERROR 13\n";exit}
70 "Drop CAP_" {puts "TESTING ERROR 14\n";exit}
71 -re "Child process initialized in \[0-9\]+.\[0-9\]+ ms"
72}
73after 500
74
75## tofix: possible problem with caps.keep in profile files
76##send -- "firejail --caps.keep=chown,fowner --noprofile\r"
77#send -- "firejail --profile=caps2.profile\r"
78#expect {
79# timeout {puts "TESTING ERROR 15\n";exit}
80# -re "Child process initialized in \[0-9\]+.\[0-9\]+ ms"
81#}
82#after 100
83#
84#send -- "cat /proc/self/status\r"
85#expect {
86# timeout {puts "TESTING ERROR 16\n";exit}
87# "CapBnd: 0000000000000009"
88#}
89#expect {
90# timeout {puts "TESTING ERROR 17\n";exit}
91# "Seccomp:"
92#}
93#send -- "exit\r"
94#sleep 1
95
96#send -- "firejail --caps.drop=chown,dac_override,dac_read_search,fowner --noprofile\r"
97send -- "firejail --profile=caps3.profile cat /proc/self/status\r"
98expect {
99 timeout {puts "TESTING ERROR 18\n";exit}
100 -re "Child process initialized in \[0-9\]+.\[0-9\]+ ms"
101}
102expect {
103 timeout {puts "TESTING ERROR 19\n";exit}
104 "CapBnd:"
105}
106expect {
107 timeout {puts "TESTING ERROR 20\n";exit}
108 "fffffff0"
109}
110expect {
111 timeout {puts "TESTING ERROR 21\n";exit}
112 "Seccomp:"
113}
114after 500
115puts "\nall done\n"
diff --git a/test/capabilities/caps1.profile b/test/capabilities/caps1.profile
new file mode 100644
index 000000000..8b0c3b340
--- /dev/null
+++ b/test/capabilities/caps1.profile
@@ -0,0 +1 @@
caps
diff --git a/test/capabilities/caps2.profile b/test/capabilities/caps2.profile
new file mode 100644
index 000000000..ad49719f1
--- /dev/null
+++ b/test/capabilities/caps2.profile
@@ -0,0 +1 @@
caps.drop chown,dac_override,dac_read_search,fowner
diff --git a/test/capabilities/caps3.profile b/test/capabilities/caps3.profile
new file mode 100644
index 000000000..ad49719f1
--- /dev/null
+++ b/test/capabilities/caps3.profile
@@ -0,0 +1 @@
caps.drop chown,dac_override,dac_read_search,fowner
diff --git a/test/capabilities/firemon-caps.exp b/test/capabilities/firemon-caps.exp
new file mode 100755
index 000000000..905c8cba9
--- /dev/null
+++ b/test/capabilities/firemon-caps.exp
@@ -0,0 +1,47 @@
1#!/usr/bin/expect -f
2# This file is part of Firejail project
3# Copyright (C) 2014-2023 Firejail Authors
4# License GPL v2
5
6set timeout 10
7spawn $env(SHELL)
8match_max 100000
9
10send -- "firejail --name=bingo1 --noprofile --caps\r"
11expect {
12 timeout {puts "TESTING ERROR 0\n";exit}
13 -re "Child process initialized in \[0-9\]+.\[0-9\]+ ms"
14}
15sleep 1
16
17spawn $env(SHELL)
18send -- "firejail --name=bingo2 --noprofile\r"
19expect {
20 timeout {puts "TESTING ERROR 1\n";exit}
21 -re "Child process initialized in \[0-9\]+.\[0-9\]+ ms"
22}
23sleep 1
24
25spawn $env(SHELL)
26send -- "firemon --caps\r"
27expect {
28 timeout {puts "TESTING ERROR 2\n";exit}
29 "need to be root" {puts "TESTING SKIP: /proc mounted as hidepid\n"; exit}
30 "bingo1"
31}
32expect {
33 timeout {puts "TESTING ERROR 3\n";exit}
34 "31cffff"
35}
36expect {
37 timeout {puts "TESTING ERROR 4\n";exit}
38 "bingo2"
39}
40expect {
41 timeout {puts "TESTING ERROR 5\n";exit}
42 "fffffff"
43}
44
45after 500
46
47puts "all done\n"