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

abi <abi/4.0>,

include <tunables/global>

@{name} = {E,e}lement
@{lib_dirs} = @{lib}/@{name}
@{config_dirs} = @{user_config_dirs}/@{name}
@{cache_dirs} = @{user_cache_dirs}/@{name}

@{exec_path} = @{bin}/element-desktop
profile element-desktop @{exec_path} flags=(attach_disconnected) {
  include <abstractions/base>
  include <abstractions/audio-client>
  include <abstractions/bus-session>
  include <abstractions/bus/org.freedesktop.ScreenSaver>
  include <abstractions/bus/org.kde.StatusNotifierWatcher>
  include <abstractions/common/electron>
  include <abstractions/p11-kit>
  include <abstractions/video>

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

  @{exec_path} mr,

  @{sh_path} r,
  @{open_path}         rPx -> child-open-strict,

  #aa:stack X xdg-settings
  @{bin}/xdg-settings  rPx -> element-desktop//&xdg-settings,

  /usr/share/webapps/element/{,**} r,

  /etc/webapps/element/{,**} r,

  /dev/tty rw,

  deny / r,
  deny @{HOME}/ r,
  deny @{user_share_dirs}/gvfs-metadata/* r,
  deny /etc/machine-id r,
  deny /var/lib/dbus/machine-id r,

  include if exists <local/element-desktop>
}

# vim:syntax=apparmor
