# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2019-2022 Mikhail Morfikov
# Copyright (C) 2022-2024 Alexandre Pujol <alexandre@pujol.io>
# SPDX-License-Identifier: GPL-2.0-only

abi <abi/3.0>,

include <tunables/global>

@{exec_path} = @{lib}/apt/methods/http{,s}
profile apt-methods-http @{exec_path} {
  include <abstractions/base>
  include <abstractions/consoles>
  include <abstractions/nameservice-strict>
  include <abstractions/ssl_certs>

  capability setgid,
  capability setuid,

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

  signal (receive) peer=apt-get,
  signal (receive) peer=apt,
  signal (receive) peer=aptitude,
  signal (receive) peer=packagekitd,
  signal (receive) peer=synaptic,
  signal (receive) peer=ubuntu-advantage,
  signal (receive) peer=unattended-upgrade,
  signal (receive) peer=update-manager,

  ptrace (read),

  @{exec_path} mr,

  # apt-helper gets "no new privs" so "rix" it
  @{lib}/apt/apt-helper rix,

  # For shell pwd
  / r,
  /etc/ r,
  /root/ r,

  /etc/apt/auth.conf.d/{,*} r,
  /etc/apt/apt.conf.d/{,*} r,
  /etc/apt/apt.conf r,

  /usr/share/dpkg/cputable r,
  /usr/share/dpkg/tupletable r,

  /var/cache/apt/ r,
  /var/cache/apt/** rwk,

  /var/log/cron-apt/temp w,

        /var/lib/apt/lists/{,**} r,
        /var/lib/ubuntu-advantage/apt-esm/{,**} r,
  owner /var/lib/apt/lists/{,**} rw,
  owner /var/lib/ubuntu-advantage/apt-esm/{,**} rw,
  owner /var/lib/apt/lists/partial/* rw,

  # For package building
  @{user_build_dirs}/** rwkl -> @{user_build_dirs}/**,

        /tmp/ r,
  owner @{tmp}/aptitude-root.*/aptitude-download-* rw,
  owner @{tmp}/apt-changelog-*/*.changelog rw,

  @{run}/ubuntu-advantage/aptnews.json rw,

  @{PROC}/1/cgroup r,
  @{PROC}/@{pid}/cgroup r,

  owner /dev/tty@{int} rw,

  include if exists <local/apt-methods-http>
}

# vim:syntax=apparmor
