gitee.com/mysnapcore/mysnapd@v0.1.0/interfaces/builtin/cifs_mount.go (about)

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 2018 Canonical Ltd
     5   *
     6   * This program is free software: you can redistribute it and/or modify
     7   * it under the terms of the GNU General Public License version 3 as
     8   * published by the Free Software Foundation.
     9   *
    10   * This program is distributed in the hope that it will be useful,
    11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13   * GNU General Public License for more details.
    14   *
    15   * You should have received a copy of the GNU General Public License
    16   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    17   *
    18   */
    19  
    20  package builtin
    21  
    22  const cifsMountSummary = `allows mounting and unmounting CIFS filesystems`
    23  
    24  const cifsMountBaseDeclarationSlots = `
    25    cifs-mount:
    26      allow-installation:
    27        slot-snap-type:
    28          - core
    29      deny-auto-connection: true
    30  `
    31  
    32  const cifsMountConnectedPlugSecComp = `
    33  # Description: Allow mount and umount syscall access.
    34  mount
    35  umount
    36  umount2
    37  `
    38  
    39  const cifsMountConnectedPlugAppArmor = `
    40  # Description: Allow mounting and unmounting CIFS filesystems.
    41  
    42  # Required for mounts and unmounts
    43  capability sys_admin,
    44  
    45  # Allow mounts to our snap-specific writable directories
    46  # parallel-installs: SNAP_{DATA,COMMON} are remapped, need to use SNAP_NAME, for
    47  # completeness allow SNAP_INSTANCE_NAME too
    48  mount fstype=cifs //** -> /var/snap/{@{SNAP_NAME},@{SNAP_INSTANCE_NAME}}/@{SNAP_REVISION}/{,**},
    49  mount fstype=cifs //** -> /var/snap/{@{SNAP_NAME},@{SNAP_INSTANCE_NAME}}/common/{,**},
    50  
    51  # NOTE: due to LP: #1613403, fstype is not mediated and as such, these rules
    52  # allow, for example, unmounting bind mounts from the content interface
    53  # parallel-installs: SNAP_{DATA,COMMON} are remapped, need to use SNAP_NAME, for
    54  # completeness allow SNAP_INSTANCE_NAME too
    55  umount /var/snap/{@{SNAP_NAME},@{SNAP_INSTANCE_NAME}}/@{SNAP_REVISION}/{,**},
    56  umount /var/snap/{@{SNAP_NAME},@{SNAP_INSTANCE_NAME}}/common/{,**},
    57  
    58  # Due to an unsolved issue with namespace awareness of libmount the unmount tries to access
    59  # /run/mount/utab but fails. The resulting apparmor warning can be ignored. The log warning
    60  # was not removed via an explicit deny to not interfere with other interfaces which might
    61  # decide to allow access (deny rules have precedence).
    62  #  - https://github.com/snapcore/snapd/pull/5340#issuecomment-398071797
    63  #  - https://forum.snapcraft.io/t/namespace-awareness-of-run-mount-utab-and-libmount/5987
    64  #deny /run/mount/utab w,
    65  `
    66  
    67  func init() {
    68  	registerIface(&commonInterface{
    69  		name:                  "cifs-mount",
    70  		summary:               cifsMountSummary,
    71  		implicitOnCore:        true,
    72  		implicitOnClassic:     true,
    73  		baseDeclarationSlots:  cifsMountBaseDeclarationSlots,
    74  		connectedPlugAppArmor: cifsMountConnectedPlugAppArmor,
    75  		connectedPlugSecComp:  cifsMountConnectedPlugSecComp,
    76  	})
    77  }