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

abi <abi/4.0>,

include <tunables/global>

@{exec_path} = /usr/share/cockpit/motd/update-motd
profile cockpit-update-motd /usr/share/cockpit/motd/update-motd flags=(complain) {
  include <abstractions/base>
  include <abstractions/nameservice-strict>

  @{exec_path} mr,

  @{sh_path}        rix,
  @{bin}/hostname   rix,
  @{bin}/ip         rPx,
  @{bin}/sed        rix,
  @{bin}/systemctl  rCx -> systemctl,

  @{run}/cockpit/active.motd rw,

  owner /dev/tty rw,

  profile systemctl flags=(complain) {
    include <abstractions/base>
    include <abstractions/app/systemctl>
  
    capability net_admin,
    capability sys_ptrace,

    @{PROC}/sys/kernel/cap_last_cap r,

    include if exists <local/cockpit-update-motd_systemctl>
  }

  include if exists <local/cockpit-update-motd>
}