2 # SPDX-License-Identifier: LGPL-2.1-or-later
3 # shellcheck disable=SC2016
6 # shellcheck source=test/units/util.sh
7 .
"$(dirname "$0")"/util.sh
9 systemctl log-level debug
10 export SYSTEMD_LOG_LEVEL
=debug
14 # We can't really test time, critical-chain and plot verbs here, as
15 # the testsuite service is a part of the boot transaction, so let's assume
18 systemd-analyze
time ||
:
19 systemd-analyze critical-chain ||
:
22 systemd-run
--wait --user --pipe -M testuser@.
host systemd-analyze blame
24 systemd-analyze plot
>/dev
/null ||
:
25 systemd-analyze plot
--json=pretty
>/dev
/null ||
:
26 systemd-analyze plot
--json=short
>/dev
/null ||
:
27 systemd-analyze plot
--json=off
>/dev
/null ||
:
28 systemd-analyze plot
--json=pretty
--no-legend >/dev
/null ||
:
29 systemd-analyze plot
--json=short
--no-legend >/dev
/null ||
:
30 systemd-analyze plot
--json=off
--no-legend >/dev
/null ||
:
31 systemd-analyze plot
--table >/dev
/null ||
:
32 systemd-analyze plot
--table --no-legend >/dev
/null ||
:
33 # legacy/deprecated options (moved to systemctl, but still usable from analyze)
34 systemd-analyze log-level
35 systemd-analyze log-level
"$(systemctl log-level)"
36 systemd-analyze get-log-level
37 systemd-analyze set-log-level
"$(systemctl log-level)"
38 systemd-analyze log-target
39 systemd-analyze log-target
"$(systemctl log-target)"
40 systemd-analyze get-log-target
41 systemd-analyze set-log-target
"$(systemctl log-target)"
42 systemd-analyze service-watchdogs
43 systemd-analyze service-watchdogs
"$(systemctl service-watchdogs)"
45 systemd-analyze dot
>/dev
/null
46 systemd-analyze dot systemd-journald.service
>/dev
/null
47 systemd-analyze dot systemd-journald.service systemd-logind.service
>/dev
/null
48 systemd-analyze dot
--from-pattern="*" --from-pattern="*.service" systemd-journald.service
>/dev
/null
49 systemd-analyze dot
--to-pattern="*" --to-pattern="*.service" systemd-journald.service
>/dev
/null
50 systemd-analyze dot
--from-pattern="*.service" --to-pattern="*.service" systemd-journald.service
>/dev
/null
51 systemd-analyze dot
--order systemd-journald.service systemd-logind.service
>/dev
/null
52 systemd-analyze dot
--require systemd-journald.service systemd-logind.service
>/dev
/null
53 systemd-analyze dot
"systemd-*.service" >/dev
/null
54 (! systemd-analyze dot systemd-journald.service systemd-logind.service
"*" bbb ccc
)
56 # this should be rate limited to 10 calls in 10 minutes for unprivileged callers
58 runas testuser systemd-analyze dump systemd-journald.service
>/dev
/null
60 (! runas testuser systemd-analyze dump
>/dev
/null
)
61 # still limited after a reload
62 systemctl daemon-reload
63 (! runas testuser systemd-analyze dump
>/dev
/null
)
65 systemctl daemon-reexec
66 (! runas testuser systemd-analyze dump
>/dev
/null
)
67 # privileged call, so should not be rate limited
69 systemd-analyze dump systemd-journald.service
>/dev
/null
71 systemd-analyze dump
>/dev
/null
72 systemd-analyze dump
"*" >/dev
/null
73 systemd-analyze dump
"*.socket" >/dev
/null
74 systemd-analyze dump
"*.socket" "*.service" aaaaaaa ...
>/dev
/null
75 systemd-analyze dump systemd-journald.service
>/dev
/null
76 systemd-analyze malloc
>/dev
/null
77 (! systemd-analyze dump
"")
79 systemd-analyze unit-files
>/dev
/null
80 systemd-analyze unit-files systemd-journald.service
>/dev
/null
81 systemd-analyze unit-files
"*" >/dev
/null
82 systemd-analyze unit-files
"*" aaaaaa
"*.service" "*.target" >/dev
/null
83 systemd-analyze unit-files
--user >/dev
/null
84 systemd-analyze unit-files
--user "*" aaaaaa
"*.service" "*.target" >/dev
/null
86 systemd-analyze unit-paths
87 systemd-analyze unit-paths
--user
88 systemd-analyze unit-paths
--global
90 systemd-analyze exit-status
91 systemd-analyze exit-status STDOUT BPF
92 systemd-analyze exit-status
0 1 {63.
.65}
93 (! systemd-analyze exit-status STDOUT BPF
"hello*")
95 systemd-analyze capability
96 systemd-analyze capability cap_chown CAP_KILL
97 systemd-analyze capability
0 1 {30.
.32}
98 (! systemd-analyze capability cap_chown CAP_KILL
"hello*")
100 mkdir
-p /run
/systemd
/system
101 UNIT_NAME
="analyze-condition-$RANDOM.service"
102 cat >"/run/systemd/system/$UNIT_NAME" <<EOF
104 AssertPathExists=/etc/os-release
105 AssertEnvironment=!FOOBAR
106 ConditionKernelVersion=>1.0
107 ConditionPathExists=/etc/os-release
112 systemctl daemon-reload
113 systemd-analyze condition
--unit="$UNIT_NAME"
114 systemd-analyze condition
'ConditionKernelVersion = ! <4.0' \
115 'ConditionKernelVersion = >=3.1' \
116 'ConditionACPower=|false' \
117 'ConditionArchitecture=|!arm' \
118 'AssertPathExists=/etc/os-release'
119 (! systemd-analyze condition
'ConditionArchitecture=|!arm' 'AssertXYZ=foo')
120 (! systemd-analyze condition
'ConditionKernelVersion=<1.0')
121 (! systemd-analyze condition
'AssertKernelVersion=<1.0')
123 systemd-analyze syscall-filter
>/dev
/null
124 systemd-analyze syscall-filter @chown @sync
125 systemd-analyze syscall-filter @sync @sync @sync
126 (! systemd-analyze syscall-filter @chown @sync @foobar
)
127 # filesystems (requires libbpf support)
128 if systemctl
--version |
grep "+BPF_FRAMEWORK"; then
129 systemd-analyze filesystems
>/dev
/null
130 systemd-analyze filesystems @basic-api
131 systemd-analyze filesystems @basic-api @basic-api @basic-api
132 (! systemd-analyze filesystems @basic-api @basic-api @foobar @basic-api
)
135 systemd-analyze calendar
'*-2-29 0:0:0'
136 systemd-analyze calendar
--iterations=5 '*-2-29 0:0:0'
137 systemd-analyze calendar
'*-* *:*:*'
138 systemd-analyze calendar
--iterations=5 '*-* *:*:*'
139 systemd-analyze calendar
--iterations=50 '*-* *:*:*'
140 systemd-analyze calendar
--iterations=0 '*-* *:*:*'
141 systemd-analyze calendar
--iterations=5 '01-01-22 01:00:00'
142 systemd-analyze calendar
--base-time=yesterday
--iterations=5 '*-* *:*:*'
143 (! systemd-analyze calendar
--iterations=0 '*-* 99:*:*')
144 (! systemd-analyze calendar
--base-time=never
'*-* *:*:*')
145 (! systemd-analyze calendar
1)
146 (! systemd-analyze calendar
"")
148 systemd-analyze timestamp now
149 systemd-analyze timestamp
-- -1
150 systemd-analyze timestamp yesterday now tomorrow
151 (! systemd-analyze timestamp yesterday never tomorrow
)
152 (! systemd-analyze timestamp
1)
153 (! systemd-analyze timestamp
'*-2-29 0:0:0')
154 (! systemd-analyze timestamp
"")
156 systemd-analyze timespan
1
157 systemd-analyze timespan
1s
300s
'1year 0.000001s'
158 (! systemd-analyze timespan
1s
300s aaaaaa
'1year 0.000001s')
159 (! systemd-analyze timespan
-- -1)
160 (! systemd-analyze timespan
'*-2-29 0:0:0')
161 (! systemd-analyze timespan
"")
163 systemd-analyze cat-config systemd
/system.conf
>/dev
/null
164 systemd-analyze cat-config
/etc
/systemd
/system.conf
>/dev
/null
165 systemd-analyze cat-config systemd
/system.conf systemd
/journald.conf
>/dev
/null
166 systemd-analyze cat-config systemd
/system.conf foo
/bar systemd
/journald.conf
>/dev
/null
167 systemd-analyze cat-config foo
/bar
169 systemd-analyze security
170 systemd-analyze security
--json=off
171 systemd-analyze security
--json=pretty | jq
172 systemd-analyze security
--json=short | jq
174 if [[ ! -v ASAN_OPTIONS
]]; then
175 # check that systemd-analyze cat-config paths work in a chroot
177 mount
--bind / /tmp
/root
178 systemd-analyze cat-config systemd
/system-preset
>/tmp
/out1
179 chroot
/tmp
/root systemd-analyze cat-config systemd
/system-preset
>/tmp
/out2
184 mkdir
-p /tmp
/img
/usr
/lib
/systemd
/system
/
185 mkdir
-p /tmp
/img
/opt
/
187 touch /tmp
/img
/opt
/script0.sh
188 chmod +x
/tmp
/img
/opt
/script0.sh
190 cat <<EOF >/tmp/img/usr/lib/systemd/system/testfile.service
192 ExecStart = /opt/script0.sh
196 # Default behaviour is to recurse through all dependencies when unit is loaded
197 (! systemd-analyze verify
--root=/tmp
/img
/ testfile.service
)
199 # As above, recurses through all dependencies when unit is loaded
200 (! systemd-analyze verify
--recursive-errors=yes --root=/tmp
/img
/ testfile.service
)
202 # Recurses through unit file and its direct dependencies when unit is loaded
203 (! systemd-analyze verify
--recursive-errors=one
--root=/tmp
/img
/ testfile.service
)
207 # zero exit status since dependencies are ignored when unit is loaded
208 systemd-analyze verify
--recursive-errors=no
--root=/tmp
/img
/ testfile.service
210 rm /tmp
/img
/usr
/lib
/systemd
/system
/testfile.service
212 cat <<EOF >/tmp/testfile.service
217 ExecStart = echo hello
220 cat <<EOF >/tmp/testfile2.service
222 Requires = testfile.service
225 ExecStart = echo hello
228 # Zero exit status since no additional dependencies are recursively loaded when the unit file is loaded
229 systemd-analyze verify
--recursive-errors=no
/tmp
/testfile2.service
232 # Non-zero exit status since all associated dependencies are recursively loaded when the unit file is loaded
233 (! systemd-analyze verify
--recursive-errors=yes /tmp
/testfile2.service
)
236 rm /tmp
/testfile.service
237 rm /tmp
/testfile2.service
239 cat <<EOF >/tmp/sample.service
241 Description = A Sample Service
244 ExecStart = echo hello
248 # Zero exit status since no additional dependencies are recursively loaded when the unit file is loaded
249 systemd-analyze verify
--recursive-errors=no
/tmp
/sample.service
251 cat <<EOF >/tmp/testfile.service
253 ExecStart = echo hello
257 # Prevent regression from #13380 and #20859 where we can't verify hidden files
258 cp /tmp
/testfile.service
/tmp
/.testfile.service
260 systemd-analyze verify
/tmp
/.testfile.service
262 rm /tmp
/.testfile.service
264 # Alias a unit file's name on disk (see #20061)
265 cp /tmp
/testfile.service
/tmp
/testsrvc
267 (! systemd-analyze verify
/tmp
/testsrvc
)
269 systemd-analyze verify
/tmp
/testsrvc
:alias.service
271 # Zero exit status since the value used for comparison determine exposure to security threats is by default 100
272 systemd-analyze security
--offline=true
/tmp
/testfile.service
274 #The overall exposure level assigned to the unit is greater than the set threshold
275 (! systemd-analyze security
--threshold=90 --offline=true
/tmp
/testfile.service
)
277 # Ensure we print the list of ACLs, see https://github.com/systemd/systemd/issues/23185
278 systemd-analyze security
--offline=true
/tmp
/testfile.service |
grep -q -F "/dev/sda"
280 rm /tmp
/testfile.service
282 cat <<EOF >/tmp/img/usr/lib/systemd/system/testfile.service
284 ExecStart = echo hello
290 # The new overall exposure level assigned to the unit is less than the set thresholds
291 # Verifies that the --offline= option works with --root=
292 systemd-analyze security
--threshold=90 --offline=true
--root=/tmp
/img
/ testfile.service
294 # Added an additional "INVALID_ID" id to the .json to verify that nothing breaks when input is malformed
295 # The PrivateNetwork id description and weight was changed to verify that 'security' is actually reading in
296 # values from the .json file when required. The default weight for "PrivateNetwork" is 2500, and the new weight
297 # assigned to that id in the .json file is 6000. This increased weight means that when the "PrivateNetwork" key is
298 # set to 'yes' (as above in the case of testfile.service) in the content of the unit file, the overall exposure
299 # level for the unit file should decrease to account for that increased weight.
300 cat <<EOF >/tmp/testfile.json
301 {"UserOrDynamicUser":
302 {"description_bad": "Service runs as root user",
306 "SupplementaryGroups":
307 {"description_good": "Service has no supplementary groups",
308 "description_bad": "Service runs with supplementary groups",
309 "description_na": "Service runs as root, option does not matter",
314 {"description_good": "Service has no access to hardware devices",
315 "description_bad": "Service potentially has access to hardware devices",
320 {"description_good": "Service cannot install system mounts",
321 "description_bad": "Service may install system mounts",
326 {"description_good": "Service doesn't have access to the host's network",
327 "description_bad": "Service has access to the host's network",
332 {"description_good": "Service has no access to other software's temporary files",
333 "description_bad": "Service has access to other software's temporary files",
338 {"description_good": "Service does not have access to other users",
339 "description_bad": "Service has access to other users",
343 "ProtectControlGroups":
344 {"description_good": "Service cannot modify the control group file system",
345 "description_bad": "Service may modify the control group file system",
349 "ProtectKernelModules":
350 {"description_good": "Service cannot load or read kernel modules",
351 "description_bad": "Service may load or read kernel modules",
355 "ProtectKernelTunables":
356 {"description_good": "Service cannot alter kernel tunables (/proc/sys, …)",
357 "description_bad": "Service may alter kernel tunables",
362 {"description_good": "Service cannot read from or write to the kernel log ring buffer",
363 "description_bad": "Service may read from or write to the kernel log ring buffer",
368 {"description_good": "Service cannot write to the hardware clock or system clock",
369 "description_bad": "Service may write to the hardware clock or system clock",
378 {"description_good": "Service cannot change system host/domainname",
379 "description_bad": "Service may change system host/domainname",
387 "RootDirectoryOrRootImage":
388 {"description_good": "Service has its own root directory/image",
389 "description_bad": "Service runs within the host's root directory",
394 {"description_good": "Service cannot change ABI personality",
395 "description_bad": "Service may change ABI personality",
399 "MemoryDenyWriteExecute":
400 {"description_good": "Service cannot create writable executable memory mappings",
401 "description_bad": "Service may create writable executable memory mappings",
406 {"description_good": "Service processes cannot acquire new privileges",
407 "description_bad": "Service processes may acquire new privileges",
411 "CapabilityBoundingSet_CAP_SYS_ADMIN":
412 {"description_good": "Service has no administrator privileges",
413 "description_bad": "Service has administrator privileges",
417 "CapabilityBoundingSet_CAP_SET_UID_GID_PCAP":
418 {"description_good": "Service cannot change UID/GID identities/capabilities",
419 "description_bad": "Service may change UID/GID identities/capabilities",
423 "CapabilityBoundingSet_CAP_SYS_PTRACE":
424 {"description_good": "Service has no ptrace() debugging abilities",
425 "description_bad": "Service has ptrace() debugging abilities",
429 "CapabilityBoundingSet_CAP_SYS_TIME":
430 {"description_good": "Service processes cannot change the system clock",
431 "description_bad": "Service processes may change the system clock",
435 "CapabilityBoundingSet_CAP_NET_ADMIN":
436 {"description_good": "Service has no network configuration privileges",
437 "description_bad": "Service has network configuration privileges",
441 "CapabilityBoundingSet_CAP_SYS_RAWIO":
442 {"description_good": "Service has no raw I/O access",
443 "description_bad": "Service has raw I/O access",
447 "CapabilityBoundingSet_CAP_SYS_MODULE":
448 {"description_good": "Service cannot load kernel modules",
449 "description_bad": "Service may load kernel modules",
453 "CapabilityBoundingSet_CAP_AUDIT":
454 {"description_good": "Service has no audit subsystem access",
455 "description_bad": "Service has audit subsystem access",
459 "CapabilityBoundingSet_CAP_SYSLOG":
460 {"description_good": "Service has no access to kernel logging",
461 "description_bad": "Service has access to kernel logging",
465 "CapabilityBoundingSet_CAP_SYS_NICE_RESOURCE":
466 {"description_good": "Service has no privileges to change resource use parameters",
467 "description_bad": "Service has privileges to change resource use parameters",
471 "CapabilityBoundingSet_CAP_MKNOD":
472 {"description_good": "Service cannot create device nodes",
473 "description_bad": "Service may create device nodes",
477 "CapabilityBoundingSet_CAP_CHOWN_FSETID_SETFCAP":
478 {"description_good": "Service cannot change file ownership/access mode/capabilities",
479 "description_bad": "Service may change file ownership/access mode/capabilities unrestricted",
483 "CapabilityBoundingSet_CAP_DAC_FOWNER_IPC_OWNER":
484 {"description_good": "Service cannot override UNIX file/IPC permission checks",
485 "description_bad": "Service may override UNIX file/IPC permission checks",
489 "CapabilityBoundingSet_CAP_KILL":
490 {"description_good": "Service cannot send UNIX signals to arbitrary processes",
491 "description_bad": "Service may send UNIX signals to arbitrary processes",
495 "CapabilityBoundingSet_CAP_NET_BIND_SERVICE_BROADCAST_RAW":
496 {"description_good": "Service has no elevated networking privileges",
497 "description_bad": "Service has elevated networking privileges",
501 "CapabilityBoundingSet_CAP_SYS_BOOT":
502 {"description_good": "Service cannot issue reboot()",
503 "description_bad": "Service may issue reboot()",
507 "CapabilityBoundingSet_CAP_MAC":
508 {"description_good": "Service cannot adjust SMACK MAC",
509 "description_bad": "Service may adjust SMACK MAC",
513 "CapabilityBoundingSet_CAP_LINUX_IMMUTABLE":
514 {"description_good": "Service cannot mark files immutable",
515 "description_bad": "Service may mark files immutable",
519 "CapabilityBoundingSet_CAP_IPC_LOCK":
520 {"description_good": "Service cannot lock memory into RAM",
521 "description_bad": "Service may lock memory into RAM",
525 "CapabilityBoundingSet_CAP_SYS_CHROOT":
526 {"description_good": "Service cannot issue chroot()",
527 "description_bad": "Service may issue chroot()",
531 "CapabilityBoundingSet_CAP_BLOCK_SUSPEND":
532 {"description_good": "Service cannot establish wake locks",
533 "description_bad": "Service may establish wake locks",
537 "CapabilityBoundingSet_CAP_WAKE_ALARM":
538 {"description_good": "Service cannot program timers that wake up the system",
539 "description_bad": "Service may program timers that wake up the system",
543 "CapabilityBoundingSet_CAP_LEASE":
544 {"description_good": "Service cannot create file leases",
545 "description_bad": "Service may create file leases",
549 "CapabilityBoundingSet_CAP_SYS_TTY_CONFIG":
550 {"description_good": "Service cannot issue vhangup()",
551 "description_bad": "Service may issue vhangup()",
555 "CapabilityBoundingSet_CAP_SYS_PACCT":
556 {"description_good": "Service cannot use acct()",
557 "description_bad": "Service may use acct()",
566 {"description_good": "Service doesn't share key material with other services",
567 "description_bad": "Service shares key material with other service",
572 {"description_good": "Service has restricted access to process tree(/proc hidepid=)",
573 "description_bad": "Service has full access to process tree(/proc hidepid=)",
578 {"description_good": "Service has no access to non-process/proc files(/proc subset=)",
579 "description_bad": "Service has full access to non-process/proc files(/proc subset=)",
584 {"description_good": "Service child processes cannot alter service state",
585 "description_bad": "Service child processes may alter service state",
590 {"description_good": "Service user cannot leave SysV IPC objects around",
591 "description_bad": "Service user may leave SysV IPC objects around",
592 "description_na": "Service runs as root, option does not apply",
597 {"description_good": "Service does not maintain its own delegated control group subtree",
598 "description_bad": "Service maintains its own delegated control group subtree",
603 {"description_good": "Service realtime scheduling access is restricted",
604 "description_bad": "Service may acquire realtime scheduling",
609 {"description_good": "SUID/SGIDfilecreationbyserviceisrestricted",
610 "description_bad": "ServicemaycreateSUID/SGIDfiles",
614 "RestrictNamespaces_user":
615 {"description_good": "Servicecannotcreateusernamespaces",
616 "description_bad": "Servicemaycreateusernamespaces",
620 "RestrictNamespaces_mnt":
621 {"description_good": "Service cannot create file system namespaces",
622 "description_bad": "Service may create file system namespaces",
626 "RestrictNamespaces_ipc":
627 {"description_good": "Service cannot create IPC namespaces",
628 "description_bad": "Service may create IPC namespaces",
632 "RestrictNamespaces_pid":
633 {"description_good": "Service cannot create process namespaces",
634 "description_bad": "Service may create process namespaces",
638 "RestrictNamespaces_cgroup":
639 {"description_good": "Service cannot create cgroup namespaces",
640 "description_bad": "Service may create cgroup namespaces",
644 "RestrictNamespaces_net":
645 {"description_good": "Service cannot create network namespaces",
646 "description_bad": "Service may create network namespaces",
650 "RestrictNamespaces_uts":
651 {"description_good": "Service cannot create hostname namespaces",
652 "description_bad": "Service may create hostname namespaces",
656 "RestrictAddressFamilies_AF_INET_INET6":
657 {"description_good": "Service cannot allocate Internet sockets",
658 "description_bad": "Service may allocate Internet sockets",
662 "RestrictAddressFamilies_AF_UNIX":
663 {"description_good": "Service cannot allocate local sockets",
664 "description_bad": "Service may allocate local sockets",
668 "RestrictAddressFamilies_AF_NETLINK":
669 {"description_good": "Service cannot allocate netlink sockets",
670 "description_bad": "Service may allocate netlink sockets",
674 "RestrictAddressFamilies_AF_PACKET":
675 {"description_good": "Service cannot allocate packet sockets",
676 "description_bad": "Service may allocate packet sockets",
680 "RestrictAddressFamilies_OTHER":
681 {"description_good": "Service cannot allocate exotic sockets",
682 "description_bad": "Service may allocate exotic sockets",
686 "SystemCallArchitectures":
690 "SystemCallFilter_swap":
694 "SystemCallFilter_obsolete":
698 "SystemCallFilter_clock":
702 "SystemCallFilter_cpu_emulation":
706 "SystemCallFilter_debug":
710 "SystemCallFilter_mount":
714 "SystemCallFilter_module":
718 "SystemCallFilter_raw_io":
722 "SystemCallFilter_reboot":
726 "SystemCallFilter_privileged":
730 "SystemCallFilter_resources":
742 "AmbientCapabilities":
743 {"description_good": "Service process does not receive ambient capabilities",
744 "description_bad": "Service process receives ambient capabilities",
755 # Reads in custom security requirements from the parsed .json file and uses these for comparison
756 systemd-analyze security
--threshold=90 --offline=true \
757 --security-policy=/tmp
/testfile.json \
758 --root=/tmp
/img
/ testfile.service
760 # The strict profile adds a lot of sanboxing options
761 systemd-analyze security
--threshold=25 --offline=true \
762 --security-policy=/tmp
/testfile.json \
764 --root=/tmp
/img
/ testfile.service
766 # The trusted profile doesn't add any sanboxing options
767 (! systemd-analyze security
--threshold=25 --offline=true \
768 --security-policy=/tmp
/testfile.json \
769 --profile=/usr
/lib
/systemd
/portable
/profile
/trusted
/service.conf \
770 --root=/tmp
/img
/ testfile.service
)
772 (! systemd-analyze security
--threshold=50 --offline=true \
773 --security-policy=/tmp
/testfile.json \
774 --root=/tmp
/img
/ testfile.service
)
776 rm /tmp
/img
/usr
/lib
/systemd
/system
/testfile.service
778 if systemd-analyze
--version |
grep -q -F "+ELFUTILS"; then
779 systemd-analyze inspect-elf
--json=short
/lib
/systemd
/systemd |
grep -q -F '"elfType":"executable"'
782 systemd-analyze
--threshold=90 security systemd-journald.service
787 output
=$
(systemd-analyze security
--offline="${2?}" "${3?}" |
grep -F 'SystemCallFilter=')
788 assert_in
"System call ${1?} list" "$output"
789 assert_in
"[+✓] SystemCallFilter=~@swap" "$output"
790 assert_in
"[+✓] SystemCallFilter=~@resources" "$output"
791 assert_in
"[+✓] SystemCallFilter=~@reboot" "$output"
792 assert_in
"[+✓] SystemCallFilter=~@raw-io" "$output"
793 assert_in
"[-✗] SystemCallFilter=~@privileged" "$output"
794 assert_in
"[+✓] SystemCallFilter=~@obsolete" "$output"
795 assert_in
"[+✓] SystemCallFilter=~@mount" "$output"
796 assert_in
"[+✓] SystemCallFilter=~@module" "$output"
797 assert_in
"[+✓] SystemCallFilter=~@debug" "$output"
798 assert_in
"[+✓] SystemCallFilter=~@cpu-emulation" "$output"
799 assert_in
"[-✗] SystemCallFilter=~@clock" "$output"
802 export -n SYSTEMD_LOG_LEVEL
804 mkdir
-p /run
/systemd
/system
805 cat >/run
/systemd
/system
/allow-list.service
<<EOF
808 SystemCallFilter=@system-service
809 SystemCallFilter=~@resources:ENOANO @privileged
810 SystemCallFilter=@clock
813 cat >/run
/systemd
/system
/deny-list.service
<<EOF
816 SystemCallFilter=~@known
817 SystemCallFilter=@system-service
818 SystemCallFilter=~@resources:ENOANO @privileged
819 SystemCallFilter=@clock
822 systemctl daemon-reload
824 check allow
yes /run
/systemd
/system
/allow-list.service
825 check allow no allow-list.service
826 check deny
yes /run
/systemd
/system
/deny-list.service
827 check deny no deny-list.service
829 output
=$
(systemd-run
-p "SystemCallFilter=@system-service" -p "SystemCallFilter=~@resources:ENOANO @privileged" -p "SystemCallFilter=@clock" sleep 60 2>&1)
830 name
=$
(echo "$output" |
awk '{ print $4 }' | cut
-d';' -f1)
832 check allow
yes /run
/systemd
/transient
/"$name"
833 check allow no
"$name"
835 output
=$
(systemd-run
-p "SystemCallFilter=~@known" -p "SystemCallFilter=@system-service" -p "SystemCallFilter=~@resources:ENOANO @privileged" -p "SystemCallFilter=@clock" sleep 60 2>&1)
836 name
=$
(echo "$output" |
awk '{ print $4 }' | cut
-d';' -f1)
838 check deny
yes /run
/systemd
/transient
/"$name"
839 check deny no
"$name"
841 # Let's also test the "image-policy" verb
843 systemd-analyze image-policy
'*' 2>&1 |
grep -q -F "Long form: =verity+signed+encrypted+unprotected+unused+absent"
844 systemd-analyze image-policy
'-' 2>&1 |
grep -q -F "Long form: =unused+absent"
845 systemd-analyze image-policy
'home=encrypted:usr=verity' 2>&1 |
grep -q -F "Long form: usr=verity:home=encrypted:=unused+absent"
846 systemd-analyze image-policy
'home=encrypted:usr=verity' 2>&1 |
grep -q -e '^home \+encrypted \+'
847 systemd-analyze image-policy
'home=encrypted:usr=verity' 2>&1 |
grep -q -e '^usr \+verity \+'
848 systemd-analyze image-policy
'home=encrypted:usr=verity' 2>&1 |
grep -q -e '^root \+ignore \+'
849 systemd-analyze image-policy
'home=encrypted:usr=verity' 2>&1 |
grep -q -e '^usr-verity \+unprotected \+'
851 (! systemd-analyze image-policy
'doedel')
853 # Output is very hard to predict, but let's run it for coverage anyway
855 systemd-analyze pcrs
--json=pretty
856 systemd-analyze pcrs
14 7 0 ima
858 systemd-analyze log-level info