# 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}/browserpass @{lib}/browserpass/browserpass-native
@{att} = /att/browserpass/
profile browserpass /{{,usr/}bin/browserpass,{,usr/}lib{,exec,32,64}/browserpass/browserpass-native}  flags=(attach_disconnected,attach_disconnected.path=@{att},complain) {
  include <abstractions/attached/base>
  include <abstractions/nameservice-strict>

  network netlink raw,

  @{exec_path} mr,

  @{bin}/gpg{2,} rcx -> gpg,

  owner @{HOME}/.password-store/{,**} r,
  owner @{HOME}/.mozilla/firefox/@{rand8}.*/.parentlock rw,
  owner @{HOME}/.mozilla/firefox/@{rand8}.*/extensions/* r,
  owner @{user_cache_dirs}/mozilla/firefox/@{rand8}.*/startupCache/scriptCache-*.bin r,
  owner @{user_cache_dirs}/mozilla/firefox/@{rand8}.*/startupCache/startupCache.*.little r,
  owner @{user_cache_dirs}/mozilla/firefox/@{rand8}.*/safebrowsing-updating/google@{d}/goog-phish-proto-@{int}.vlpset rw,
  owner @{tmp}/mozilla-temp-@{int} r,

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

  # Inherit Silencer
  deny network inet6,
  deny network inet,
  deny owner @{HOME}/.mozilla/firefox/@{rand8}.*/features/*/*.xpi r,
  deny owner @{HOME}/.mozilla/firefox/@{rand8}.*/storage/default/{,**} rw,
  deny owner @{user_download_dirs}/{,**} rw,
  deny owner @{run}/user/@{uid}/gnome-shell-disable-extensions w,
  deny owner @{user_share_dirs}/gvfs-metadata/{,**} r,
  deny /dev/dri/* rw,

  profile gpg  flags=(attach_disconnected,attach_disconnected.path=@{att},complain) {
    include <abstractions/attached/base>
    include <abstractions/nameservice-strict>

    capability dac_read_search,

    @{bin}/gpg{,2}    mr,

    owner @{HOME}/@{XDG_GPG_DIR}/ rw,
    owner @{HOME}/@{XDG_GPG_DIR}/** rwkl -> @{HOME}/@{XDG_GPG_DIR}/**,

    owner @{user_passwordstore_dirs}/   rw,
    owner @{user_passwordstore_dirs}/** rwkl -> @{HOME}/.password-store/**,
    owner @{user_projects_dirs}/**/*-store/   rw,
    owner @{user_projects_dirs}/**/*-store/** rwkl -> @{user_projects_dirs}/**/*-store/**,
    owner @{user_config_dirs}/*-store/   rw,
    owner @{user_config_dirs}/*-store/** rwkl -> @{user_config_dirs}/*-store/**,

    include if exists <local/browserpass_gpg>
  }

  include if exists <local/browserpass>
}

# vim:syntax=apparmor
