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

# TODO: GNOME JavaScript interpreter. It is used to run some gnome internal app
# as well as third party extensions. Therefore, by default, some extension are
# confined under this profile. The resulting profile is quite broad.
# This architecture needs to be rethinked.

abi <abi/4.0>,

include <tunables/global>

@{exec_path} = @{bin}/gjs-console
profile gjs-console @{exec_path} flags=(attach_disconnected) {
  include <abstractions/base>
  include <abstractions/attached/consoles>
  include <abstractions/bus-session>
  include <abstractions/bus-system>
  include <abstractions/bus/org.freedesktop.portal.Desktop>
  include <abstractions/bus/org.gnome.Shell.Introspect>
  include <abstractions/bus/org.gtk.vfs.MountTracker>
  include <abstractions/dconf-write>
  include <abstractions/fontconfig-cache-write>
  include <abstractions/gnome-strict>
  include <abstractions/graphics>
  include <abstractions/nameservice-strict>

  network netlink raw,

  signal (receive) set=(term hup) peer=gdm*,

  #aa:dbus own bus=session name=org.freedesktop.Notifications
  #aa:dbus own bus=session name=org.gnome.ScreenSaver
  #aa:dbus own bus=session name=org.gnome.Shell.Extensions
  #aa:dbus own bus=session name=org.gnome.Shell.Notifications
  #aa:dbus own bus=session name=org.gnome.Shell.Screencast

  #aa:dbus talk bus=session name=org.gnome.Mutter.ScreenCast label=gnome-shell

  dbus send bus=session path=/org/gnome/Shell
       interface=org.freedesktop.DBus.Properties
       member=GetAll
       peer=(name=:*, label=gnome-shell),
  dbus send bus=session path=/org/gnome/Shell
       interface=org.gnome.Shell.Extensions
       member=ListExtensions
       peer=(name=:*, label=gnome-shell),

  @{exec_path} mr,

  @{bin}/       r,
  @{bin}/*    PUx,
  @{lib}/**   PUx,

  /usr/share/gnome-shell/extensions/gsconnect@andyholmes.github.io/{service/daemon.js,gsconnect-preferences} rPx,
  @{user_share_dirs}/gnome-shell/extensions/gsconnect@andyholmes.github.io/{service/daemon.js,gsconnect-preferences} rPx,

  /etc/openni2/OpenNI.ini r,

  /usr/share/dconf/profile/gdm r,
  /usr/share/gdm/greeter-dconf-defaults r,
  /usr/share/gnome-shell/{,**} r,

  /tmp/ r,
  /var/tmp/ r,

  owner @{gdm_cache_dirs}/fontconfig/[a-f0-9]*.cache-?{,.NEW,.LCK,.TMP-*} rwl,
  owner @{gdm_cache_dirs}/gstreamer-1.0/ rw,
  owner @{gdm_cache_dirs}/gstreamer-1.0/registry.*.bin{,.tmp@{rand6}} rw,
  owner @{gdm_config_dirs}/dconf/user r,
  owner @{GDM_HOME}/greeter-dconf-defaults r,

  owner @{HOME}/ r,

  owner @{user_share_dirs}/gnome-shell/extensions/{,**} r,
  owner @{user_cache_dirs}/gstreamer-1.0/ rw,
  owner @{user_cache_dirs}/gstreamer-1.0/registry.*.bin{,.tmp@{rand6}} rw,

  owner @{PROC}/@{pid}/cmdline r,
  owner @{PROC}/@{pid}/fd/ r,
  owner @{PROC}/@{pid}/mounts r,
  owner @{PROC}/@{pid}/stat r,
  owner @{PROC}/@{pid}/task/ r,
  owner @{PROC}/@{pid}/task/@{tid}/stat r,

  /dev/ r,
  /dev/tty rw,

  include if exists <local/gjs-console>
}

# vim:syntax=apparmor
