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

abi <abi/4.0>,

include <tunables/global>

@{exec_path} = @{bin}/firewalld
profile firewalld @{exec_path} flags=(attach_disconnected) {
  include <abstractions/base>
  include <abstractions/app/kmod>
  include <abstractions/bus-session>
  include <abstractions/bus-system>
  include <abstractions/bus/org.freedesktop.NetworkManager>
  include <abstractions/bus/org.freedesktop.PolicyKit1>
  include <abstractions/nameservice-strict>

  capability dac_read_search,
  capability mknod,
  capability net_admin,
  capability net_raw,
  capability setpcap,
  capability sys_module,

  network inet raw,
  network inet6 raw,
  network netlink raw,

  #aa:dbus own bus=system name=org.fedoraproject.FirewallD1

  @{exec_path} mr,

  @{bin}/ r,
  @{bin}/alts                     rix,
  @{bin}/ebtables-legacy          rix,
  @{bin}/ebtables-legacy-restore  rix,
  @{bin}/false                    rix,
  @{bin}/ipset                    rix,
  @{bin}/kmod                     rix,
  @{bin}/modprobe                 rix,
  @{bin}/xtables-legacy-multi     rix,
  @{bin}/xtables-nft-multi        rix,

  /usr/local/lib/python3.@{int}/dist-packages/ r,

  /usr/share/iproute2/{,**} r,
  /usr/share/libalternatives/{,**} r,

  /etc/firewalld/{,**} rw,
  /etc/iproute2/group r,
  /etc/iproute2/rt_realms r,

  /var/lib/ebtables/lock rwk,

  /var/log/firewalld rw,

  @{run}/firewalld/{,*} rw,
  @{run}/modprobe.d/{,*.conf} r,
  @{run}/xtables.lock rwk,

  @{sys}/module/compression r,
  @{sys}/module/*/initstate r,

        @{PROC}/sys/kernel/modprobe r,
        @{PROC}/sys/net/ipv{4,6}/ip_forward rw,
  owner @{PROC}/@{pid}/fd/ r,
  owner @{PROC}/@{pid}/mounts r,
  owner @{PROC}/@{pids}/net/ip_tables_names r,

  include if exists <local/firewalld>
}

# vim:syntax=apparmor
