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

abi <abi/3.0>,

include <tunables/global>

@{exec_path} = @{bin}/loupe
profile loupe @{exec_path} flags=(attach_disconnected) {
  include <abstractions/base>
  include <abstractions/dconf-write>
  include <abstractions/gnome-strict>
  include <abstractions/graphics>
  include <abstractions/nameservice-strict>
  include <abstractions/trash-strict>
  include <abstractions/user-read-strict>
  include <abstractions/user-write-strict>

  signal (send) set=(kill) peer=loupe//bwrap,

  @{exec_path} mr,

  @{bin}/bwrap rCx -> bwrap,
  @{open_path} rPx -> child-open-help,

  /usr/share/glycin-loaders/{,**} r,

  / r,

  @{run}/mount/utab r,

  @{sys}/fs/cgroup/user.slice/cpu.max r,
  @{sys}/fs/cgroup/user.slice/user-@{uid}.slice/cpu.max r,
  @{sys}/fs/cgroup/user.slice/user-@{uid}.slice/user@@{uid}.service/app.slice/cpu.max r,
  @{sys}/fs/cgroup/user.slice/user-@{uid}.slice/user@@{uid}.service/cpu.max r,

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

  deny @{user_share_dirs}/gvfs-metadata/* r,

  profile bwrap flags=(attach_disconnected) {
    include <abstractions/base>
    include <abstractions/common/bwrap>

    signal (receive) set=(kill) peer=loupe,

    @{bin}/bwrap mr,
    @{lib}/glycin-loaders/*/glycin-image-rs rix,

    deny @{user_share_dirs}/gvfs-metadata/* r,

    include if exists <local/loupe_bwrap>
  }

  include if exists <local/loupe>
}

# vim:syntax=apparmor
