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

abi <abi/3.0>,

include <tunables/global>

@{exec_path} = @{bin}/smartd
profile smartd @{exec_path} {
  include <abstractions/base>
  include <abstractions/disks-read>
  include <abstractions/nameservice-strict>

  capability sys_rawio,
  capability sys_admin,

  # Needed?
  audit capability net_admin,

  @{exec_path} mr,

  @{sh_path}        rix,
  @{bin}/cat        rix,
  @{bin}/hostname   rix,
  @{bin}/mail       rix,
  @{bin}/mktemp     rix,
  @{bin}/run-parts  rix,

  /etc/smartmontools/run.d/* rix,
  /usr/share/smartmontools/{smartd-runner,smartd_warning.sh} rix,

  /etc/smart_drivedb.h r,
  /etc/smartd.conf r,
  /etc/smartmontools/smartd_warning.d/{,*} r,
  /usr/share/smartmontools/drivedb.h r,
  /var/lib/smartmontools/drivedb/drivedb.h r,

  /var/lib/smartmontools/smartd.*.state{,~} rw,
  /var/lib/smartmontools/attrlog.*.csv rw,

  /tmp/tmp.* rw,

  @{run}/systemd/notify rw,

  @{sys}/class/scsi_host/ r,

  @{PROC}/devices r,

  /dev/ r,

  include if exists <local/smartd>
}
