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

include <tunables/global>

@{exec_path} = @{bin}/gnome-system-monitor
@{att} = /att/gnome-system-monitor/
profile gnome-system-monitor /{,usr/}bin/gnome-system-monitor  flags=(attach_disconnected,attach_disconnected.path=@{att},complain) {
  include <abstractions/attached/base>
  include <abstractions/bus/org.freedesktop.portal.Desktop>
  include <abstractions/bus/session/org.gtk.Private.RemoteVolumeMonitor>
  include <abstractions/bus/session/org.gtk.vfs.Daemon>
  include <abstractions/common/gnome>
  include <abstractions/nameservice-strict>

  capability sys_ptrace,

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

  ptrace read,

  signal send set=(kill term cont stop),

  include <abstractions/bus/session/own>

  dbus bind bus=session name=org.gnome.SystemMonitor{,.*},
  dbus receive bus=session path=/org/gnome/SystemMonitor{,/**}
       interface=org.gnome.SystemMonitor{,.*}
       peer=(name="@{busname}"),
  dbus send bus=session path=/org/gnome/SystemMonitor{,/**}
       interface=org.gnome.SystemMonitor{,.*}
       peer=(name="{@{busname},org.freedesktop.DBus}"),
  dbus (send receive) bus=session path=/org/gnome/SystemMonitor{,/**}
       interface=org.freedesktop.DBus.Properties
       member={Get,GetAll,Set,PropertiesChanged}
       peer=(name="{@{busname},org.freedesktop.DBus}"),
  dbus receive bus=session path=/org/gnome/SystemMonitor{,/**}
       interface=org.freedesktop.DBus.Introspectable
       member=Introspect
       peer=(name="@{busname}"),
  dbus receive bus=session path=/org/gnome/SystemMonitor{,/**}
       interface=org.freedesktop.DBus.ObjectManager
       member=GetManagedObjects
       peer=(name="{@{busname},org.gnome.SystemMonitor{,.*}}"),
  dbus send bus=session path=/org/gnome/SystemMonitor{,/**}
       interface=org.freedesktop.DBus.ObjectManager
       member={InterfacesAdded,InterfacesRemoved}
       peer=(name="{@{busname},org.freedesktop.DBus}"),

  @{exec_path} mr,

  @{sh_path}    rix,
  @{bin}/lsblk  rpx,
  @{bin}/pkexec rcx -> pkexec,
  @{bin}/sed    rix,
  @{bin}/tr     rix,

  /usr/share/byobu/desktop/{,**} r,
  /usr/share/firefox{,-esr}/browser/chrome/icons/{,**} r,

  / r,

  owner @{tmp}/gdkpixbuf-xpm-tmp.@{rand6} rw,

  owner @{run}/user/@{uid}/doc/ rw,
  owner @{run}/user/@{uid}/gnome-shell-disable-extensions w,

  @{run}/systemd/sessions/*     r,
  @{run}/systemd/sessions/*.ref r,
  @{run}/mount/utab r,

  @{sys}/devices/@{pci}/net/*/statistics/collisions r,
  @{sys}/devices/@{pci}/net/*/statistics/rx_{bytes,errors,packets} r,
  @{sys}/devices/@{pci}/net/*/statistics/tx_{bytes,errors,packets} r,
  @{sys}/devices/@{pci}/usb@{int}/**/net/*/statistics/collisions r,
  @{sys}/devices/@{pci}/usb@{int}/**/net/*/statistics/rx_{bytes,errors,packets} r,
  @{sys}/devices/@{pci}/usb@{int}/**/net/*/statistics/tx_{bytes,errors,packets} r,
  @{sys}/devices/@{pci}/virtio@{int}/**/stat r,
  @{sys}/devices/virtual/net/*/statistics/collisions r,
  @{sys}/devices/virtual/net/*/statistics/rx_{bytes,errors,packets} r,
  @{sys}/devices/virtual/net/*/statistics/tx_{bytes,errors,packets} r,

  @{PROC}/ r,
  @{PROC}/@{pids}/attr/current r,
  @{PROC}/@{pids}/cgroup r,
  @{PROC}/@{pids}/cmdline r,
  @{PROC}/@{pids}/fd/ r,
  @{PROC}/@{pids}/io r,
  @{PROC}/@{pids}/mountinfo r,
  @{PROC}/@{pids}/mounts r,
  @{PROC}/@{pids}/net/dev r,
  @{PROC}/@{pids}/net/tcp{,6} r,
  @{PROC}/@{pids}/net/unix r,
  @{PROC}/@{pids}/smaps r,
  @{PROC}/@{pids}/stat r,
  @{PROC}/@{pids}/statm r,
  @{PROC}/@{pids}/status r,
  @{PROC}/@{pids}/wchan r,
  @{PROC}/diskstats r,
  @{PROC}/vmstat r,

  deny owner @{user_share_dirs}/gvfs-metadata/{,*} r,

  /dev/tty rw,

  profile pkexec flags=(attach_disconnected,attach_disconnected.path=@{att},complain) {
    include <abstractions/attached/base>
    include <abstractions/app/pkexec>

    include if exists <local/gnome-system-monitor_pkexec>
  }

  include if exists <local/gnome-system-monitor>
}

# vim:syntax=apparmor
