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

abi <abi/4.0>,

include <tunables/global>

@{exec_path} = @{bin}/usbguard
profile usbguard @{exec_path} {
  include <abstractions/base>
  include <abstractions/consoles>
  include <abstractions/devices-usb>

  capability chown,
  capability fowner,
  capability dac_override,

  # Needed to create policy (usbguard generate-policy)
  network netlink dgram,

  unix (send, receive, connect) type=stream peer=(label="usbguard-daemon",addr=@@{int}),

  #aa:dbus own bus=system name=org.usbguard1

  @{exec_path} mr,

  /etc/usbguard/*.conf rw,
  /etc/usbguard/IPCAccessControl.d/{,*} rw,

  /dev/shm/qb-usbguard-{request,response,event}-@{int}-@{int}-@{int}-{header,data} rw,
  /dev/shm/qb-@{int}-@{int}-@{int}-*/qb-{request,response,event}-usbguard-{header,data} rw,

  # For "usbguard generate-policy"
  @{sys}/devices/@{pci}/uevent r,

  include if exists <local/usbguard>
}

# vim:syntax=apparmor
