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

abi <abi/4.0>,

include <tunables/global>

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

  capability dac_read_search,
  capability net_admin,
  capability sys_ptrace,
  capability sys_resource,

  ptrace read peer=@{p_systemd},

  unix bind type=stream addr=@@{udbus}/bus/run0/system,
  unix bind type=stream addr=@@{udbus}/bus/systemd-run/,

  signal receive set=(cont term),
  signal send    set=(cont term)       peer=systemd-run//run,
  signal send    set=(cont term winch) peer=systemd-tty-ask-password-agent,

  dbus send bus=system path=/org/freedesktop/systemd1/unit/run_*service
       interface=org.freedesktop.DBus.Properties
       member=GetAll
       peer=(name=org.freedesktop.systemd1, label="@{p_systemd}"),

  dbus receive bus=system path=/org/freedesktop/systemd1/unit/run_*service
       interface=org.freedesktop.DBus.Properties
       member=PropertiesChanged
       peer=(name=@{busname}, label="@{p_systemd}"),

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

  @{exec_path} mr,

  @{bin}/pkttyagent  rpx,
  @{bin}/systemd-tty-ask-password-agent px,

  # Allow to open everything (equivalent to child-open-any)
  @{bin}/**                     pux,
  @{lib}/**                     pux,
  @{user_bin_dirs}/**           pux,
  /opt/*/**                     pux,
  /usr/local/bin/**             pux,
  /usr/share/**                 pux,

  @{run}/systemd/private rw,

  owner @{PROC}/@{pid}/stat r,

        /dev/ptmx rw,
  owner /dev/pts/@{u16} rw,

  include if exists <local/systemd-run>
}

# vim:syntax=apparmor

