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

abi <abi/4.0>,

include <tunables/global>

@{exec_path} = @{bin}/login
@{att} = /att/login/
profile login /{,usr/}bin/login  flags=(attach_disconnected,attach_disconnected.path=@{att},complain) {
  include <abstractions/attached/base>
  include <abstractions/authentication>
  include <abstractions/bus-system>
  include <abstractions/attached/consoles>
  include <abstractions/nameservice-strict>
  include <abstractions/wutmp>


  capability audit_write,
  capability chown,
  capability dac_override,
  capability dac_read_search,
  capability fowner,
  capability fsetid,
  capability kill,
  capability net_admin,
  capability setgid,
  capability setuid,
  capability sys_resource,
  capability sys_tty_config,

  network netlink raw,

  signal send set=(hup term),

  ptrace read,

  unix type=stream addr=none peer=(label="@{p_systemd_logind}", addr=none),

  dbus (send receive) bus=system path=/org/freedesktop/login1{,/**}
       interface=org.freedesktop.login1{,.*}
       peer=(name="{@{busname},org.freedesktop.login1{,.*}}", label="@{p_systemd_logind}"),
  dbus (send receive) bus=system path=/org/freedesktop/login1{,/**}
       interface=org.freedesktop.DBus.Properties
       member={Get,GetAll,Set,PropertiesChanged}
       peer=(name="{@{busname},org.freedesktop.login1{,.*}}", label="@{p_systemd_logind}"),
  dbus send bus=system path=/org/freedesktop/login1{,/**}
       interface=org.freedesktop.DBus.Introspectable
       member=Introspect
       peer=(name="{@{busname},org.freedesktop.login1{,.*}}", label="@{p_systemd_logind}"),
  dbus send bus=system path=/org/freedesktop/login1{,/**}
       interface=org.freedesktop.DBus.ObjectManager
       member=GetManagedObjects
       peer=(name="{@{busname},org.freedesktop.login1{,.*}}", label="@{p_systemd_logind}"),
  dbus receive bus=system path=/org/freedesktop/login1{,/**}
       interface=org.freedesktop.DBus.ObjectManager
       member={InterfacesAdded,InterfacesRemoved}
       peer=(name="{@{busname},org.freedesktop.login1{,.*}}", label="@{p_systemd_logind}"),

  @{exec_path} mr,

  @{shells_path}     ux,

  @{etc_ro}/environment r,
  @{etc_ro}/security/group.conf r,
  @{etc_ro}/security/limits.conf r,
  @{etc_ro}/security/limits.d/{,*} r,
  @{etc_ro}/security/pam_env.conf r,
  /etc/default/locale r,
  /etc/legal r,
  /etc/machine-id r,
  /etc/motd r,
  /etc/motd.d/ r,
  /etc/shells r,

  /var/lib/faillock/@{user} rwk,
  /var/lib/lastlog/ r,
  /var/log/btmp{,.@{int}} r,

  owner @{user_cache_dirs}/ w,
  owner @{user_cache_dirs}/motd.legal-displayed rw,

  @{att}@{run}/systemd/sessions/@{int}.ref w,

  @{run}/credentials/getty@tty@{int}.service/ r,
  @{run}/faillock/@{user} rwk,
  @{run}/motd.d/{,*} r,
  @{run}/motd.dynamic{,.new} rw,

        @{PROC}/@{pids}/cgroup r,
        @{PROC}/1/limits r,
  owner @{PROC}/@{pid}/loginuid rw,
  owner @{PROC}/@{pid}/uid_map r,

  /dev/tty@{int} rw,

  include if exists <local/login>
}

# vim:syntax=apparmor
