# 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/4.0>,

include <tunables/global>

@{exec_path} = @{bin}/fwupdmgr
profile fwupdmgr @{exec_path} flags=(attach_disconnected) {
  include <abstractions/base>
  include <abstractions/bus-system>
  include <abstractions/bus/org.freedesktop.NetworkManager>
  include <abstractions/dconf-write>
  include <abstractions/freedesktop.org>
  include <abstractions/nameservice-strict>
  include <abstractions/ssl_certs>

  capability sys_nice,

  signal send,

  network inet stream,
  network inet6 stream,
  network inet dgram,
  network inet6 dgram,
  network netlink raw,

  #aa:dbus talk bus=system name=org.freedesktop.fwupd label=fwupd path=/
  
  @{exec_path} mr,

  @{bin}/dbus-launch   Cx -> bus,
  @{bin}/pkttyagent    Px,

  /etc/machine-id r,

  owner /var/cache/private/fwupdmgr/fwupd/lvfs-metadata.xml.gz{,.asc}.* rw,
  owner /var/cache/private/fwupdmgr/fwupd/lvfs-metadata.xml.gz{,.asc} rw,

        @{user_cache_dirs}/dconf/user rw,
  owner @{user_cache_dirs}/ rw,
  owner @{user_cache_dirs}/fwupd/ rw,
  owner @{user_cache_dirs}/fwupd/lvfs-metadata.xml.gz{,.*} rw,

  owner @{run}/systemd/.cache/ rw,

  owner @{PROC}/@{pid}/fd/ r,

  /dev/i2c-@{int} rw,
  /dev/tty rw,
  /dev/pts/@{int} rw,

  profile bus flags=(attach_disconnected) {
    include <abstractions/base>
    include <abstractions/app/bus>
    include if exists <local/fwupdmgr_bus>
  }

  include if exists <local/fwupdmgr>
}

# vim:syntax=apparmor
