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

abi <abi/4.0>,

include <tunables/global>

@{exec_path} = @{sbin}/mount.nfs
@{att} = ""
profile mount-nfs /{,usr/}{,s}bin/mount.nfs flags=(complain) {
  include <abstractions/base-strict>
  include <abstractions/nameservice-strict>

  # To be able to mount anything
  capability sys_admin,

  capability chown,
  capability setgid,
  capability setuid,
  capability net_bind_service,

  network inet dgram,
  network inet6 dgram,
  network inet stream,
  network inet6 stream,

  # Allow to mount smb/cifs disks only under the /media/ dirs
  mount fstype=nfs -> @{MOUNTDIRS}/,
  mount fstype=nfs -> @{MOUNTS}/,
  mount fstype=nfs -> @{MOUNTS}/*/,
  mount fstype=nfs -> /,
  mount fstype=nfs -> /*/,

  umount @{MOUNTDIRS}/,
  umount @{MOUNTS}/,
  umount @{MOUNTS}/*/,
  umount /,
  umount /*/,

  @{exec_path} mr,

  @{sh_path}              rix,
  @{bin}/flock            rix,
  @{sbin}/start-statd     rix,
  @{bin}/systemctl        rcx -> systemctl,

  /etc/fstab r,
  /etc/netconfig r,
  /etc/nfsmount.conf rk,
  /etc/rpc r,

  # Mount points
  @{MOUNTDIRS}/ r,
  @{MOUNTS}/ r,
  @{MOUNTS}/*/ r,

  owner @{run}/mount/utab.lock wk,
  owner @{run}/mount/utab{,.*} rw,
  owner @{run}/rpc.statd.lock wk,

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

  profile systemctl {
    include <abstractions/base-strict>
    include <abstractions/app/systemctl>

    include if exists <local/mount-nfs_systemctl>
  }

  include if exists <local/mount-nfs>
}

# vim:syntax=apparmor
