<title>Mounting logging sockets into root environment</title>
<programlisting>BindReadOnlyPaths=/dev/log /run/systemd/journal/socket /run/systemd/journal/stdout</programlisting>
- </example></listitem>
+ </example>
+
+ <xi:include href="system-or-user-ns.xml" xpointer="singular"/></listitem>
</varlistentry>
<varlistentry>
<citerefentry><refentrytitle>os-release</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
<para>Note that usage from user units requires overlayfs support in unprivileged user namespaces,
- which was first introduced in kernel v5.11.</para></listitem>
+ which was first introduced in kernel v5.11.</para>
+
+ <xi:include href="system-or-user-ns.xml" xpointer="singular"/></listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>Capabilities</title>
- <xi:include href="system-only.xml" xpointer="plural"/>
+ <xi:include href="system-or-user-ns.xml" xpointer="plural"/>
<variablelist class='unit-directives'>
<varname>DynamicUser=</varname> is set. This setting cannot ensure protection in all cases. In
general it has the same limitations as <varname>ReadOnlyPaths=</varname>, see below.</para>
- <xi:include href="system-only.xml" xpointer="singular"/></listitem>
+ <xi:include href="system-or-user-ns.xml" xpointer="singular"/></listitem>
</varlistentry>
<varlistentry>
ExecPaths=/usr/sbin/my_daemon /usr/lib /usr/lib64
</programlisting></para>
- <xi:include href="system-only.xml" xpointer="plural"/></listitem>
+ <xi:include href="system-or-user-ns.xml" xpointer="plural"/></listitem>
</varlistentry>
<varlistentry>
then the invoked processes by the unit cannot see any files or directories under <filename>/var/</filename> except for
<filename>/var/lib/systemd</filename> or its contents.</para>
- <xi:include href="system-only.xml" xpointer="singular"/></listitem>
+ <xi:include href="system-or-user-ns.xml" xpointer="singular"/></listitem>
</varlistentry>
<varlistentry>
available), and the unit should be written in a way that does not solely rely on this setting for
security.</para>
- <xi:include href="system-only.xml" xpointer="singular"/></listitem>
+ <xi:include href="system-or-user-ns.xml" xpointer="singular"/></listitem>
</varlistentry>
<varlistentry>
namespaces are not available), and the unit should be written in a way that does not solely rely on
this setting for security.</para>
- <xi:include href="system-only.xml" xpointer="singular"/>
+ <xi:include href="system-or-user-ns.xml" xpointer="singular"/>
<para>When access to some but not all devices must be possible, the <varname>DeviceAllow=</varname>
setting might be used instead. See
<varname>JoinsNamespaceOf=</varname> to listen on sockets inside of network namespaces of other
services.</para>
- <xi:include href="system-only.xml" xpointer="singular"/></listitem>
+ <xi:include href="system-or-user-ns.xml" xpointer="singular"/></listitem>
</varlistentry>
<varlistentry>
<para>When this option is used on a socket unit any sockets bound on behalf of this unit will be
bound within the specified network namespace.</para>
- <xi:include href="system-only.xml" xpointer="singular"/></listitem>
+ <xi:include href="system-or-user-ns.xml" xpointer="singular"/></listitem>
</varlistentry>
<varlistentry>
not available), and the unit should be written in a way that does not solely rely on this setting for
security.</para>
- <xi:include href="system-only.xml" xpointer="singular"/></listitem>
+ <xi:include href="system-or-user-ns.xml" xpointer="singular"/></listitem>
</varlistentry>
<varlistentry>
<varname>IPCNamespacePath=</varname> configured, as otherwise the network namespace of those
units is reused.</para>
- <xi:include href="system-only.xml" xpointer="singular"/></listitem>
+ <xi:include href="system-or-user-ns.xml" xpointer="singular"/></listitem>
</varlistentry>
<varlistentry>
capability (e.g. services for which <varname>User=</varname> is set),
<varname>NoNewPrivileges=yes</varname> is implied.</para>
- <xi:include href="system-only.xml" xpointer="singular"/></listitem>
+ <xi:include href="system-or-user-ns.xml" xpointer="singular"/></listitem>
</varlistentry>
<varlistentry>
doesn't have the <constant>CAP_SYS_ADMIN</constant> capability (e.g. services for which
<varname>User=</varname> is set), <varname>NoNewPrivileges=yes</varname> is implied.</para>
- <xi:include href="system-only.xml" xpointer="singular"/></listitem>
+ <xi:include href="system-or-user-ns.xml" xpointer="singular"/></listitem>
</varlistentry>
<varlistentry>
inaccessible. If <varname>ProtectKernelTunables=</varname> is set,
<varname>MountAPIVFS=yes</varname> is implied.</para>
- <xi:include href="system-only.xml" xpointer="singular"/></listitem>
+ <xi:include href="system-or-user-ns.xml" xpointer="singular"/></listitem>
</varlistentry>
<varlistentry>
but the unit doesn't have the <constant>CAP_SYS_ADMIN</constant> capability (e.g. services for
which <varname>User=</varname> is set), <varname>NoNewPrivileges=yes</varname> is implied.</para>
- <xi:include href="system-only.xml" xpointer="singular"/></listitem>
+ <xi:include href="system-or-user-ns.xml" xpointer="singular"/></listitem>
</varlistentry>
<varlistentry>
capability (e.g. services for which <varname>User=</varname> is set),
<varname>NoNewPrivileges=yes</varname> is implied.</para>
- <xi:include href="system-only.xml" xpointer="singular"/></listitem>
+ <xi:include href="system-or-user-ns.xml" xpointer="singular"/></listitem>
</varlistentry>
<varlistentry>
option. Hence it is primarily useful to explicitly request this behaviour if none of the other settings are
used.</para>
- <xi:include href="system-only.xml" xpointer="singular"/></listitem>
+ <xi:include href="system-or-user-ns.xml" xpointer="singular"/></listitem>
</varlistentry>
<varlistentry>
<para>Usually, it is best to leave this setting unmodified, and use higher level file system namespacing
options instead, in particular <varname>PrivateMounts=</varname>, see above.</para>
- <xi:include href="system-only.xml" xpointer="singular"/></listitem>
+ <xi:include href="system-or-user-ns.xml" xpointer="singular"/></listitem>
</varlistentry>
</variablelist>
-p PrivateUsers=yes -p BindPaths=/dev/null:/etc/os-release \
test ! -s /etc/os-release
+runas testuser systemd-run --wait --user --unit=test-read-write \
+ -p PrivateUsers=yes -p ReadOnlyPaths=/ \
+ -p ReadWritePaths="/var /run /tmp" \
+ -p NoExecPaths=/ -p ExecPaths=/usr \
+ test ! -w /etc/os-release
+
+runas testuser systemd-run --wait --user --unit=test-caps \
+ -p PrivateUsers=yes -p AmbientCapabilities=CAP_SYS_ADMIN \
+ -p CapabilityBoundingSet=CAP_SYS_ADMIN \
+ test -s /etc/os-release
+
+runas testuser systemd-run --wait --user --unit=test-devices \
+ -p PrivateUsers=yes -p PrivateDevices=yes -p PrivateIPC=yes \
+ sh -c "ls -1 /dev/ | wc -l | grep -q -F 18"
+
+# Same check as test/test-execute/exec-privatenetwork-yes.service
+runas testuser systemd-run --wait --user --unit=test-network \
+ -p PrivateUsers=yes -p PrivateNetwork=yes \
+ /bin/sh -x -c '! ip link | grep -E "^[0-9]+: " | grep -Ev ": (lo|(erspan|gre|gretap|ip_vti|ip6_vti|ip6gre|ip6tnl|sit|tunl)0@.*):"'
+
+runas testuser systemd-run --wait --user --unit=test-hostname \
+ -p PrivateUsers=yes -p ProtectHostname=yes \
+ hostnamectl hostname foo \
+ && { echo 'unexpected success'; exit 1; }
+
+runas testuser systemd-run --wait --user --unit=test-clock \
+ -p PrivateUsers=yes -p ProtectClock=yes \
+ timedatectl set-time "2012-10-30 18:17:16" \
+ && { echo 'unexpected success'; exit 1; }
+
+runas testuser systemd-run --wait --user --unit=test-kernel-tunable \
+ -p PrivateUsers=yes -p ProtectKernelTunables=yes \
+ sh -c "echo 0 > /proc/sys/user/max_user_namespaces" \
+ && { echo 'unexpected success'; exit 1; }
+
+runas testuser systemd-run --wait --user --unit=test-kernel-mod \
+ -p PrivateUsers=yes -p ProtectKernelModules=yes \
+ sh -c "modprobe -r overlay && modprobe overlay" \
+ && { echo 'unexpected success'; exit 1; }
+
+if sysctl kernel.dmesg_restrict=0; then
+ runas testuser systemd-run --wait --user --unit=test-kernel-log \
+ -p PrivateUsers=yes -p ProtectKernelLogs=yes -p LogNamespace=yes \
+ dmesg \
+ && { echo 'unexpected success'; exit 1; }
+fi
+
unsquashfs -no-xattrs -d /tmp/img /usr/share/minimal_0.raw
runas testuser systemd-run --wait --user --unit=test-root-dir \
-p PrivateUsers=yes -p RootDirectory=/tmp/img \
mkdir /tmp/img_bind
mount --bind /tmp/img /tmp/img_bind
runas testuser systemd-run --wait --user --unit=test-root-dir-bind \
- -p PrivateUsers=yes -p RootDirectory=/tmp/img_bind \
+ -p PrivateUsers=yes -p RootDirectory=/tmp/img_bind -p MountFlags=private \
grep MARKER=1 /etc/os-release
+umount /tmp/img_bind
# Unprivileged overlayfs was added to Linux 5.11, so try to detect it first
mkdir -p /tmp/a /tmp/b /tmp/c
grep PORTABLE_PREFIXES=app1 /usr/lib/extension-release.d/extension-release.app2
fi
-umount /tmp/img_bind
-
systemd-analyze log-level info
echo OK >/testok