# 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}/aa-notify
@{att} = /att/aa-notify/
profile aa-notify /{,usr/}bin/aa-notify  flags=(attach_disconnected,attach_disconnected.path=@{att},complain) {
  include <abstractions/attached/base>
  include <abstractions/attached/consoles>
  include <abstractions/dconf-write>
  include <abstractions/desktop>
  include <abstractions/attached/nameservice-strict>
  include <abstractions/notifications>
  include <abstractions/python>

  capability setgid,
  capability setuid,
  capability sys_ptrace,

  ptrace read,

  @{exec_path} mr,

  @{bin}/gtk-launch  ix,
  @{bin}/pkexec      cx -> pkexec,
  @{bin}/xdg-mime    px,
  @{open_path}       cx -> open,

  @{bin}/ r,
  @{sbin}/ r,

  /usr/share/apparmor/** r,
  /usr/share/tcltk/** r,
  /usr/share/terminfo/** r,

  @{etc_ro}/inputrc r,
  @{etc_ro}/inputrc.keys r,
  /etc/apparmor.d/{,**} r,
  /etc/apparmor/*.conf r,

  /var/lib/snapd/apparmor/snap-confine/ r,
  /var/lib/snapd/apparmor/snap-confine/cap-bpf r,

  /var/log/audit/* r,
  /var/log/syslog* r,
  /var/log/kern.log r,

  owner @{HOME}/.inputrc r,
  owner @{HOME}/.terminfo/@{int}/dumb r,

  owner @{tmp}/@{word8} rw,
  owner @{tmp}/apparmor-bugreport-@{word8}.txt rw,

        @{PROC}/ r,
        @{PROC}/@{pid}/stat r,
        @{PROC}/@{pid}/cmdline r,
  owner @{PROC}/@{pid}/mounts r,

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

    @{editor_ui_path}  rpx -> aa-notify//editor,

    include if exists <local/aa-notify_open>
  }

  profile editor flags=(attach_disconnected,attach_disconnected.path=@{att},complain) {
    include <abstractions/attached/base>
    include <abstractions/app/open>
    include <abstractions/bus/session/org.freedesktop.FileManager1>
    include <abstractions/common/gnome>
    include <abstractions/enchant>

    @{editor_ui_path} rix,
    @{open_path}  rpx -> child-open-help,

    /etc/apparmor.d/{,**} r,

    owner @{user_share_dirs}/org.gnome.TextEditor/{,**} rw,

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

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

    include if exists <local/aa-notify_editor>
  }

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

    ptrace read peer=aa-notify,

    @{sbin}/apparmor_parser px,
    @{lib}/@{python_name}/site-packages/apparmor/update_profile.py ix,

    /usr/share/apparmor/** r,
    /usr/share/terminfo/** r,

    @{etc_ro}/inputrc r,
    @{etc_ro}/inputrc.keys r,

    /etc/apparmor.d/ r,
    /etc/apparmor.d/** rw,
    /etc/apparmor/* r,

    @{PROC}/@{pid}/mounts r,

    include if exists <local/aa-notify_pkexec>
  }

  include if exists <local/aa-notify>
}

# vim:syntax=apparmor
