# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2019-2021 Mikhail Morfikov
# 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} = @{sbin}/deluser
@{att} = ""
profile deluser /{,usr/}{,s}bin/deluser flags=(complain) {
  include <abstractions/base-strict>
  include <abstractions/perl>
  include <abstractions/consoles>
  include <abstractions/nameservice-strict>

  capability dac_override,
  capability dac_read_search,
  capability sys_admin,

  @{exec_path} r,

  @{sh_path}       rix,
  @{archive_path}  rix,
  @{bin}/logger    rix,
  @{bin}/crontab   rpx,
  @{bin}/gpasswd   rpx,
  @{sbin}/groupdel rpx,
  @{bin}/mount     rcx -> mount,
  @{sbin}/userdel  rpx,

  /etc/adduser.conf r,
  /etc/deluser.conf r,

  owner /etc/shadow r,

  #aa:lint ignore=too-wide
  # This is for the "--remove-all-files" flag, which it used to remove all files owned by the user
  # that's going to be deleted. Basically it scans all the files in the system in each dir and look
  # for matches. This also includes files required by the "--remove-home" flag as well as the
  # "--backup" and --backup-to flags.
  /   r,
  /** rwk,

  profile mount flags=(complain) {
    include <abstractions/base-strict>

    @{bin}/mount mr,

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

    @{sys}/devices/virtual/block/**/name r,

    include if exists <local/deluser_mount>
  }

  include if exists <local/deluser>
}

# vim:syntax=apparmor
