# 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} = @{bin}/crontab
profile crontab /{,usr/}{,s}bin/crontab flags=(complain) {
  include <abstractions/base>
  include <abstractions/consoles>
  include <abstractions/nameservice-strict>

  capability setgid,
  capability setuid,

  @{exec_path} mr,

  @{sh_path}             rix,

  # When editing the crontab file
  @{bin}/sensible-editor rCx -> editor,
  @{bin}/vim.*           rCx -> editor,

  /etc/cron.{allow,deny} r,

        /var/spool/cron/ r,
        /var/spool/cron/crontabs/ rw,
  owner /var/spool/cron/crontabs/* rw,

  owner /tmp/crontab.*/{,crontab} rw,


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

    capability fsetid,

    @{bin}/sensible-editor mr,
    @{bin}/vim.*           mrix,
    @{sh_path}              rix,
    @{bin}/which{,.debianutils}            rix,

    owner @{HOME}/.selected_editor r,

    /usr/share/vim/{,**} r,
    /etc/vim/{,**} r,
    owner @{HOME}/.viminfo{,.tmp} rw,

          /tmp/ r,
    owner /tmp/crontab.*/crontab rw,

    # file_inherit
    /etc/cron.{allow,deny} r,

  }

  include if exists <local/crontab>
}
