2 # SPDX-License-Identifier: LGPL-2.1-or-later
6 systemd-analyze log-level debug
11 # shellcheck disable=SC2016
12 su
"$userid" -s /bin
/sh
-c 'XDG_RUNTIME_DIR=/run/user/$UID exec "$@"' -- sh
"$@"
15 runas testuser systemd-run
--wait --user --unit=test-private-users \
16 -p PrivateUsers
=yes -P echo hello
18 runas testuser systemd-run
--wait --user --unit=test-private-tmp-innerfile \
19 -p PrivateUsers
=yes -p PrivateTmp
=yes \
20 -P touch /tmp
/innerfile.txt
21 # File should not exist outside the job's tmp directory.
22 test ! -e /tmp
/innerfile.txt
24 touch /tmp
/outerfile.txt
25 # File should not appear in unit's private tmp.
26 runas testuser systemd-run
--wait --user --unit=test-private-tmp-outerfile \
27 -p PrivateUsers
=yes -p PrivateTmp
=yes \
28 -P test ! -e /tmp
/outerfile.txt
30 # Confirm that creating a file in home works
31 runas testuser systemd-run
--wait --user --unit=test-unprotected-home \
32 -P touch /home
/testuser
/works.txt
33 test -e /home
/testuser
/works.txt
35 # Confirm that creating a file in home is blocked under read-only
36 runas testuser systemd-run
--wait --user --unit=test-protect-home-read-only \
37 -p PrivateUsers
=yes -p ProtectHome
=read-only \
39 test -e /home/testuser/works.txt || exit 10
40 touch /home/testuser/blocked.txt && exit 11
42 && { echo 'unexpected success'; exit 1; }
43 test ! -e /home
/testuser
/blocked.txt
45 # Check that tmpfs hides the whole directory
46 runas testuser systemd-run
--wait --user --unit=test-protect-home-tmpfs \
47 -p PrivateUsers
=yes -p ProtectHome
=tmpfs \
48 -P test ! -e /home
/testuser
50 # Confirm that home, /root, and /run/user are inaccessible under "yes"
51 # shellcheck disable=SC2016
52 runas testuser systemd-run
--wait --user --unit=test-protect-home-yes \
53 -p PrivateUsers
=yes -p ProtectHome
=yes \
55 test "$(stat -c %a /home)" = "0"
56 test "$(stat -c %a /root)" = "0"
57 test "$(stat -c %a /run/user)" = "0"
60 # Confirm we cannot change groups because we only have one mapping in the user
61 # namespace (no CAP_SETGID in the parent namespace to write the additional
62 # mapping of the user supplied group and thus cannot change groups to an
64 runas testuser systemd-run
--wait --user --unit=test-group-fail \
65 -p PrivateUsers
=yes -p Group
=daemon \
67 && { echo 'unexpected success'; exit 1; }
69 systemd-analyze log-level info