feat(profile): rewrite the dbus profiles.

Replace the old dbus-broker/dbus-daemon profiles stack by a new unified set of
profiles that does not depend-on the dbus implementation used.

Ensure that a given bus is fully managed by one unified profile:
- We need to allow far fewer rules than before (especially by splitting
  dbus-system and dbus-session).
- It has the side effect to fix some long-running issues regarding dbus start
  (see: #74, #80 & #235) while keeping all dbus server in the same place.
This commit is contained in:
Alexandre Pujol 2024-03-16 13:03:32 +00:00
parent 4819022202
commit 61e2cb55ac
Failed to generate hash of commit
10 changed files with 199 additions and 360 deletions

View file

@ -12,17 +12,9 @@ profile at-spi2-registryd @{exec_path} flags=(attach_disconnected) {
include <abstractions/base> include <abstractions/base>
include <abstractions/bus-accessibility> include <abstractions/bus-accessibility>
include <abstractions/bus-session> include <abstractions/bus-session>
include <abstractions/bus/org.a11y>
include <abstractions/bus/org.gnome.SessionManager> include <abstractions/bus/org.gnome.SessionManager>
include <abstractions/nameservice-strict>
include <abstractions/X-strict>
signal (receive) set=(term hup kill) peer=@{systemd},
signal (receive) set=(term hup kill) peer=dbus-daemon,
signal (receive) set=(term hup kill) peer=gdm*,
# dbus: own bus=accessibility name=org.a11y.atspi.{R,r}egistry # dbus: own bus=accessibility name=org.a11y.atspi.{R,r}egistry
dbus send bus=accessibility path=/org/a11y/atspi/accessible/root dbus send bus=accessibility path=/org/a11y/atspi/accessible/root
interface=org.freedesktop.DBus.Properties interface=org.freedesktop.DBus.Properties
member=Set member=Set
@ -31,12 +23,16 @@ profile at-spi2-registryd @{exec_path} flags=(attach_disconnected) {
interface=org.a11y.atspi.Socket interface=org.a11y.atspi.Socket
member=Embed member=Embed
peer=(name=:*), peer=(name=:*),
dbus receive bus=accessibility path=/org/a11y/atspi/registry/deviceeventcontroller dbus receive bus=accessibility path=/org/a11y/atspi/registry/deviceeventcontroller
interface=org.a11y.atspi.DeviceEventController interface=org.a11y.atspi.DeviceEventController
member={GetKeystrokeListeners,GetDeviceEventListeners} member={GetKeystrokeListeners,GetDeviceEventListeners}
peer=(name=:*), peer=(name=:*),
dbus send bus=session path=/org/a11y/bus
interface=org.a11y.Bus
member=GetAddress
peer=(name=org.a11y.Bus, label=dbus-accessibility),
dbus receive bus=session dbus receive bus=session
interface=org.freedesktop.DBus.Introspectable interface=org.freedesktop.DBus.Introspectable
member=Introspect member=Introspect
@ -44,7 +40,5 @@ profile at-spi2-registryd @{exec_path} flags=(attach_disconnected) {
@{exec_path} mr, @{exec_path} mr,
owner /dev/tty@{int} rw,
include if exists <local/at-spi2-registryd> include if exists <local/at-spi2-registryd>
} }

View file

@ -0,0 +1,62 @@
# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2024 Alexandre Pujol <alexandre@pujol.io>
# SPDX-License-Identifier: GPL-2.0-only
abi <abi/3.0>,
include <tunables/global>
@{exec_path} = @{lib}/{,at-spi2{,-core}/}at-spi-bus-launcher
profile dbus-accessibility @{exec_path} flags=(attach_disconnected) {
include <abstractions/base>
include <abstractions/bus-accessibility>
include <abstractions/bus-session>
include <abstractions/bus/org.a11y>
include <abstractions/bus/org.gnome.SessionManager>
include <abstractions/dconf-write>
include <abstractions/nameservice-strict>
signal (receive) set=(term hup kill) peer=dbus-session,
signal (receive) set=(term hup kill) peer=gdm,
dbus bus=accessibility,
# dbus: own bus=session name=org.a11y.{B,b}us
dbus receive bus=session
interface=org.freedesktop.DBus.Introspectable
member=Introspect
peer=(name=:*, label=gnome-shell),
@{exec_path} mrix,
@{bin}/dbus-broker rix,
@{bin}/dbus-broker-launch rix,
@{bin}/dbus-daemon rix,
@{lib}/at-spi2-registryd rPx,
@{lib}/at-spi2{,-core}/at-spi2-registryd rPx,
/usr/share/dbus-1/accessibility-services/{,**} r,
/usr/share/dconf/profile/gdm r,
/usr/share/defaults/at-spi2/{,**} r,
/usr/share/gdm/greeter-dconf-defaults r,
/usr/share/glib-2.0/schemas/gschemas.compiled r,
/etc/machine-id r,
/var/lib/gdm{3,}/.config/dconf/user r,
/var/lib/gdm{3,}/greeter-dconf-defaults r,
@{run}/systemd/userdb/ r,
@{run}/systemd/users/@{uid} r,
@{sys}/kernel/security/apparmor/.access rw,
@{PROC}/@{pid}/cgroup r,
@{PROC}/@{pid}/cmdline r,
@{PROC}/@{pid}/oom_score_adj r,
@{PROC}/sys/kernel/random/boot_id r,
owner @{PROC}/@{pid}/fd/ r,
include if exists <local/dbus-accessibility>
}

View file

@ -1,45 +0,0 @@
# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2024 Alexandre Pujol <alexandre@pujol.io>
# SPDX-License-Identifier: GPL-2.0-only
abi <abi/3.0>,
include <tunables/global>
@{exec_path} = @{bin}/dbus-broker
profile dbus-broker @{exec_path} flags=(attach_disconnected) {
include <abstractions/base>
include <abstractions/bus-accessibility>
include <abstractions/bus-session>
include <abstractions/bus-system>
include <abstractions/nameservice-strict>
network netlink raw,
network bluetooth stream,
network bluetooth seqpacket,
dbus bus=accessibility,
dbus bus=session,
dbus bus=system,
@{exec_path} mr,
@{bin}/* rPUx,
# Extra rules for GDM
/var/lib/gdm{3,}/.local/share/icc/ r,
/var/lib/gdm{3,}/.local/share/icc/edid-*.icc r,
@{user_share_dirs}/icc/ r,
@{user_share_dirs}/icc/edid-*.icc r,
@{run}/systemd/sessions/*.ref rw,
@{run}/systemd/inhibit/*.ref rw,
/dev/dri/card@{int} rw,
/dev/input/event@{int} rw,
@{PROC}/sys/kernel/cap_last_cap r,
include if exists <local/dbus-broker>
}

View file

@ -1,35 +0,0 @@
# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2024 Alexandre Pujol <alexandre@pujol.io>
# SPDX-License-Identifier: GPL-2.0-only
abi <abi/3.0>,
include <tunables/global>
@{exec_path} = @{bin}/dbus-broker-launch
profile dbus-broker-launch @{exec_path} flags=(attach_disconnected) {
include <abstractions/base>
include <abstractions/nameservice-strict>
capability net_admin,
capability setgid,
capability setuid,
@{exec_path} mr,
@{bin}/dbus-broker rPx,
/usr/share/dbus-1/{,**} r,
/usr/share/defaults/**.conf r,
# Extra rules for Flatpak
@{system_share_dirs}/dbus-1/{,**} r,
/etc/machine-id r,
@{run}/user/@{uid}/dbus-1/{,**} r,
@{PROC}/sys/kernel/random/boot_id r,
include if exists <local/dbus-broker-launch>
}

View file

@ -1,129 +0,0 @@
# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2020-2022 Mikhail Morfikov
# Copyright (C) 2021-2024 Alexandre Pujol <alexandre@pujol.io>
# SPDX-License-Identifier: GPL-2.0-only
abi <abi/3.0>,
include <tunables/global>
@{exec_path} = @{bin}/dbus-daemon
profile dbus-daemon @{exec_path} flags=(attach_disconnected) {
include <abstractions/base>
include <abstractions/bus-accessibility>
include <abstractions/bus-session>
include <abstractions/bus-system>
include <abstractions/consoles>
include <abstractions/dconf-write>
include <abstractions/nameservice-strict>
capability audit_write,
capability setgid,
capability setuid,
capability sys_resource,
network netlink raw,
network unix stream,
network bluetooth stream,
network bluetooth seqpacket,
signal (receive) set=(term hup kill) peer=at-spi-bus-launcher,
signal (receive) set=(term hup kill) peer=dbus-run-session,
signal (receive) set=(term hup kill) peer=gdm*,
signal (send) set=(term hup kill) peer=at-spi-bus-launcher,
signal (send) set=(term hup kill) peer=at-spi2-registryd,
signal (send) set=(term hup kill) peer=dconf-service,
signal (send) set=(term hup kill) peer=xdg-permission-store,
ptrace (read),
dbus bus=accessibility,
dbus bus=session,
dbus bus=system,
@{exec_path} mr,
@{bin}/ r,
@{bin}/* rPUx,
@{bin}/{false,true} rix,
@{bin}/dbus-launch rix,
@{lib}/{,at-spi2{,-core}/}at-spi-bus-launcher rix, # See #74, #80 & #235
@{lib}/{,kf6/}kauth/{,libexec/}* rPx,
@{lib}/@{multiarch}/libexec/ksmserver-logout-greeter rPx,
@{lib}/@{multiarch}/tumbler-1/tumblerd rPUx,
@{lib}/@{multiarch}/xfce[0-9]/xfconf/xfconfd rPx,
@{lib}/* rPUx,
@{lib}/atril/atrild rPx,
@{lib}/dbus-1*/dbus-daemon-launch-helper rPx,
@{lib}/gnome-shell/gnome-shell-calendar-server rPx,
@{lib}/ibus/ibus-* rPx,
@{lib}/kf{5,6}/kiod{5,6} rPx,
@{lib}/telepathy/mission-control-5 rPx,
@{lib}/xfce[0-9]/xfconf/xfconfd rPx,
/usr/share/gnome-documents/org.gnome.Documents rPx,
/usr/share/gnome-maps/org.gnome.Maps rPUx,
/usr/share/gnome-shell/extensions/gsconnect@andyholmes.github.io/service/daemon.js rPx,
/usr/share/org.gnome.Characters/org.gnome.Characters rPx,
/usr/share/org.gnome.Characters/org.gnome.Characters.BackgroundService rPx,
@{lib}/mate-notification-daemon/mate-notification-daemon rPUx,
@{user_share_dirs}/gnome-shell/extensions/gsconnect@andyholmes.github.io/service/daemon.js rPx,
/etc/dbus-1/{,**} r,
/usr/share/dbus-1/{,**} r,
/usr/share/dconf/profile/gdm r,
/usr/share/defaults/**.conf r,
/usr/share/gdm/greeter-dconf-defaults r,
/usr/share/glib-2.0/schemas/gschemas.compiled r,
# Extra rules for GDM
/var/lib/gdm{3,}/.config/dconf/user r,
/var/lib/gdm{3,}/.local/share/icc/ r,
/var/lib/gdm{3,}/.local/share/icc/edid-*.icc r,
/var/lib/gdm{3,}/greeter-dconf-defaults r,
# Extra rules for Flatpak
@{system_share_dirs}/dbus-1/{,**} r,
@{system_share_dirs}/dbus-1/services/{,**} r,
# Extra rules for Snap
/var/lib/snapd/dbus-1/services/{,**} r,
/var/lib/snapd/dbus-1/system-services/{,**} r,
@{user_share_dirs}/icc/ r,
@{user_share_dirs}/icc/edid-*.icc r,
owner @{user_share_dirs}/dbus-1/{,**} r,
owner @{user_share_dirs}/Trash/files/** r,
@{run}/systemd/inhibit/*.ref rw,
@{run}/systemd/notify w,
@{run}/systemd/sessions/*.ref rw,
@{run}/systemd/users/@{uid} r,
owner @{run}/user/@{uid}/dbus-1/ rw,
owner @{run}/user/@{uid}/dbus-1/services/ rw,
owner @{run}/user/@{uid}/gdm/Xauthority r,
owner @{run}/user/@{uid}/systemd/notify w,
@{sys}/kernel/security/apparmor/.access rw,
@{sys}/kernel/security/apparmor/features/dbus/mask r,
@{sys}/module/apparmor/parameters/enabled r,
@{PROC}/@{pids}/attr/apparmor/current r,
@{PROC}/@{pids}/cgroup r,
@{PROC}/@{pids}/cmdline r,
@{PROC}/@{pids}/mounts r,
@{PROC}/@{pids}/oom_score_adj rw,
@{PROC}/1/environ r,
@{PROC}/cmdline r,
@{PROC}/sys/kernel/osrelease r,
owner @{PROC}/@{pid}/fd/ r,
/dev/dri/card@{int} rw,
/dev/input/event@{int} rw,
/dev/tty@{int} rw,
include if exists <local/dbus-daemon>
}

View file

@ -1,40 +0,0 @@
# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2021-2024 Alexandre Pujol <alexandre@pujol.io>
# SPDX-License-Identifier: GPL-2.0-only
abi <abi/3.0>,
include <tunables/global>
@{exec_path} = @{lib}/dbus-1*/dbus-daemon-launch-helper
profile dbus-daemon-launch-helper @{exec_path} {
include <abstractions/base>
include <abstractions/app-launcher-root>
include <abstractions/nameservice-strict>
capability setgid,
capability setuid,
capability sys_resource,
@{exec_path} mr,
@{lib}/{,cups-pk-helper/}cups-pk-helper-mechanism rPx,
@{lib}/{,kf6/}kauth/{,libexec/}* rPx,
@{lib}/{,polkit-1/}polkitd rPx,
@{lib}/{,udisks2/}udisksd rPx,
@{lib}/@{multiarch}/cups-pk-helper-mechanism rPx,
@{lib}/language-selector/ls-dbus-backend rPx,
@{lib}/software-properties/software-properties-dbus rPx,
/usr/share/org.gnome.Characters/org.gnome.Characters.BackgroundService rPx,
/usr/share/usb-creator/usb-creator-helper rPx,
/usr/share/hplip/pkservice.py rPx,
/usr/share/dbus-1*/{,**} r,
/etc/dbus-1/{,**} r,
owner @{PROC}/@{pid}/oom_score_adj rw,
include if exists <local/dbus-daemon-launch-helper>
}

View file

@ -1,35 +0,0 @@
# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2021-2024 Alexandre Pujol <alexandre@pujol.io>
# SPDX-License-Identifier: GPL-2.0-only
abi <abi/3.0>,
include <tunables/global>
@{exec_path} = @{bin}/dbus-run-session
profile dbus-run-session @{exec_path} {
include <abstractions/base>
signal (receive) set=(term, kill, hup) peer=gdm*,
signal (send) set=term peer=dbus-daemon,
@{exec_path} mr,
@{bin}/dbus-daemon rPx,
@{bin}/gnome-session rix,
@{bin}/gnome-shell rPx,
@{bin}/gsettings rPx,
@{bin}/startplasma-wayland rPx,
@{lib}/gnome-session-binary rPx,
/var/lib/gdm{3,}/.config/dconf/user r,
/var/lib/gdm{3,}/.cache/dconf/ rw,
/var/lib/gdm{3,}/greeter-dconf-defaults r,
owner @{PROC}/@{pid}/fd/ r,
/dev/tty rw,
/dev/tty@{int} rw,
include if exists <local/dbus-run-session>
}

View file

@ -0,0 +1,67 @@
# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2024 Alexandre Pujol <alexandre@pujol.io>
# SPDX-License-Identifier: GPL-2.0-only
# Profile for session dbus, regardless of the dbus implementation used.
# It does not specify an attachment path as it would be the same than
# "dbus-system". It is intended to be used only via "Px ->" or via
# systemd drop-in AppArmorProfile= setting.
abi <abi/3.0>,
include <tunables/global>
@{exec_path} = @{bin}/dbus-run-session
@{exec_path} += @{bin}/dbus-broker @{bin}/dbus-broker-launch
@{exec_path} += @{bin}/dbus-daemon @{lib}/dbus-1.0/dbus-daemon-launch-helper
profile dbus-session flags=(attach_disconnected) {
include <abstractions/base>
include <abstractions/bus-session>
include <abstractions/nameservice-strict>
unix (send receive) type=stream addr=none peer=(label=gnome-shell, addr=none),
signal (receive) set=(term hup) peer=gdm-session-worker,
signal (receive) set=(term hup) peer=gdm-session,
signal (receive) set=(term hup) peer=gdm,
signal (send) set=(term hup kill) peer=dbus-accessibility,
signal (send) set=(term hup kill) peer=xdg-permission-store,
signal (send) set=(hup) peer=dconf-service,
dbus bus=session,
@{exec_path} mrix,
@{bin}/{true,false} rix,
@{lib}/{,at-spi2{,-core}/}at-spi-bus-launcher rPx -> dbus-accessibility,
@{bin}/** PUx,
@{lib}/** PUx,
/usr/share/** PUx,
/etc/dbus-1/{,**} r,
/usr/share/dbus-1/{,**} r,
/var/lib/snapd/dbus-1/{,**} r,
@{system_share_dirs}/dbus-1/{,**} r,
@{run}/systemd/userd/b/ r,
@{run}/systemd/users/@{uid} r,
owner @{run}/user/@{uid}/dbus-1/ rw,
owner @{run}/user/@{uid}/dbus-1/services/ rw,
owner @{run}/user/@{uid}/systemd/notify w,
@{sys}/kernel/security/apparmor/.access rw,
@{sys}/kernel/security/apparmor/features/dbus/mask r,
@{sys}/module/apparmor/parameters/enabled r,
@{PROC}/sys/kernel/random/boot_id r,
owner @{PROC}/@{pid}/attr/apparmor/current r,
owner @{PROC}/@{pid}/cmdline r,
owner @{PROC}/@{pid}/fd/ r,
owner @{PROC}/@{pid}/oom_score_adj r,
owner @{PROC}/@{pid}/mounts r,
/dev/tty@{int} rw,
include if exists <local/dbus-session>
}

View file

@ -0,0 +1,65 @@
# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2024 Alexandre Pujol <alexandre@pujol.io>
# SPDX-License-Identifier: GPL-2.0-only
# Profile for system dbus, regardless of the dbus implementation used.
# It does not specify an attachment path as it would be the same than
# "dbus-session". It is intended to be used only via "Px ->" or via
# systemd drop-in AppArmorProfile= setting.
abi <abi/3.0>,
include <tunables/global>
@{exec_path} = @{bin}/dbus-broker @{bin}/dbus-broker-launch
@{exec_path} += @{bin}/dbus-daemon @{lib}/dbus-1.0/dbus-daemon-launch-helper
profile dbus-system flags=(attach_disconnected) {
include <abstractions/base>
include <abstractions/bus-system>
include <abstractions/nameservice-strict>
capability audit_write,
capability net_admin,
capability setgid,
capability setuid,
network netlink raw,
network bluetooth stream,
network bluetooth seqpacket,
dbus bus=system,
@{exec_path} mrix,
@{bin}/** PUx,
@{lib}/** PUx,
/usr/share/*/** PUx,
/etc/machine-id r,
/etc/dbus-1/{,**} r,
/usr/share/dbus-1/{,**} r,
/var/lib/snapd/dbus-1/{,**} r,
@{system_share_dirs}/dbus-1/{,**} r,
@{user_share_dirs}/icc/ r,
@{user_share_dirs}/icc/edid-@{md5}.icc r,
/var/lib/gdm{,3}/.local/share/icc/ r,
/var/lib/gdm{,3}/.local/share/icc/edid-@{md5}.icc r,
@{run}/systemd/users/@{int} r,
@{run}/systemd/sessions/*.ref rw,
@{run}/systemd/inhibit/*.ref rw,
@{sys}/kernel/security/apparmor/.access rw,
@{sys}/kernel/security/apparmor/features/dbus/mask r,
@{sys}/module/apparmor/parameters/enabled r,
@{PROC}/@{pid}/cmdline r,
owner @{PROC}/@{pid}/fd/ r,
owner @{PROC}/@{pid}/mounts r,
/dev/dri/card@{int} rw,
/dev/input/event@{int} rw,
include if exists <local/dbus-system>
}

View file

@ -1,65 +0,0 @@
# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2018-2022 Mikhail Morfikov
# Copyright (C) 2021-2024 Alexandre Pujol <alexandre@pujol.io>
# SPDX-License-Identifier: GPL-2.0-only
abi <abi/3.0>,
include <tunables/global>
@{exec_path} = @{lib}/{,at-spi2{,-core}/}at-spi-bus-launcher
profile at-spi-bus @{exec_path} flags=(attach_disconnected) {
include <abstractions/base>
include <abstractions/bus-accessibility>
include <abstractions/bus-session>
include <abstractions/dconf-write>
include <abstractions/nameservice-strict>
network inet stream, # TODO: local only
network inet6 stream,
network inet dgram,
network inet6 dgram,
network netlink raw,
signal (receive) set=(term hup kill) peer=dbus-daemon,
dbus bus=accessibility,
dbus bus=session,
@{exec_path} mr,
@{bin}/dbus-broker-launch rix,
@{bin}/dbus-daemon rix,
@{bin}/dbus-broker rix,
@{lib}/{,at-spi2{,-core}/}at-spi2-registryd rix,
/usr/share/dbus-1/accessibility-services/ r,
/usr/share/dbus-1/accessibility-services/org.a11y.atspi.Registry.service r,
/usr/share/dconf/profile/gdm r,
/usr/share/defaults/at-spi2/accessibility.conf r,
/usr/share/gdm/greeter-dconf-defaults r,
/usr/share/glib-2.0/schemas/gschemas.compiled r,
/var/lib/gdm{3,}/.config/dconf/user r,
/var/lib/gdm{3,}/greeter-dconf-defaults r,
/var/lib/lightdm/.Xauthority r,
/var/log/lightdm/seat@{int}-greeter.log w,
@{run}/systemd/users/@{uid} r,
@{sys}/kernel/security/apparmor/.access rw,
@{sys}/kernel/security/apparmor/features/dbus/mask r,
@{sys}/module/apparmor/parameters/enabled r,
@{PROC}/@{pid}/cmdline r,
@{PROC}/@{pid}/oom_score_adj rw,
@{PROC}/@{pids}/mounts r,
@{PROC}/1/cgroup r,
owner @{PROC}/@{pid}/attr/apparmor/current r,
owner @{PROC}/@{pid}/cgroup r,
owner @{PROC}/@{pid}/fd/ r,
owner /dev/tty@{int} rw,
include if exists <local/at-spi-bus>
}