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

abi <abi/4.0>,

include <tunables/global>

@{name} = heroic
@{domain} = org.chromium.Chromium
@{lib_dirs} = /opt/@{name}/ @{lib}/@{name}/
@{config_dirs} = @{user_config_dirs}/@{name}
@{cache_dirs} = @{user_cache_dirs}/@{name}
@{wineprefix_dirs} = @{HOME}/Games/Heroic/Prefixes/*/

@{exec_path} = @{bin}/heroic @{lib_dirs}/heroic
@{att} = /att/heroic/
profile heroic /{{,usr/}bin/heroic,opt/heroic/heroic,{,usr/}lib{,exec,32,64}/heroic/heroic} flags=(attach_disconnected,attach_disconnected.path=@{att},complain) {
  include <abstractions/attached/base>
  include <abstractions/audio-client>
  include <abstractions/common/electron>
  include <abstractions/graphics>
  include <abstractions/attached/nameservice-strict>
  include <abstractions/screensaver>
  include <abstractions/ssl_certs>
  include <abstractions/user-download-strict>
  include <abstractions/vulkan-strict>

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

  @{exec_path} mrix,
  @{sh_path}    rix,

  @{lib_dirs}/chrome-sandbox rix,

  # Bundled backend CLIs (legendary/gogdl/nile), vendored in heroic's own dir, not packaged
  @{lib_dirs}/resources/app.asar.unpacked/**/legendary{,.exe} rix,
  @{lib_dirs}/resources/app.asar.unpacked/**/gogdl{,.exe} rix,
  @{lib_dirs}/resources/app.asar.unpacked/**/nile{,.exe} rix,
  @{lib_dirs}/resources/app.asar.unpacked/**/comet{,.exe} rix,
  @{lib_dirs}/resources/app.asar.unpacked/**/vulkan-helper rix,

  # Launching games goes through umu-run (Proton/Wine) or native binaries.
  @{bin}/umu-run                    px,
  owner @{wineprefix_dirs}/ rw,
  owner @{wineprefix_dirs}/** rwlk,

  @{open_path} rpx -> child-open-strict,

  /etc/ r,

  owner @{HOME}/Games/{,**} rw,

  owner @{config_dirs}/{,**} rwk,
  owner @{cache_dirs}/{,**} rwk,

  owner @{user_config_dirs}/autostart/heroic.desktop rw,

  owner "@{tmp}/Heroic Crashes/" rw,
  owner @{tmp}/heroic.sock rw,

  owner @{run}/user/@{uid}/heroic-ipc-@{int} rw,

  owner @{PROC}/@{pid}/mem r,

  deny ptrace read,

  include if exists <local/heroic>
}

# vim:syntax=apparmor
