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

abi <abi/4.0>,

include <tunables/global>

@{exec_path} = @{bin}/hostnamectl
profile hostnamectl /{,usr/}{,s}bin/hostnamectl flags=(complain) {
  include <abstractions/base>
  include <abstractions/bus-system>
  include <abstractions/consoles>

  capability net_admin,

  dbus send bus=system path=/org/freedesktop/hostname1{,/**}
       interface=org.freedesktop.hostname1{,.*}
       peer=(name="{:1.@{int},org.freedesktop.hostname1{,.*}}", label=systemd-hostnamed),
  dbus send bus=system path=/org/freedesktop/hostname1{,/**}
       interface=org.freedesktop.DBus.Properties
       peer=(name="{:1.@{int},org.freedesktop.hostname1{,.*}}", label=systemd-hostnamed),
  dbus send bus=system path=/org/freedesktop/hostname1{,/**}
       interface=org.freedesktop.DBus.ObjectManager
       peer=(name="{:1.@{int},org.freedesktop.hostname1{,.*}}", label=systemd-hostnamed),
  dbus receive bus=system path=/org/freedesktop/hostname1{,/**}
       interface=org.freedesktop.hostname1{,.*}
       peer=(name="{:1.@{int},org.freedesktop.hostname1{,.*}}", label=systemd-hostnamed),
  dbus receive bus=system path=/org/freedesktop/hostname1{,/**}
       interface=org.freedesktop.DBus.Properties
       peer=(name="{:1.@{int},org.freedesktop.hostname1{,.*}}", label=systemd-hostnamed),
  dbus receive bus=system path=/org/freedesktop/hostname1{,/**}
       interface=org.freedesktop.DBus.ObjectManager
       peer=(name="{:1.@{int},org.freedesktop.hostname1{,.*}}", label=systemd-hostnamed),

  @{exec_path} mr,

  /etc/machine-id r,

  @{PROC}/sys/kernel/random/boot_id r,

  include if exists <local/hostnamectl>
}