aboutsummaryrefslogtreecommitdiffstats
path: root/test/capabilities
diff options
context:
space:
mode:
authorLibravatar netblue30 <netblue30@protonmail.com>2023-03-08 16:23:30 -0500
committerLibravatar netblue30 <netblue30@protonmail.com>2023-03-08 16:23:30 -0500
commitacf8efb878b84882a9df61eff51fdcaceb522a4c (patch)
tree88042e5d0723c36a10efc05774335bd0df52703a /test/capabilities
parentMerge pull request #5717 from glitsj16/aa-examples (diff)
downloadfirejail-acf8efb878b84882a9df61eff51fdcaceb522a4c.tar.gz
firejail-acf8efb878b84882a9df61eff51fdcaceb522a4c.tar.zst
firejail-acf8efb878b84882a9df61eff51fdcaceb522a4c.zip
testing
Diffstat (limited to 'test/capabilities')
-rwxr-xr-xtest/capabilities/capabilities.sh23
-rwxr-xr-xtest/capabilities/caps-join.exp96
-rwxr-xr-xtest/capabilities/caps-print.exp103
-rwxr-xr-xtest/capabilities/caps.exp139
-rw-r--r--test/capabilities/caps1.profile1
-rw-r--r--test/capabilities/caps2.profile1
-rw-r--r--test/capabilities/caps3.profile1
7 files changed, 364 insertions, 0 deletions
diff --git a/test/capabilities/capabilities.sh b/test/capabilities/capabilities.sh
new file mode 100755
index 000000000..50279cd4f
--- /dev/null
+++ b/test/capabilities/capabilities.sh
@@ -0,0 +1,23 @@
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
diff --git a/test/capabilities/caps-join.exp b/test/capabilities/caps-join.exp
new file mode 100755
index 000000000..1830143fb
--- /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"
38after 100
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 100
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 100
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..b403f9ffe
--- /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 100
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 100
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 100
103puts "\nall done\n"
diff --git a/test/capabilities/caps.exp b/test/capabilities/caps.exp
new file mode 100755
index 000000000..dbd63efda
--- /dev/null
+++ b/test/capabilities/caps.exp
@@ -0,0 +1,139 @@
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\r"
11expect {
12 timeout {puts "TESTING ERROR 1\n";exit}
13 -re "Child process initialized in \[0-9\]+.\[0-9\]+ ms"
14}
15after 100
16
17send -- "cat /proc/self/status\r"
18expect {
19 timeout {puts "TESTING ERROR 2\n";exit}
20 "CapBnd: 0000000000000009"
21}
22expect {
23 timeout {puts "TESTING ERROR 3\n";exit}
24 "Seccomp:"
25}
26send -- "exit\r"
27sleep 1
28
29send -- "firejail --caps.drop=all --noprofile\r"
30expect {
31 timeout {puts "TESTING ERROR 4\n";exit}
32 -re "Child process initialized in \[0-9\]+.\[0-9\]+ ms"
33}
34after 100
35
36send -- "cat /proc/self/status\r"
37expect {
38 timeout {puts "TESTING ERROR 5\n";exit}
39 "CapBnd: 0000000000000000"
40}
41expect {
42 timeout {puts "TESTING ERROR 6\n";exit}
43 "Seccomp:"
44}
45send -- "exit\r"
46sleep 1
47
48send -- "firejail --caps.drop=chown,dac_override,dac_read_search,fowner --noprofile\r"
49expect {
50 timeout {puts "TESTING ERROR 7\n";exit}
51 -re "Child process initialized in \[0-9\]+.\[0-9\]+ ms"
52}
53after 100
54
55send -- "cat /proc/self/status\r"
56expect {
57 timeout {puts "TESTING ERROR 8\n";exit}
58 "CapBnd:"
59}
60expect {
61 timeout {puts "TESTING ERROR 9\n";exit}
62 "fffffff0"
63}
64expect {
65 timeout {puts "TESTING ERROR 10\n";exit}
66 "Seccomp:"
67}
68send -- "exit\r"
69sleep 1
70
71
72send -- "firejail --profile=caps1.profile --debug\r"
73expect {
74 timeout {puts "TESTING ERROR 11\n";exit}
75 "Drop CAP_SYS_MODULE"
76}
77expect {
78 timeout {puts "TESTING ERROR 12\n";exit}
79 "Drop CAP_SYS_ADMIN"
80}
81expect {
82 timeout {puts "TESTING ERROR 13\n";exit}
83 "Drop CAP_" {puts "TESTING ERROR 14\n";exit}
84 -re "Child process initialized in \[0-9\]+.\[0-9\]+ ms"
85}
86after 100
87send -- "exit\r"
88sleep 1
89
90
91## tofix: possible problem with caps.keep in profile files
92##send -- "firejail --caps.keep=chown,fowner --noprofile\r"
93#send -- "firejail --profile=caps2.profile\r"
94#expect {
95# timeout {puts "TESTING ERROR 15\n";exit}
96# -re "Child process initialized in \[0-9\]+.\[0-9\]+ ms"
97#}
98#after 100
99#
100#send -- "cat /proc/self/status\r"
101#expect {
102# timeout {puts "TESTING ERROR 16\n";exit}
103# "CapBnd: 0000000000000009"
104#}
105#expect {
106# timeout {puts "TESTING ERROR 17\n";exit}
107# "Seccomp:"
108#}
109#send -- "exit\r"
110#sleep 1
111
112#send -- "firejail --caps.drop=chown,dac_override,dac_read_search,fowner --noprofile\r"
113send -- "firejail --profile=caps3.profile\r"
114expect {
115 timeout {puts "TESTING ERROR 18\n";exit}
116 -re "Child process initialized in \[0-9\]+.\[0-9\]+ ms"
117}
118after 100
119
120send -- "cat /proc/self/status\r"
121expect {
122 timeout {puts "TESTING ERROR 19\n";exit}
123 "CapBnd:"
124}
125expect {
126 timeout {puts "TESTING ERROR 20\n";exit}
127 "fffffff0"
128}
129expect {
130 timeout {puts "TESTING ERROR 21\n";exit}
131 "Seccomp:"
132}
133send -- "exit\r"
134sleep 1
135
136
137
138after 100
139puts "\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