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

abi <abi/3.0>,

include <tunables/global>

@{exec_path} = @{bin}/fusermount{,3}
profile fusermount @{exec_path} {
  include <abstractions/base>
  include <abstractions/nameservice-strict>

  capability dac_read_search,
  capability sys_admin,

  # Be able to mount ISO images
  mount fstype={fuse,fuse.*} -> @{HOME}/*/,
  mount fstype={fuse,fuse.*} -> @{HOME}/*/*/,
  mount fstype={fuse,fuse.*} -> @{user_cache_dirs}/**/,
  mount fstype={fuse,fuse.*} -> @{MOUNTS}/*/,
  mount fstype={fuse,fuse.*} -> @{MOUNTS}/*/*/,
  mount fstype={fuse,fuse.*} -> @{run}/user/@{uid}/*/,
  mount fstype={fuse,fuse.*} -> /var/tmp/flatpak-cache-*/*/,
  mount fstype={fuse,fuse.*} -> /tmp/.mount_nextcl@{rand6}/,

  umount @{HOME}/*/,
  umount @{HOME}/*/*/,
  umount @{user_cache_dirs}/**/,
  umount @{MOUNTS}/*/,
  umount @{MOUNTS}/*/*/,
  umount /tmp/.mount_*/,
  umount @{run}/user/@{uid}/*/,
  umount /var/tmp/flatpak-cache-*/*/,

  @{exec_path} mr,

  /etc/fuse.conf r,
  /etc/machine-id r,

  /var/tmp/flatpak-cache-*/*/ r,

  # Where to mount ISO files
  owner @{HOME}/*/ rw,
  owner @{HOME}/*/*/ rw,

  owner @{user_cache_dirs}/**/ rw,

  @{run}/user/@{uid}/doc/ r,

  @{PROC}/@{pid}/mounts r,

  /dev/fuse rw,

  include if exists <local/fusermount>
}
