# apparmor.d - Full set of apparmor profiles
# 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}/paccache
@{att} = /att/paccache/
profile paccache /{,usr/}bin/paccache flags=(attach_disconnected,attach_disconnected.path=@{att}) {
  include <abstractions/attached/base>
  include <abstractions/attached/consoles>
  include <abstractions/attached/nameservice-strict>

  capability dac_override,
  capability dac_read_search,
  capability mknod,
  capability sys_ptrace, # optional: no audit

  @{exec_path} mr,

  @{sh_path}          rix,
  @{bin}/{m,g,}awk    rix,
  @{bin}/cat          rix,
  @{bin}/date         rix,
  @{bin}/find         rix,
  @{bin}/gettext      rix,
  @{bin}/gpg{,2}      rix,
  @{bin}/gpgconf      rix,
  @{bin}/gpgsm        rix,
  @{bin}/mv           rix,
  @{bin}/pacman       rix,
  @{bin}/pacman-conf  rix,
  @{bin}/pacsort      rix,
  @{bin}/rm           rix,
  @{bin}/stat         rix,
  @{bin}/sudo         rcx -> sudo,
  @{bin}/tput         rix,
  @{bin}/xargs        rix,

  /usr/share/makepkg/util/*.sh r,
  /usr/share/terminfo/** r,

  /etc/pacman.conf r,
  /etc/pacman.d/{,**} r,
  /etc/pacman.d/gnupg/** rwlk -> /etc/pacman.d/gnupg/**,

  /var/cache/pacman/pkg/{,**} rw,
  /var/lib/pacman/{,**} r,

  @{user_gpg_dirs}/gpg.conf r,
  @{user_gpg_dirs}/gpgsm.conf r,

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

  # Silencer
  deny network inet dgram,
  deny network inet6 dgram,

  profile sudo {
    include <abstractions/attached/base>
    include <abstractions/app/sudo>
    include <abstractions/attached/consoles>

    capability sys_ptrace,

    ptrace read,

    @{bin}/mv    rix,
    @{bin}/rm    rix,
    @{bin}/xargs rix,

    /var/cache/pacman/pkg/** rw,

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

    include if exists <local/paccache_sudo>
  }

  include if exists <local/paccache>
}

# vim:syntax=apparmor
