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

# Note: This profile does not specify an attachment path because it is
# intended to be used only via "px -> child-systemctl" exec transitions
# from other profiles. We want to confine the systemctl(1) utility when
# it is invoked from other confined applications, but not when it is
# used in regular (unconfined) shell scripts or run directly by the user.

abi <abi/4.0>,

include <tunables/global>

@{exec_path} = @{bin}/systemctl
@{att} = /att/child-systemctl/
profile child-systemctl  flags=(attach_disconnected,attach_disconnected.path=@{att},complain) {
  include <abstractions/attached/base>
  include <abstractions/bus-system>
  include <abstractions/attached/consoles>
  include <abstractions/common/systemd>
  include <abstractions/wutmp>

  capability mknod,
  capability net_admin,
  capability sys_ptrace,

  network inet stream,
  network inet6 stream,

  dbus send bus=system path=/org/freedesktop/systemd1
       interface=org.freedesktop.systemd1.Manager
       member=GetUnitFileState
       peer=(name=org.freedesktop.systemd1, label="@{p_systemd}"),

  @{exec_path} mr,

  /etc/machine-id r,
  /etc/systemd/user/{,**} rwl,

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

  @{run}/systemd/private rw,

  include if exists <local/child-systemctl>
}

# vim:syntax=apparmor
