# 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

# Note: This profile does not specify an attachment path because it is
# intended to be used only via "px -> child-dpkg" exec transitions from
# other profiles. We want to confine the dpkg(1) utility when it
# is invoked from other confined applications, but not when it is used
# in regular (unconfined) shell scripts or run directly by the user.

abi <abi/4.0>,

include <tunables/global>

@{exec_path} = @{bin}/dpkg
@{att} = /att/child-dpkg/
profile child-dpkg  flags=(attach_disconnected,attach_disconnected.path=@{att},complain) {
  include <abstractions/attached/base>
  include <abstractions/attached/consoles>
  include <abstractions/nameservice-strict>

  capability dac_read_search,
  capability setgid,

  @{exec_path} mr,

  # Do not strip env to avoid errors like the following:
  #  ERROR: ld.so: object 'libfakeroot-sysv.so' from LD_PRELOAD cannot be preloaded (cannot open
  #  shared object file): ignored.
  @{bin}/dpkg-query rpx,
  @{bin}/dpkg-deb rpx,
  @{bin}/dpkg-split rpx,

  /etc/dpkg/dpkg.cfg.d/{,*} r,
  /etc/dpkg/dpkg.cfg r,

  /usr/share/doc/perl-modules-*/{,**/}*.dpkg-{new,tmp} rwl,
  /usr/share/perl/*/{,**/}*.dpkg-{new,tmp} rwl,

  /var/lib/dpkg/** r,
  /var/lib/dpkg/lock rw,
  /var/lib/dpkg/tmp.ci/control rw,
  /var/lib/dpkg/tmp.ci/md5sums rw,
  /var/lib/dpkg/triggers/Lock rw,
  /var/lib/dpkg/updates/* rw,
  /var/log/dpkg.log rw,

  # file_inherit
  /tmp/#@{int} rw,

  include if exists <local/child-dpkg>
}

# vim:syntax=apparmor
