Find a file
Maanya Goenka 4b4a8ef741 systemd-analyze: add new option to generate JSON output of security analysis table
The new option --json= works with the 'security' verb and takes in one of three format flags.
These are off which is the default, pretty and short which use JSON format flags for output.
When set to true, it generates a JSON formatted output of the security analysis table. The
format is a JSON array with objects containing the following fields: set which indicates if
the id has been set or not, name which is what is used to refer to the id, json_field
which is the equivalent JSON formatted id name only used for JSON outputs, description which
is an outline of the id state, and exposure which is an unsigned integer in the range 0.0..10.0,
where a higher value corresponds to a higher security threat. The JSON version of the table is
printed on the standard output file.

Example Run:

The unit file testfile.service was created to test the --json= option

maanya-goenka@debian:~/systemd (json-security)$ cat <<EOF >testfile.service

> [Service]
> ExecStart = echo hello
> PrivateNetwork = yes
> PrivateMounts = yes
> PrivateDevices = yes
> EOF

Both the JSON output and the security analysis table below have been truncated to increase readability.
1. Testing for when --json=off

maanya-goenka@debian:~/systemd (json-security)$ sudo build/systemd-analyze security --json=off --root= --offline=true
testfile.service --no-pager

/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/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.
/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.
/home/maanya-goenka/systemd/foo.service:2: Unknown key name 'foo' in section 'Unit', ignoring.

    NAME                                                      DESCRIPTION                                                       EXPOSURE
✓   PrivateNetwork=                                           Service has no access to the host's network
✗   User=/DynamicUser=                                        Service runs as root user                                              0.4
✗   CapabilityBoundingSet=~CAP_SET(UID|GID|PCAP)              Service may change UID/GID identities/capabilities                     0.3
✗   CapabilityBoundingSet=~CAP_NET_ADMIN                      Service has administrator privileges                                   0.3

→ Overall exposure level for testfile.service: 8.3 EXPOSED 🙁

2. Testing for when --json=pretty

maanya-goenka@debian:~/systemd (json-security)$ sudo build/systemd-analyze security --json=pretty --root= --offline=true
testfile.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/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.
/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.
/home/maanya-goenka/systemd/foo.service:2: Unknown key name 'foo' in section 'Unit', ignoring.

[
        {
                "set" : true,
                "name" : "PrivateNetwork=",
		"json-field" : "PrivateNetwork",
                "description" : "Service has no access to the host's network",
                "exposure" : null
        },
        {
                "set" : false,
                "name" : "User=/DynamicUser=",
		"json-field" : "UserOrDynamicUser",
                "decsription" : "Service runs as root user",
                "exposure" : "0.4"
        },
        {
                "set" : false,
                "name" : "CapabilityBoundingSet=~CAP_SET(UID|GID|PCAP)",
		"json_field" : "CapabilityBoundingSet_CAP_SET_UID_GID_PCAP",
                "description" : "Service may change UID/GID identities/capabilities",
                "exposure" : "0.3"
        },
        {
                "set" : false,
                "name" : "CapabilityBoundingSet=~CAP_NET_ADMIN",
		"json_field" : "CapabilityBoundingSet_CAP_NET_ADMIN",
                "description" : "Service has administrator privileges",
                "exposure" : "0.3"
        },
        ...
]

3. Testing for when --json=short

maanya-goenka@debian:~/systemd (json-security)$ sudo build/systemd-analyze security --json=short --root= --offline=true
testfile.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/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.
/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.
/home/maanya-goenka/systemd/foo.service:2: Unknown key name 'foo' in section 'Unit', ignoring.

[{"set":true,"name":"PrivateNetwork=", "json_field":"PrivateNetwork", "description":"Service has no access to the host's network","exposure":null}, ...]
2021-09-06 19:55:27 +01:00
.github ci: Add openSUSE Tumbleweed among tested distros 2021-08-04 11:16:48 +02:00
.lgtm/cpp-queries lgtm: complain about accept() [people should use accept4() instead, due to O_CLOEXEC] 2019-04-10 20:03:38 +02:00
.semaphore ci: drop py2 lxml, pull in jinja2 2021-05-19 10:25:26 +09:00
catalog units: added factory-reset.target 2021-08-10 17:08:00 +02:00
coccinelle coccinelle: filter out a couple of 'false-positive' transformations 2021-03-18 11:59:53 +01:00
docs mkosi: move distro files to mkosi.default.d/ 2021-09-03 13:18:38 +02:00
factory/etc pam: fix typo try_authtok → use_authtok 2021-05-12 12:14:17 +02:00
hwdb.d Fix volume control keys for LG Gram (#20644) 2021-09-06 16:55:11 +02:00
man systemd-analyze: add new option to generate JSON output of security analysis table 2021-09-06 19:55:27 +01:00
mkosi.default.d tree-wide: fix typo 2021-09-05 09:09:13 +02:00
modprobe.d meson: install the right README file in modprobe.d 2021-07-07 14:52:05 +02:00
network network: add 80-container-vb.network 2021-09-04 08:15:34 +09:00
po po: Translated using Weblate (Finnish) 2021-09-01 05:17:52 +09:00
presets boot: optionally update sd-boot on boot 2021-07-30 17:19:55 +02:00
rules.d udev: Fix by-uuid symlink for ubifs volumes 2021-07-02 14:26:18 +01:00
shell-completion systemd-analyze: add new option to generate JSON output of security analysis table 2021-09-06 19:55:27 +01:00
src systemd-analyze: add new option to generate JSON output of security analysis table 2021-09-06 19:55:27 +01:00
sysctl.d meson: use a/b instead of join_paths(a,b) 2021-07-27 19:32:35 +02:00
sysusers.d meson: allow "soft-static" allocations for uids and gids in the initrd 2021-06-17 09:48:28 +02:00
test systemd-analyze: use config value in RestrictNamespaces id (#20645) 2021-09-06 17:33:16 +02:00
tmpfiles.d tmpfiles.d: remove .Test-unix, it's obsolete 2021-08-31 10:57:37 +02:00
tools git-contrib: copypaste-friendly output 2021-07-19 15:39:26 +09:00
units homed: add missing capabilities for SMB/CIFS backend 2021-08-31 10:51:42 +02:00
xorg scripts: use 4 space indentation 2019-04-12 08:30:31 +02:00
.clang-format clang-format: set SpaceBeforeParens to ControlStatementsExceptForEachMacros 2020-11-16 16:57:51 +09:00
.ctags
.dir-locals.el scripts: use 4 space indentation 2019-04-12 08:30:31 +02:00
.editorconfig editorconfig: add man configuration 2020-05-26 15:37:05 +02:00
.gitattributes udev: Extract RAM properties from DMI information 2020-12-16 18:32:29 +01:00
.gitignore gitignore: only ignore *local*.conf" under mkosi.default.d/ 2021-09-03 13:15:52 +02:00
.lgtm.yml ci: bump meson version in LGTM 2021-07-28 11:26:10 +02:00
.mailmap mailmap: two more names 2021-03-30 13:17:58 +02:00
.packit.yml ci: add ppc64le Rawhide chroot to the Packit chroot set 2021-07-19 12:16:36 +01:00
.vimrc scripts: use 4 space indentation 2019-04-12 08:30:31 +02:00
.ycm_extra_conf.py
configure tree-wide: add spdx header on all scripts and helpers 2021-01-28 09:55:35 +01:00
LICENSE.GPL2
LICENSE.LGPL2.1
Makefile tree-wide: add spdx header on all scripts and helpers 2021-01-28 09:55:35 +01:00
meson.build meson.build: change operator combining bools from + to and 2021-09-04 09:09:32 +09:00
meson_options.txt sd-boot: Draw custom edit cursor 2021-08-17 13:59:13 +02:00
mkosi.build mkosi: make mkosi.build shellcheck-clean 2021-09-03 09:54:43 +02:00
NEWS NEWS: net.ipv4.tcp_ecn = 1 was reverted at v240 2021-08-25 09:08:23 +01:00
README README: add requirements for RestrictNetworkInterfaces= 2021-08-19 07:25:01 -05:00
README.md docs: add ARCHITECTURE.md with code map 2021-06-03 22:14:19 +02:00
TODO update TODO 2021-08-31 17:11:10 +02:00

Systemd

System and Service Manager

Count of open issues over time Count of open pull requests over time Semaphore CI 2.0 Build Status
Coverity Scan Status
OSS-Fuzz Status
CIFuzz
CII Best Practices
Language Grade: C/C++
CentOS CI - CentOS 7
CentOS CI - Arch
CentOS CI - Arch (sanitizers)
Fossies codespell report
Packaging status

Details

Most documentation is available on systemd's web site.

Assorted, older, general information about systemd can be found in the systemd Wiki.

Information about build requirements is provided in the README file.

Consult our NEWS file for information about what's new in the most recent systemd versions.

Please see the Code Map for information about this repository's layout and content.

Please see the Hacking guide for information on how to hack on systemd and test your modifications.

Please see our Contribution Guidelines for more information about filing GitHub Issues and posting GitHub Pull Requests.

When preparing patches for systemd, please follow our Coding Style Guidelines.

If you are looking for support, please contact our mailing list or join our IRC channel.

Stable branches with backported patches are available in the stable repo.