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

# Minimal set of rules for sudo. Interactive sudo need more rules.

  include <abstractions/authentication>
  include <abstractions/bus-system>
  include <abstractions/consoles>
  include <abstractions/nameservice-strict>
  include <abstractions/wutmp>

  capability audit_write,
  capability dac_override,
  capability dac_read_search,
  capability net_admin,
  capability setgid,
  capability setuid,
  capability sys_resource,

  network netlink raw,   # PAM

  dbus send bus=system path=/org/freedesktop/login1
       interface=org.freedesktop.logi1.Manager
       member=CreateSession
       peer=(name=org.freedesktop.login1, label=systemd-logind),

  dbus (send receive) bus=session path=/org/freedesktop/systemd1
         interface=org.freedesktop.systemd.Manager
         member={JobRemoved,StartTransientUnit},

  @{bin}/sudo     mr,
  @{lib}/sudo/**  mr,

  @{etc_ro}/environment r,
  @{etc_ro}/security/limits.d/{,*} r,
  @{etc_ro}/sudo.conf r,
  @{etc_ro}/sudoers r,
  @{etc_ro}/sudoers.d/{,*} r,

  / r,
  /etc/machine-id r,

        /var/db/sudo/lectured/ r,
  owner /var/lib/sudo/ts/ rw,   
  owner /var/lib/sudo/ts/@{uid} rwk,
  owner /var/log/sudo.log wk,

  owner @{HOME}/.sudo_as_admin_successful rw,

        @{run}/faillock/ rw,
        @{run}/faillock/@{user} rwk,
  owner @{run}/sudo/ rw,
  owner @{run}/sudo/ts/ rw,
  owner @{run}/sudo/ts/@{uid} rwk,

  @{PROC}/@{pid}/limits r,
  @{PROC}/@{pid}/loginuid r,
  @{PROC}/@{pid}/stat r,
  @{PROC}/sys/kernel/cap_last_cap r,
  @{PROC}/sys/kernel/ngroups_max r,
  @{PROC}/sys/kernel/seccomp/actions_avail r,

        /dev/ r,
        /dev/ptmx rwk,
        /dev/tty rwk,
  owner /dev/tty@{int} rw,

  deny @{user_share_dirs}/gvfs-metadata/* r,

  include if exists <abstractions/app/sudo.d>

# vim:syntax=apparmor
