# 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} = /usr/share/aurpublish/*.hook
@{att} = ""
profile aurpublish /usr/share/aurpublish/*.hook flags=(complain) {
  include <abstractions/base-strict>
  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}/{,e}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/*/src/ w,
  owner @{tmp}/tmp.@{rand10} rw,

  /dev/tty rw,

  profile gpg flags=(complain) {
    include <abstractions/base-strict>

    @{bin}/gpg{,2} mr,
    @{bin}/gpgconf mr,
    @{bin}/gpg-agent rix,
    @{lib}/{,gnupg/}scdaemon rix,

    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 @{run}/user/@{uid}/ r,
    owner @{run}/user/@{uid}/gnupg/ r,
    owner @{run}/user/@{uid}/gnupg/d.@{rand}/ rw,
    owner @{run}/user/@{uid}/gnupg/d.@{rand}/S.gpg-agent rw,
    owner @{run}/user/@{uid}/gnupg/d.@{rand}/S.gpg-agent.browser w,
    owner @{run}/user/@{uid}/gnupg/d.@{rand}/S.gpg-agent.extra w,
    owner @{run}/user/@{uid}/gnupg/d.@{rand}/S.gpg-agent.ssh w,

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

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

    include if exists <local/aurpublish_gpg>
  }

  include if exists <local/aurpublish>
}

# vim:syntax=apparmor
