# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2019-2022 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}/sudo
profile sudo @{exec_path} flags=(attach_disconnected) {
  include <abstractions/base>
  include <abstractions/app-launcher-root>
  include <abstractions/app/sudo>

  capability chown,
  capability fowner,
  capability mknod,
  capability sys_ptrace,

  network inet dgram,
  network inet6 dgram,

  ptrace (read),

  signal (send,receive) peer=cockpit-bridge,
  signal (send) peer=@{p_systemd},
  signal (send) set=(cont,hup,winch) peer=su,
  signal (send) set=(winch) peer=child-pager,
  signal (send) set=(winch) peer=journalctl,
  signal (send) set=(winch) peer=pacman,

  @{bin}/@{shells}                  rUx,
  @{lib}/**                         PUx,
  /opt/*/**                         PUx,
  /snap/snapd/@{int}@{bin}/snap    rPUx,

  /etc/default/locale r,

        /var/db/sudo/lectured/ r,
  owner /var/db/sudo/lectured/@{uid} rw,
  owner /var/lib/extrausers/shadow r,

        /var/lib/sudo/lectured/ r,
  owner /var/lib/sudo/lectured/@{uid} rw,

  @{run}/ r,
  @{run}/systemd/sessions/* r,
  @{run}/systemd/sessions/?@{int}.ref rw,

  @{sys}/fs/cgroup/*.slice{,/*.slice}/*.service/cgroup.procs r,

  include if exists <local/sudo>
}

# vim:syntax=apparmor
