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

abi <abi/4.0>,

include <tunables/global>

@{name} = spotify
@{lib_dirs} = /opt/spotify/
@{config_dirs} = @{user_config_dirs}/@{name}
@{cache_dirs} = @{user_cache_dirs}/@{name}

@{exec_path} = @{bin}/@{name} @{lib_dirs}/@{name}
profile spotify @{exec_path} flags=(attach_disconnected) {
  include <abstractions/base>
  include <abstractions/audio-client>
  include <abstractions/common/electron>

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

  @{exec_path} mrix,

  @{sh_path} mr,
  @{bin}/grep rix,

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

  /etc/machine-id r,
  /etc/spotify-adblock/* r,
  /var/lib/dbus/machine-id r,

  owner @{user_music_dirs}/{,**} r,

  owner @{user_config_dirs}/spotify-adblock/* r,

  owner @{cache_dirs}/WidevineCdm/**/libwidevinecdm.so rm,
  owner @{config_dirs}/*/WidevineCdm/**/libwidevinecdm.so rm,

  owner @{tmp}/.org.chromium.Chromium.@{rand6}/** rw,

        @{PROC}/pressure/* r,
        @{PROC}/@{pid}/net/unix r,
  owner @{PROC}/@{pid}/clear_refs w,

  /dev/tty rw,

  deny @{sys}/bus/ r,
  deny @{sys}/bus/*/devices/ r,
  deny @{sys}/class/*/ r,
  deny @{sys}/devices/@{pci}/usb@{int}/** r,
  deny @{user_share_dirs}/gvfs-metadata/* r,

  include if exists <local/spotify>
}

# vim:syntax=apparmor
