# 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}/homectl
@{att} = /att/homectl/
profile homectl /{,usr/}bin/homectl  flags=(attach_disconnected,attach_disconnected.path=@{att},complain) {
  include <abstractions/attached/base>
  include <abstractions/bus-system>
  include <abstractions/common/systemd>
  include <abstractions/attached/consoles>
  include <abstractions/nameservice-strict>

  capability net_admin,
  capability sys_resource,

  signal send peer=child-pager,

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

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

  @{exec_path} mr,

  @{bin}/pkttyagent  rpx,

  @{pager_path} rpx -> child-pager,

  /etc/machine-id r,

  owner @{PROC}/@{pids}/cgroup r,

  /dev/tty rw,

  include if exists <local/homectl>
}

# vim:syntax=apparmor
