# SPDX-FileCopyrightText: 2026 Skye Soss <skye@soss.website>
#
# SPDX-License-Identifier: MIT-0

abi <abi/4.0>,

include <tunables/global>

# No attachment path: nothing is confined until AppArmorProfile= asks for it.
profile defused flags=(attach_disconnected) {
  include <abstractions/base>

  capability dac_read_search,
  capability sys_admin,
  capability sys_chroot,
  capability sys_ptrace,

  network unix seqpacket,

  # setns() into a client's mount namespace via its pidfd needs PTRACE_MODE_READ
  # on the client, whatever that client's own label is.
  ptrace (read),

  /proc/@{pid}/fdinfo/* r,

  # An fd on /proc/<pid>/ns/mnt is an nsfs file with no path of its own, so
  # attach_disconnected reports it as "/", which /** does not match.
  / r,

  # The client passes already-open mountpoint and parent directory fds.
  # Permit metadata lookups through those delegated descriptors.
  /** r,

  mount,
  umount,

  include if exists <local/defused>
}
