# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2022-2024 Alexandre Pujol <alexandre@pujol.io>
# SPDX-License-Identifier: GPL-2.0-only

abi <abi/4.0>,

include <tunables/global>

@{exec_path} = @{lib}/boltd
profile boltd /{,usr/}lib{,exec,32,64}/boltd  flags=(attach_disconnected,complain) {
  include <abstractions/base>
  include <abstractions/bus-system>
  include <abstractions/bus/org.freedesktop.PolicyKit1>
  include <abstractions/nameservice-strict>

  capability net_admin,

  network netlink raw,

  dbus bind bus=system name=org.freedesktop.bolt{,.*},
  dbus receive bus=system path=/org/freedesktop/bolt{,/**}
       interface=org.freedesktop.bolt{,.*}
       peer=(name=":1.@{int}"),
  dbus receive bus=system path=/org/freedesktop/bolt{,/**}
       interface=org.freedesktop.DBus.Properties
       peer=(name=":1.@{int}"),
  dbus receive bus=system path=/org/freedesktop/bolt{,/**}
       interface=org.freedesktop.DBus.ObjectManager
       peer=(name=":1.@{int}"),
  dbus send bus=system path=/org/freedesktop/bolt{,/**}
       interface=org.freedesktop.bolt{,.*}
       peer=(name="{:1.@{int},org.freedesktop.DBus}"),
  dbus send bus=system path=/org/freedesktop/bolt{,/**}
       interface=org.freedesktop.DBus.Properties
       peer=(name="{:1.@{int},org.freedesktop.DBus}"),
  dbus send bus=system path=/org/freedesktop/bolt{,/**}
       interface=org.freedesktop.DBus.ObjectManager
       peer=(name="{:1.@{int},org.freedesktop.DBus}"),
  dbus receive bus=system path=/org/freedesktop/bolt{,/**}
       interface=org.freedesktop.DBus.Introspectable
       member=Introspect
       peer=(name=":1.@{int}"),

  @{exec_path} mr,

  /var/lib/boltd/{,**} rw,

  owner @{run}/boltd/{,**} rw,

  @{run}/systemd/notify rw,
  @{run}/systemd/journal/socket w,
  @{run}/udev/data/+thunderbolt:* r,

  @{sys}/bus/ r,
  @{sys}/bus/thunderbolt/devices/ r,
  @{sys}/bus/wmi/devices/ r,
  @{sys}/class/ r,
  @{sys}/devices/@{pci}/@{uuid}/uevent r,
  @{sys}/devices/@{pci}/device r,
  @{sys}/devices/@{pci}/domain@{int}/ r,
  @{sys}/devices/@{pci}/domain@{int}/{security,uevent} r,
  @{sys}/devices/@{pci}/domain@{int}/**/ r,
  @{sys}/devices/@{pci}/domain@{int}/**/{authorized,generation} r,
  @{sys}/devices/@{pci}/domain@{int}/**/{boot,rx_lanes,rx_speed,tx_lanes,tx_speed} r,
  @{sys}/devices/@{pci}/domain@{int}/**/{uevent,unique_id} r,
  @{sys}/devices/@{pci}/domain@{int}/**/{vendor,device}_name r,
  @{sys}/devices/@{pci}/domain@{int}/boot_acl rw,
  @{sys}/devices/@{pci}/domain@{int}/iommu_dma_protection r,
  @{sys}/devices/platform/**/uevent r,
  @{sys}/devices/platform/*/wmi_bus/wmi_bus-*/@{uuid}/force_power rw,
  @{sys}/devices/virtual/dmi/id/{sys_vendor,product_version,product_name} r,

  include if exists <local/boltd>
}
