# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2020-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} = /usr/share/debian-security-support/check-support-status.hook
@{att} = ""
profile check-support-status-hook /usr/share/debian-security-support/check-support-status.hook flags=(complain) {
  include <abstractions/base-strict>
  include <abstractions/consoles>
  include <abstractions/nameservice-strict>

  @{exec_path} r,
  @{sh_path}        rix,

  @{bin}/           r,
  @{bin}/getent     rix,
  @{bin}/mkdir      rix,
  @{bin}/chown      rix,
  @{bin}/stat       rix,
  @{bin}/mktemp     rix,
  @{bin}/rm         rix,

  @{sbin}/adduser             rpx,
  @{bin}/check-support-status rpx,
  @{bin}/debconf-escape       rcx -> debconf-escape,
  @{sbin}/runuser             rcx -> runuser,

  # Think what to do about this (#FIXME#)
  /usr/share/debconf/frontend      rpx,
  #/usr/share/debconf/frontend     rcx -> frontend,

  /usr/share/debconf/confmodule r,

  # For shell pwd
  / r,
  /root/ r,

        /tmp/ r,
  owner @{tmp}/debian-security-support.postinst.*/ rw,
  owner @{tmp}/debian-security-support.postinst.*/output rw,

  /var/lib/ r,
  /var/lib/debian-security-support/ r,


  profile debconf-escape flags=(complain) {
    include <abstractions/base-strict>
    include <abstractions/consoles>
    include <abstractions/perl>

    @{bin}/debconf-escape r,

          /tmp/ r,
    owner @{tmp}/debian-security-support.postinst.*/output r,

    include if exists <local/check-support-status-hook_debconf-escape>
  }

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

    /usr/share/debconf/frontend r,

    /usr/share/debian-security-support/ r,
    /usr/share/debian-security-support/check-support-status.hook rpx,

    @{sh_path}        rix,
    @{bin}/stty       rix,
    @{bin}/locale     rix,

    /etc/debconf.conf r,
    owner /var/cache/debconf/{config,passwords,templates}.dat{,-new,-old} rwk,

    # The following is needed when debconf uses GUI frontends.
    include <abstractions/gtk>
    include <abstractions/fonts>
    include <abstractions/fontconfig-cache-read>
    include <abstractions/freedesktop.org>
    capability dac_read_search,
    @{bin}/lsb_release rpx,
    @{bin}/hostname    rix,
    owner @{PROC}/@{pid}/mounts r,
    @{HOME}/.Xauthority r,

    include if exists <local/check-support-status-hook_frontend>
  }

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

    network netlink raw,

    # To remove the following errors:
    #  runuser: cannot set user id: Operation not permitted
    capability setuid,

    # To remove the following errrors:
    #  runuser: cannot set groups: Operation not permitted
    capability setgid,

    # To write records to the kernel auditing log.
    capability audit_write,

    @{sbin}/runuser mr,

    @{sh_path}        rix,

    @{bin}/check-support-status rpx,

    owner @{PROC}/@{pids}/loginuid r,
          @{PROC}/1/limits r,

    @{etc_ro}/security/limits.d/ r,

          /tmp/ r,
    owner @{tmp}/debian-security-support.postinst.*/output w,

    include if exists <local/check-support-status-hook_runuser>
  }

  include if exists <local/check-support-status-hook>
}

# vim:syntax=apparmor
