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

include <tunables/global>

@{exec_path} = /usr/share/aurpublish/*.hook
profile aurpublish @{exec_path} {
  include <abstractions/base>
  include <abstractions/nameservice-strict>
  include <abstractions/ssl_certs>

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

  signal (receive) peer=git,

  @{exec_path} mr,

  @{sh_path}         rix,
  @{bin}/cat         rix,
  @{bin}/chmod       rix,
  @{bin}/curl        rix,
  @{bin}/date        rix,
  @{bin}/gettext     rix,
  @{bin}/git         rPx,
  @{bin}/gpg{,2}     rCx -> gpg,
  @{bin}/grep        rix,
  @{bin}/makepkg     rix,
  @{bin}/mkdir       rix,
  @{bin}/mktemp      rix,
  @{bin}/mv          rix,
  @{bin}/nproc       rix,
  @{bin}/rm          rix,
  @{bin}/sha*sum     rix,
  @{bin}/tput        rix,
  @{bin}/wc          rix,

  /usr/share/makepkg/{,**} r,
  /usr/share/terminfo/** r,

  /etc/makepkg.conf r,
  /etc/makepkg.conf.d/{,**} r,

  owner @{user_build_dirs}/**/ w,
  owner @{user_projects_dirs}/** r,
  owner @{user_projects_dirs}/**/.git/COMMIT_EDITMSG rw,
  owner @{user_projects_dirs}/**/.SRCINFO rw,

  owner @{user_cache_dirs}/makepkg/src/* rw,
  owner @{user_config_dirs}/pacman/makepkg.conf r,

  owner @{tmp}/tmp.@{rand10} rw,

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

  /dev/tty rw,

  profile gpg {
    include <abstractions/base>

    @{bin}/gpg{,2} mr,
    @{bin}/gpgconf mr,

    owner @{HOME}/@{XDG_GPG_DIR}/ rw,
    owner @{HOME}/@{XDG_GPG_DIR}/** rwkl -> @{HOME}/@{XDG_GPG_DIR}/**,

    owner @{user_cache_dirs}/makepkg/src/*.asc r,

    owner @{tmp}/tmp.@{rand10} rw,

    include if exists <local/aurpublish_gpg>
  }

  include if exists <local/aurpublish>
}

# vim:syntax=apparmor
