# 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/3.0>,

include <tunables/global>

@{exec_path} = @{bin}/dpkg-preconfigure
profile dpkg-preconfigure @{exec_path} {
  include <abstractions/base>
  include <abstractions/consoles>
  include <abstractions/perl>
  include <abstractions/nameservice-strict>

  #capability sys_tty_config,

  @{exec_path} r,
  @{bin}/perl r,

  @{sh_path}        rix,
  @{bin}/{,e}grep   rix,
  @{bin}/{,g,m}awk  rix,
  @{bin}/cat        rix,
  @{bin}/dialog     rix,
  @{bin}/locale     rix,
  @{bin}/sed        rix,
  @{bin}/sort       rix,
  @{bin}/stty       rix,
  @{bin}/tr         rix,

  @{bin}/dpkg                 rPx -> child-dpkg,
  @{bin}/apt-extracttemplates rPx,
  @{bin}/whiptail             rPx,

  /usr/share/debconf/confmodule r,

  /etc/debconf.conf r,
  /etc/default/grub r,
  /etc/inputrc r,
  /etc/shadow r,

  owner @{tmp}/*.template.* rw,
  owner @{tmp}/*.config.* rwPUx,

        /var/lib/dbus/machine-id r,
  owner /var/cache/debconf/ rw,
  owner /var/cache/debconf/{config,passwords,templates}.dat{,-old,-new} rwk,
  owner /var/cache/debconf/tmp.ci/ r,
  owner /var/cache/debconf/tmp.ci/* rix,
  owner /var/cache/debconf/tmp.ci/*.config.@{rand6} w,
  owner /var/cache/debconf/tmp.ci/*.passwords.@{rand6} w,
  owner /var/cache/debconf/tmp.ci/*.template.@{rand6} w,
  owner /var/log/unattended-upgrades/unattended-upgrades-dpkg.log rw,

  @{run}/user/@{uid}/.mutter-Xwaylandauth.@{rand6} r,
  @{run}/user/@{uid}/pk-debconf-socket rw,

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

  # The following is needed when dpkg-preconfigure uses debcconf 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 -> lsb_release,
  @{bin}/hostname    rix,
  @{HOME}/.Xauthority r,
  owner @{PROC}/@{pid}/mounts r,

  include if exists <local/dpkg-preconfigure>
}

# vim:syntax=apparmor
