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

abi <abi/4.0>,

include <tunables/global>

@{exec_path} = @{bin}/sshfs
profile sshfs /{,usr/}{,s}bin/sshfs flags=(complain) {
  include <abstractions/base>

  mount fstype=fuse.sshfs -> @{HOME}/*/,
  mount fstype=fuse.sshfs -> @{HOME}/*/*/,

  unix (connect, send, receive) type=stream peer=(label="sshfs//fusermount",addr=none),

  @{exec_path} mr,

  @{bin}/ssh            rPx,
  @{bin}/fusermount{,3} rCx -> fusermount,

  @{PROC}/sys/fs/pipe-max-size r,

  /dev/fuse rw,

  profile fusermount flags=(complain) {
    include <abstractions/base>
    include <abstractions/nameservice-strict>

    capability sys_admin,

    mount fstype={fuse,fuse.sshfs} -> @{HOME}/*/,
    mount fstype={fuse,fuse.sshfs} -> @{HOME}/*/*/,

    unix (connect, send, receive) type=stream peer=(label="sshfs",addr=none),

    @{bin}/fusermount{,3} mr,

    /etc/fuse.conf r,

    @{PROC}/@{pid}/mounts r,

    /dev/fuse rw,

    include if exists <local/sshfs_fusermount>
  }

  include if exists <local/sshfs>
}
