# 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/3.0>,

include <tunables/global>

@{exec_path} = @{bin}/systemd-dissect
profile systemd-dissect @{exec_path} flags=(attach_disconnected) {
  include <abstractions/base>
  include <abstractions/consoles>
  include <abstractions/disks-read>

  capability dac_read_search,
  capability sys_admin,
  capability sys_resource,

  mount options=(rw, rslave) -> /,
  mount options=(rw, nodev) -> /mnt/*/,
  mount -> /tmp/dissect-@{rand6}/,

  signal (send) set=(cont) peer=child-pager,

  @{exec_path} mr,

  @{bin}/fsck  rPx,
  @{bin}/less  rPx -> child-pager,
  @{bin}/more  rPx -> child-pager,
  @{bin}/pager rPx -> child-pager,

  # Location of file system OS images
  @{user_build_dirs}/{,**} r,
  @{user_pkg_dirs}/{,**} r,
  @{user_projects_dirs}/{,**} r,
  @{user_vm_dirs}/{,**} r,

  owner @{tmp}/dissect-@{rand6}/{,**} rw,

  @{sys}/devices/virtual/block/loop@{int}/{,**} r,
  @{sys}/kernel/uevent_seqnum r,

  @{PROC}/@{pids}/cgroup r,

  /dev/btrfs-control rw,
  /dev/loop-control rwk,
  /dev/loop*  rwk,

  include if exists <local/systemd-dissect>
}

# vim:syntax=apparmor
