# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2018-2022 Mikhail Morfikov
# 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} = @{lib}/systemd/systemd-hostnamed
profile systemd-hostnamed @{exec_path} flags=(attach_disconnected) {
  include <abstractions/base>
  include <abstractions/bus-system>
  include <abstractions/bus/org.freedesktop.PolicyKit1>
  include <abstractions/common/systemd>

  capability sys_admin,  # To set a hostname

  network unix stream,

  unix (bind) type=stream addr=@@{udbus}/bus/systemd-hostnam/system,

  #aa:dbus own bus=system name=org.freedesktop.hostname1

  dbus send bus=system path=/org/freedesktop/DBus
       interface=org.freedesktop.DBus
       member=GetConnectionUnixUser
       peer=(name=org.freedesktop.DBus, label="@{p_dbus_system}"),

  @{exec_path} mr,

  @{etc_rw}/.#hostname* rw,
  @{etc_rw}/hostname rw,
  /etc/.#machine-info@{hex16} rw,
  /etc/.#machine-info@{rand6} rw,
  /etc/machine-id r,
  /etc/machine-info rw,
  /etc/os-release r,

  @{att}/@{run}/systemd/notify rw,

  @{run}/systemd/default-hostname rw,
  @{run}/udev/data/+dmi:* r,              # for motherboard info

  @{sys}/devices/virtual/dmi/id/ r,
  @{sys}/devices/virtual/dmi/id/bios_date r,
  @{sys}/devices/virtual/dmi/id/bios_vendor r,
  @{sys}/devices/virtual/dmi/id/bios_version r,
  @{sys}/devices/virtual/dmi/id/board_vendor r,
  @{sys}/devices/virtual/dmi/id/chassis_type r,
  @{sys}/devices/virtual/dmi/id/product_name r,
  @{sys}/devices/virtual/dmi/id/product_version r,
  @{sys}/devices/virtual/dmi/id/sys_vendor r,
  @{sys}/devices/virtual/dmi/id/uevent r,
  @{sys}/firmware/acpi/pm_profile r,
  @{sys}/firmware/dmi/entries/*/raw r,

  /dev/vsock r,

  include if exists <local/systemd-hostnamed>
}

# vim:syntax=apparmor
