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

abi <abi/4.0>,

include <tunables/global>

@{exec_path}  = @{lib}/@{multiarch}/{,libexec/}polkit-kde-authentication-agent-[0-9]
@{exec_path} += @{lib}/polkit-kde-authentication-agent-[0-9]
@{att} = /att/polkit-kde-authentication-agent/
profile polkit-kde-authentication-agent /{{,usr/}lib{,exec,32,64}/*-linux-gnu*/{,libexec/}polkit-kde-authentication-agent-[0-9],{,usr/}lib{,exec,32,64}/polkit-kde-authentication-agent-[0-9],{,usr/}lib{,exec,32,64}/polkit-kde-authentication-agent-[0-9]}  flags=(attach_disconnected,attach_disconnected.path=@{att},complain,mediate_deleted) {
  include <abstractions/attached/base>
  include <abstractions/bus-session>
  include <abstractions/bus-system>
  include <abstractions/attached/consoles>
  include <abstractions/fontconfig-cache-read>
  include <abstractions/graphics>
  include <abstractions/kde-strict>
  include <abstractions/nameservice-strict>
  include <abstractions/qt5-compose-cache-write>

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

  signal (send) set=(term, kill) peer=polkit-agent-helper,

  include <abstractions/bus/session/own>

  dbus bind bus=session name=org.kde.polkit-kde-authentication-agent-@{int}{,.*},
  dbus receive bus=session path=/org/kde/polkit-kde-authentication-agent-@{int}{,/**}
       interface=org.kde.polkit-kde-authentication-agent-@{int}{,.*}
       peer=(name="@{busname}"),
  dbus send bus=session path=/org/kde/polkit-kde-authentication-agent-@{int}{,/**}
       interface=org.kde.polkit-kde-authentication-agent-@{int}{,.*}
       peer=(name="{@{busname},org.freedesktop.DBus}"),
  dbus (send receive) bus=session path=/org/kde/polkit-kde-authentication-agent-@{int}{,/**}
       interface=org.freedesktop.DBus.Properties
       member={Get,GetAll,Set,PropertiesChanged}
       peer=(name="{@{busname},org.freedesktop.DBus}"),
  dbus receive bus=session path=/org/kde/polkit-kde-authentication-agent-@{int}{,/**}
       interface=org.freedesktop.DBus.Introspectable
       member=Introspect
       peer=(name="@{busname}"),
  dbus receive bus=session path=/org/kde/polkit-kde-authentication-agent-@{int}{,/**}
       interface=org.freedesktop.DBus.ObjectManager
       member=GetManagedObjects
       peer=(name="{@{busname},org.kde.polkit-kde-authentication-agent-@{int}{,.*}}"),
  dbus send bus=session path=/org/kde/polkit-kde-authentication-agent-@{int}{,/**}
       interface=org.freedesktop.DBus.ObjectManager
       member={InterfacesAdded,InterfacesRemoved}
       peer=(name="{@{busname},org.freedesktop.DBus}"),
  unix type=stream addr=none peer=(label=polkitd, addr=none),

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

  @{exec_path} mr,

  @{lib}/polkit-[0-9]/polkit-agent-helper-[0-9] rpx,

  /etc/machine-id r,
  /etc/xdg/plasmarc r,
  /var/lib/dbus/machine-id r,

  owner @{user_config_dirs}/breezerc r,
  owner @{user_config_dirs}/kdedefaults/plasmarc r,

  owner @{user_cache_dirs}/polkit-kde-authentication-agent-@{int}/ rw,
  owner @{user_cache_dirs}/polkit-kde-authentication-agent-@{int}/** rwk,
  owner link @{user_cache_dirs}/polkit-kde-authentication-agent-@{int}/** -> @{user_cache_dirs}/polkit-kde-authentication-agent-@{int}/**,
  owner @{user_cache_dirs}/qtshadercache-*/* r,

  owner @{tmp}/#@{int} rw,
  owner @{tmp}/polkit-kde-authentication-agent-[0-9].* rwl -> /tmp/#@{int},
  # owner /tmp/xauth_@{rand6} r,

  /dev/shm/#@{int} rw,

  @{run}/systemd/users/@{uid} r,

  @{PROC}/@{pid}/cgroup r,
  @{PROC}/@{pid}/cmdline r,
  @{PROC}/@{pid}/fd/ r,

  include if exists <local/polkit-kde-authentication-agent>
}

# vim:syntax=apparmor
