# 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>

@{lib_dirs} = @{HOME}/.tb/tor-browser/Browser/

@{exec_path} = @{bin}/torbrowser
profile torbrowser-wrapper @{exec_path} {
  include <abstractions/base>
  include <abstractions/consoles>
  include <abstractions/nameservice-strict>

  @{exec_path} rm,

  @{sh_path}                     rix,
  @{bin}/basename                 ix,
  @{bin}/cp                       ix,
  @{bin}/dirname                  ix,
  @{bin}/grep                     ix,
  @{bin}/id                       ix,
  @{bin}/mkdir                    ix,
  @{bin}/mktemp                   ix,
  @{bin}/mount                    ix,
  @{bin}/str_replace              ix,
  @{bin}/sudo                     Cx -> sudo,
  @{bin}/systemctl                Cx -> systemctl,
  @{bin}/touch                    ix,
  @{bin}/tty                      ix,
  @{bin}/whoami                   ix,

  @{lib_dirs}/start-tor-browser                         Px, # torbrowser-start 
  @{lib}/msgcollector/msgcollector                      Px,
  @{lib}/open-link-confirmation/open-link-confirmation  Px,

  @{lib}/helper-scripts/* r,

  /etc/torbrowser.d/{,*} r,

  owner /var/cache/tb-binary/{,**} rw,

  owner @{HOME}/.tb/{,**} rw,
  owner @{HOME}/.xsession-errors rw,
  
  owner @{tmp}/tmp.@{rand10} rw,

  owner @{run}/mount/utab r,
  
  owner @{PROC}/@{pid}/mountinfo r,

  profile sudo {
    include <abstractions/base>
    include <abstractions/app/sudo>

    @{lib}/tb-updater/tb-permission-fix rPx,

    include if exists <local/torbrowser-wrapper_sudo>
  }

  profile systemctl {
    include <abstractions/base>
    include <abstractions/app/systemctl>

    /etc/machine-id r,

    /{run,var}/log/journal/ r,
    /{run,var}/log/journal/@{hex32}/ r,
    /{run,var}/log/journal/@{hex32}/*.journal* r,

    include if exists <local/torbrowser-wrapper_systemctl>
  }

  include if exists <local/torbrowser-wrapper>
}

# vim:syntax=apparmor
