Commit dfbda87
committed
systemd-analyze: add new 'security' option to compare unit's overall exposure level with
--threshold option added to work with security verb and with the --offline option so that
users can determine what qualifies as a security threat. The threshold set by the user is
compared with the overall exposure level assigned to a unit file and if the exposure is
higher than the threshold, 'security' will return a non-zero exit status. The default value
of the --threshold option is 100.
Example Run:
1. testcase.service is a unit file created for testing the --threshold option
maanya-goenka@debian:~/systemd (systemd-security)$ cat<<EOF>testcase.service
> [Service]
> ExecStart = echo hello
> EOF
For the purposes of this demo, the security table outputted below has been cut to show only the first two security settings.
maanya-goenka@debian:~/systemd (systemd-security)$ sudo build/systemd-analyze security --offline=true testcase.service
/usr/lib/systemd/system/plymouth-start.service:15: Unit configured to use KillMode=none. This is unsafe, as it disables systemd's
process lifecycle management for the service. Please update your service to use a safer KillMode=, such as 'mixed' or 'control-group'.
Support for KillMode=none is deprecated and will eventually be removed.
/usr/lib/systemd/system/gdm.service:30: Standard output type syslog is obsolete, automatically updating to journal. Please update your
unit file, and consider removing the setting altogether.
/usr/lib/systemd/system/dbus.socket:5: ListenStream= references a path below legacy directory /var/run/, updating
/var/run/dbus/system_bus_socket → /run/dbus/system_bus_socket; please update the unit file accordingly.
NAME DESCRIPTION EXPOSURE
✗ PrivateNetwork= Service has access to the host's network 0.5
✗ User=/DynamicUser= Service runs as root user 0.4
→ Overall exposure level for testcase.service: 9.6 UNSAFE 😨
maanya-goenka@debian:~/systemd (systemd-security)$ echo $? 0
2. Next, we use the same testcase.service file but add an additional --threshold=60 parameter. We would expect 'security' to exit
with a non-zero status because the overall exposure level (= 96) is higher than the set threshold (= 60).
maanya-goenka@debian:~/systemd (systemd-security)$ sudo build/systemd-analyze security --offline=true --threshold=60 testcase.service
/usr/lib/systemd/system/plymouth-start.service:15: Unit configured to use KillMode=none. This is unsafe, as it disables systemd's
process lifecycle management for the service. Please update your service to use a safer KillMode=, such as 'mixed' or 'control-group'.
Support for KillMode=none is deprecated and will eventually be removed.
/usr/lib/systemd/system/gdm.service:30: Standard output type syslog is obsolete, automatically updating to journal. Please update your
unit file, and consider removing the setting altogether.
/usr/lib/systemd/system/dbus.socket:5: ListenStream= references a path below legacy directory /var/run/, updating
/var/run/dbus/system_bus_socket → /run/dbus/system_bus_socket; please update the unit file accordingly.
NAME DESCRIPTION EXPOSURE
✗ PrivateNetwork= Service has access to the host's network 0.5
✗ User=/DynamicUser= Service runs as root user 0.4
→ Overall exposure level for testcase.service: 9.6 UNSAFE 😨
maanya-goenka@debian:~/systemd (systemd-security)$ echo $? 11 parent bb43d85 commit dfbda87
File tree
6 files changed
+50
-14
lines changed- man
- shell-completion
- bash
- zsh
- src/analyze
6 files changed
+50
-14
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
782 | 782 | | |
783 | 783 | | |
784 | 784 | | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
785 | 795 | | |
786 | 796 | | |
787 | 797 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
144 | 144 | | |
145 | 145 | | |
146 | 146 | | |
147 | | - | |
| 147 | + | |
148 | 148 | | |
149 | 149 | | |
150 | 150 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
| 94 | + | |
94 | 95 | | |
95 | 96 | | |
96 | 97 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1527 | 1527 | | |
1528 | 1528 | | |
1529 | 1529 | | |
1530 | | - | |
| 1530 | + | |
1531 | 1531 | | |
1532 | 1532 | | |
1533 | 1533 | | |
| |||
1723 | 1723 | | |
1724 | 1724 | | |
1725 | 1725 | | |
| 1726 | + | |
| 1727 | + | |
| 1728 | + | |
| 1729 | + | |
1726 | 1730 | | |
1727 | 1731 | | |
1728 | 1732 | | |
| |||
2188 | 2192 | | |
2189 | 2193 | | |
2190 | 2194 | | |
2191 | | - | |
| 2195 | + | |
| 2196 | + | |
| 2197 | + | |
2192 | 2198 | | |
2193 | 2199 | | |
2194 | 2200 | | |
| |||
2204 | 2210 | | |
2205 | 2211 | | |
2206 | 2212 | | |
2207 | | - | |
| 2213 | + | |
2208 | 2214 | | |
2209 | 2215 | | |
2210 | 2216 | | |
| |||
2390 | 2396 | | |
2391 | 2397 | | |
2392 | 2398 | | |
2393 | | - | |
| 2399 | + | |
2394 | 2400 | | |
2395 | 2401 | | |
2396 | 2402 | | |
| |||
2405 | 2411 | | |
2406 | 2412 | | |
2407 | 2413 | | |
2408 | | - | |
| 2414 | + | |
2409 | 2415 | | |
2410 | 2416 | | |
2411 | | - | |
| 2417 | + | |
2412 | 2418 | | |
2413 | 2419 | | |
2414 | 2420 | | |
| |||
2467 | 2473 | | |
2468 | 2474 | | |
2469 | 2475 | | |
2470 | | - | |
| 2476 | + | |
2471 | 2477 | | |
2472 | 2478 | | |
2473 | 2479 | | |
2474 | 2480 | | |
2475 | 2481 | | |
2476 | 2482 | | |
2477 | 2483 | | |
2478 | | - | |
| 2484 | + | |
| 2485 | + | |
| 2486 | + | |
2479 | 2487 | | |
2480 | 2488 | | |
2481 | 2489 | | |
2482 | 2490 | | |
2483 | 2491 | | |
2484 | 2492 | | |
2485 | | - | |
| 2493 | + | |
2486 | 2494 | | |
2487 | 2495 | | |
2488 | 2496 | | |
| |||
2542 | 2550 | | |
2543 | 2551 | | |
2544 | 2552 | | |
2545 | | - | |
| 2553 | + | |
2546 | 2554 | | |
2547 | 2555 | | |
2548 | 2556 | | |
| |||
2577 | 2585 | | |
2578 | 2586 | | |
2579 | 2587 | | |
2580 | | - | |
| 2588 | + | |
2581 | 2589 | | |
2582 | 2590 | | |
2583 | 2591 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
| 17 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
| 95 | + | |
95 | 96 | | |
96 | 97 | | |
97 | 98 | | |
| |||
2161 | 2162 | | |
2162 | 2163 | | |
2163 | 2164 | | |
2164 | | - | |
| 2165 | + | |
2165 | 2166 | | |
2166 | 2167 | | |
2167 | 2168 | | |
| |||
2210 | 2211 | | |
2211 | 2212 | | |
2212 | 2213 | | |
| 2214 | + | |
| 2215 | + | |
2213 | 2216 | | |
2214 | 2217 | | |
2215 | 2218 | | |
| |||
2262 | 2265 | | |
2263 | 2266 | | |
2264 | 2267 | | |
| 2268 | + | |
2265 | 2269 | | |
2266 | 2270 | | |
2267 | 2271 | | |
| |||
2273 | 2277 | | |
2274 | 2278 | | |
2275 | 2279 | | |
| 2280 | + | |
2276 | 2281 | | |
2277 | 2282 | | |
2278 | 2283 | | |
| |||
2397 | 2402 | | |
2398 | 2403 | | |
2399 | 2404 | | |
| 2405 | + | |
| 2406 | + | |
| 2407 | + | |
| 2408 | + | |
| 2409 | + | |
| 2410 | + | |
| 2411 | + | |
2400 | 2412 | | |
2401 | 2413 | | |
2402 | 2414 | | |
| |||
2422 | 2434 | | |
2423 | 2435 | | |
2424 | 2436 | | |
| 2437 | + | |
| 2438 | + | |
| 2439 | + | |
| 2440 | + | |
2425 | 2441 | | |
2426 | 2442 | | |
2427 | 2443 | | |
| |||
0 commit comments