# 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}/apt-listbugs
profile apt-listbugs @{exec_path} {
  include <abstractions/base>
  include <abstractions/consoles>
  include <abstractions/ruby>
  include <abstractions/nameservice-strict>

  #capability sys_tty_config,

  network inet dgram,
  network inet6 dgram,
  network inet stream,
  network inet6 stream,
  network netlink raw,

  @{exec_path} r,
  @{bin}/ruby[0-9].@{int} rix,

  @{sh_path}              rix,
  @{bin}/logname          rix,

  @{bin}/apt-config       rPx,
  # 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,

  /usr/local/lib/site_ruby/[0-9].[0-9].[0-9]/**.rb r,

  /usr/share/rubygems-integration/*/specifications/ r,
  /usr/share/rubygems-integration/*/specifications/*.gemspec rwk,

  @{lib}/ruby/gems/*/specifications/ r,
  @{lib}/ruby/gems/*/specifications/** r,
  @{lib}/ruby/gems/*/specifications/**.gemspec rwk,

  /etc/apt/listbugs/{,*} r,

  @{PROC}/@{pid}/loginuid r,

  # The following is needed when apt-listbugs 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,
  owner @{PROC}/@{pid}/mounts r,
  @{HOME}/.Xauthority r,

  include if exists <local/apt-listbugs>
}

# vim:syntax=apparmor
