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

abi <abi/4.0>,

include <tunables/global>

@{exec_path} = @{bin}/loginctl
@{att} = ""
profile loginctl /{,usr/}bin/loginctl  flags=(complain) {
  include <abstractions/base-strict>
  include <abstractions/bus-system>
  include <abstractions/bus/system/org.freedesktop.systemd1>
  include <abstractions/common/systemd>
  include <abstractions/consoles>
  include <abstractions/nameservice-strict>

  capability net_admin,
  capability sys_resource,

  signal send set=cont peer=child-pager,

  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,

  @{pager_path} rpx -> child-pager,
  @{bin}/ssh    rpx,

  /etc/machine-id r,

  @{run}/log/journal/ r,

  /var/lib/systemd/catalog/database r,

  /{run,var}/log/journal/ r,
  /{run,var}/log/journal/@{hex32}/ r,
  /{run,var}/log/journal/@{hex32}/system.journal* r,
  /{run,var}/log/journal/@{hex32}/system@@{hex}-@{hex}.journal* r,
  /{run,var}/log/journal/@{hex32}/system@@{hex32}-@{hex16}-@{hex16}.journal* r,
  /{run,var}/log/journal/@{hex32}/user-@{hex}.journal* r,
  /{run,var}/log/journal/@{hex32}/user-@{uid}@@{hex}-@{hex}.journal* r,
  /{run,var}/log/journal/@{hex32}/user-@{uid}@@{hex32}-@{hex16}-@{hex16}.journal* r,

        @{PROC}/sys/fs/nr_open r,
  owner @{PROC}/@{pid}/cgroup r,

  /dev/rfkill r,

  include if exists <local/loginctl>
}

# vim:syntax=apparmor
