# 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} = @{bin}/update-notifier
profile update-notifier @{exec_path} {
  include <abstractions/base>
  include <abstractions/audio-client>
  include <abstractions/bus-accessibility>
  include <abstractions/bus-session>
  include <abstractions/bus-system>
  include <abstractions/bus/org.a11y>
  include <abstractions/bus/org.gtk.vfs.MountTracker>
  include <abstractions/bus/org.kde.StatusNotifierWatcher>
  include <abstractions/common/apt>
  include <abstractions/dconf-write>
  include <abstractions/gnome-strict>
  include <abstractions/nameservice-strict>
  include <abstractions/python>

  unix (bind) type=stream addr=@@{udbus}/bus/systemd/bus-api-user,

  #aa:dbus talk bus=system name=org.debian.apt label=apt
  #aa:dbus talk bus=session name=org.ayatana.NotificationItem label=gnome-shell

  @{exec_path} mr,

  @{sh_path}                                     rix,
  @{bin}/ionice                                  rix,
  @{bin}/ischroot                                rix,
  @{bin}/nice                                    rix,

  @{bin}/dpkg                                    rPx -> child-dpkg,
  @{bin}/lsb_release                             rPx -> lsb_release,
  @{bin}/pkexec                                  rCx -> pkexec,
  @{bin}/snap                                   rPUx,
  @{bin}/software-properties-gtk                 rPx,
  @{bin}/systemctl                               rCx -> systemctl,
  @{bin}/update-manager                          rPx,
  @{lib}/ubuntu-release-upgrader/check-new-release-gtk rPx,
  @{lib}/update-notifier/apt_check.py            rix,
  @{lib}/update-notifier/list-oem-metapackages   rPx,
  @{lib}/update-notifier/livepatch-notification  rPx,
  @{lib}/update-notifier/package-system-locked   rPx,
  /usr/share/apport/apport-checkreports          rPx,
  /usr/share/apport/apport-gtk                   rPx,

  @{lib}/python3.@{int}/dist-packages/{apt,gi}/**/__pycache__/{,**} rw,

  /usr/share/dpkg/cputable r,
  /usr/share/dpkg/tupletable r,
  /usr/share/update-notifier/{,**} r,

  /var/lib/snapd/desktop/applications/{,**} r,
  /var/lib/update-notifier/user.d/ r,

  owner @{user_config_dirs}/update-notifier/ w,
  owner @{user_share_dirs}/applications/ r,

  owner @{run}/user/@{uid}/update-notifier.pid rwk,

  owner @{tmp}/#@{int} rw,

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

  profile pkexec {
    include <abstractions/base>
    include <abstractions/app/pkexec>

    ptrace read peer=update-notifier,

    @{lib}/update-notifier/package-system-locked Px,

    @{PROC}/@{pid}/fdinfo/@{int} r,
    @{PROC}/@{pid}/stat r,

    include if exists <local/update-notifier_pkexec>
  }

  profile systemctl {
    include <abstractions/base>
    include <abstractions/app/systemctl>
    include <abstractions/bus-system>

    unix (bind) type=stream addr=@@{udbus}/bus/systemctl/system,

    dbus send bus=system path=/org/freedesktop/systemd1
         interface=org.freedesktop.systemd1.Manager
         member=GetUnitFileState
         peer=(name=org.freedesktop.systemd1, label="@{p_systemd}"),

    include if exists <local/update-notifier_systemctl>
  }

  include if exists <local/update-notifier>
}

# vim:syntax=apparmor
