# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2019-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-timesyncd
@{att} = /att/systemd-timesyncd/
profile systemd-timesyncd /{,usr/}lib{,exec,32,64}/systemd/systemd-timesyncd  flags=(attach_disconnected,attach_disconnected.path=@{att},complain) {
  include <abstractions/attached/base>
  include <abstractions/bus-system>
  include <abstractions/nameservice-strict>
  include <abstractions/common/systemd>

  capability sys_time,

  network inet dgram,
  network inet6 dgram,
  network inet stream,
  network inet6 stream,

  unix (bind) type=stream addr=@@{udbus}/bus/systemd-timesyn/bus-api-timesync,
  unix (send, receive) type=dgram addr=none peer=(label=@{p_sd}, addr=none),

  include <abstractions/bus/system/own>

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

  @{exec_path} mr,

  @{etc_rw}/adjtime r,
  /etc/systemd/timesyncd.conf r,
  /etc/systemd/timesyncd.conf.d/{,**} r,

  owner /var/lib/systemd/timesync/clock rw,

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

        @{run}/resolvconf/*.conf r,
        @{run}/systemd/netif/state r,
        @{run}/systemd/timesyncd.conf.d/{,**} r,
  owner @{run}/systemd/timesync/synchronized rw,

  @{PROC}/@{pid}/cgroup r,
  @{PROC}/pressure/* r,

  include if exists <local/systemd-timesyncd>
}

# vim:syntax=apparmor
