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

abi <abi/4.0>,

include <tunables/global>

@{exec_path} = @{bin}/ufw
profile ufw @{exec_path} flags=(attach_disconnected) {
  include <abstractions/base>
  include <abstractions/attached/consoles>
  include <abstractions/nameservice-strict>
  include <abstractions/python>

  capability dac_read_search,
  capability net_admin,
  capability net_raw,
  capability sys_ptrace,

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

  ptrace read,

  @{exec_path} mr,

  @{bin}/ r,
  @{bin}/cat ix,
  @{bin}/env r,
  @{bin}/python3.@{int} ix,
  @{bin}/sysctl ix,
  @{bin}/xtables-legacy-multi ix,
  @{bin}/xtables-nft-multi ix,
  @{lib}/ufw/ufw-init ix,

  /etc/default/ufw rw,
  /etc/ufw/ rw,
  /etc/ufw/** rwk,

        @{run}/xtables.lock rwk,
  owner @{run}/ufw.lock rwk,

  owner @{tmp}/@{word8} rw,
  owner @{tmp}/tmp@{word8} rw,
  owner /var/tmp/@{word8} rw,
  owner /var/tmp/tmp@{word8} rw,

  @{PROC}/@{pid}/fd/ r,
  @{PROC}/@{pid}/net/ip_tables_names r,
  @{PROC}/@{pid}/stat r,
  @{PROC}/sys/net/ipv{4,6}/** rw,
  @{PROC}/sys/kernel/modprobe r,

  include if exists <local/ufw>
}

# vim:syntax=apparmor
