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

abi <abi/3.0>,

include <tunables/global>

@{lib_dirs} = @{lib}/ /snap/{snapd,core}/@{int}@{lib}

@{exec_path} = @{lib_dirs}/snapd/snap-update-ns
profile snap-update-ns @{exec_path} {
  include <abstractions/base>

  capability dac_override,
  capability sys_admin,
  capability sys_chroot,

  network netlink raw,

  mount -> /boot/,
  mount -> /snap/**,
  mount -> /tmp/.snap/**,
  mount -> /usr/**,
  mount -> /var/lib/dhcp/,
  umount /snap/**,
  umount /var/lib/dhcp/,

  @{exec_path} mr,

  /var/lib/snapd/mount/{,*} r,

  / r,
  /tmp/ r,

  owner /snap/{,**} rw,

  owner /var/ rw,
  owner /var/snap/ rw,
  owner /var/snap/**/ rw,

  owner @{tmp}/.snap/{,**} rwk,

  @{run}/snapd/lock/*.lock rwk,
  @{run}/snapd/ns/{,**} rw,

  @{sys}/fs/cgroup/{,**/} r,
  @{sys}/fs/cgroup/system.slice/snap.*.service/cgroup.freeze rw,
  @{sys}/fs/cgroup/user.slice/user-@{uid}.slice/user@@{uid}.service/app.slice/snap*.service/cgroup.freeze rw,
  @{sys}/kernel/mm/transparent_hugepage/hpage_pmd_size r,

  @{PROC}/@{pids}/cgroup r,
  @{PROC}/cmdline r,
  @{PROC}/version r,

  include if exists <local/snap-update-ns>
}

# vim:syntax=apparmor
