# 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/3.0>,

include <tunables/global>

@{exec_path} = @{bin}/terminator
profile terminator @{exec_path} flags=(attach_disconnected) {
  include <abstractions/base>
  include <abstractions/bus-accessibility>
  include <abstractions/bus-session>
  include <abstractions/bus/org.a11y>
  include <abstractions/consoles>
  include <abstractions/dconf-write>
  include <abstractions/desktop>
  include <abstractions/nameservice-strict>
  include <abstractions/python>

  capability sys_ptrace,

  ptrace,

  #aa:dbus own bus=session name=net.tenshu.Terminator@{hex}

  @{exec_path} mr,

  @{bin}/ r,
  @{bin}/python3.@{int} rix,

  # The shell is not confined on purpose.
  @{bin}/@{shells}      rUx,

  @{open_path} rPx,

  owner @{user_config_dirs}/terminator/{,**} rw,

  owner @{tmp}/#@{int} rw,

        @{PROC}/ r,
        @{PROC}/@{pid}/net/tcp{,6} r,
        @{PROC}/@{pid}/net/udp{,6} r,
        @{PROC}/@{pids}/cmdline r,
        @{PROC}/@{pids}/stat r,
        @{PROC}/1/cgroup r,
  owner @{PROC}/@{pid}/cgroup r,
  owner @{PROC}/@{pid}/environ r,
  owner @{PROC}/@{pid}/fd/ r,
  owner @{PROC}/@{pid}/fdinfo/@{tid} r,
  owner @{PROC}/@{pid}/io r,
  owner @{PROC}/@{pid}/mounts r,
  owner @{PROC}/@{pid}/smaps r,
  owner @{PROC}/@{pid}/smaps_rollup r,
  owner @{PROC}/@{pid}/statm r,
  owner @{PROC}/@{pid}/task/ r,
  owner @{PROC}/@{pid}/task/@{tid}/stat r,

  /dev/ r,
  /dev/dri/card@{int} rw,
  /dev/ptmx rw,

  deny @{user_share_dirs}/gvfs-metadata/{,*} r,

  include if exists <local/terminator>
}