gitee.com/mysnapcore/mysnapd@v0.1.0/interfaces/builtin/microstack_support.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2020 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 /* 23 * Microstack is a full OpenStack in a single snap package. 24 * Virtual machines are spawned as QEMU processes with libvirt acting as a management 25 * daemon (including for activities such as applying AppArmor profiles). 26 * Networking is provided largely via OpenVSwitch and Neutron with dnsmasq acting 27 * as an auxiliary daemon. tun/tap kernel module is used for creating virtual interfaces. 28 * Virtual machines rely on KVM for virtualization acceleration and on vhost 29 * framework in the kernel (vhost_net, vhost_scsi, vhost_vsock). 30 * 31 * This interface uses the controlsDeviceCgroup flag (which implies 32 * `Delegate=true` on the systemd unit) since the snap already manages the 33 * cgroup configuration of its containers. 34 */ 35 36 const microStackSupportSummary = `allows operating as the MicroStack service` 37 38 const microStackSupportBaseDeclarationPlugs = ` 39 microstack-support: 40 allow-installation: false 41 deny-auto-connection: true 42 ` 43 44 const microStackSupportBaseDeclarationSlots = ` 45 microstack-support: 46 allow-installation: 47 slot-snap-type: 48 - core 49 deny-auto-connection: true 50 ` 51 52 const microStackSupportConnectedPlugAppArmor = ` 53 54 # Used by QEMU to work with the kernel-side virtio implementations. 55 /dev/vhost-net rw, 56 /dev/vhost-scsi rw, 57 /dev/vhost-vsock rw, 58 # Used by QEMU to work with VFIO (https://www.kernel.org/doc/Documentation/vfio.txt). 59 # For vfio hotplug on systems without static vfio (LP: #1775777) 60 # VFIO userspace driver interface. 61 /dev/vfio/vfio rw, 62 # Access to VFIO group character devices such as /dev/vfio/<group> where <group> is the group number. 63 /dev/vfio/* rw, 64 # Used by Nova for mounting images via qemu-nbd. 65 /dev/nbd* rw, 66 67 # Allow creating dm-* devices, /dev/<vg-name> directories, /dev/mapper directory and symlinks under it. 68 # Allow issuing ioctls to the Device Mapper for LVM tools via /dev/mapper/control. 69 /dev/mapper/control rw, 70 # Besides symlinks for LVs prefixed with a VG name this is also needed for DM devices created with 71 # dm-crypt and other DM modules. 72 /dev/mapper/{,**} rw, 73 # Allow device mapper devices to be accessed. 74 /dev/dm-* rw, 75 /dev/microstack-*/{,**} rw, 76 # Allow bcache devices to be accessed since DM devices may be set up on top of those. 77 /dev/bcache[0-9]{,[0-9],[0-9][0-9]} rw, # bcache (up to 1000 devices) 78 79 # Allow access to loop devices and loop-control to be able to associate a file with a loop device 80 # for the purpose of using a file-backed LVM setup. 81 /dev/loop-control rw, 82 /dev/loop[0-9]* rw, 83 84 # Description: this policy intentionally allows Microstack services to configure AppArmor 85 # as libvirt generates AppArmor profiles for the utility processes it spawns. 86 /sys/kernel/security/apparmor/{,**} r, 87 /sys/kernel/security/apparmor/.remove w, 88 /sys/kernel/security/apparmor/.replace w, 89 90 # Used by libvirt to work with IOMMU. 91 /sys/kernel/iommu_groups/{,**} r, 92 /sys/bus/pci/devices/**/iommu_group/** r, 93 94 # Used by libvirt's QEMU driver state initialization code path. 95 # The path used is hard-coded in libvirt to <huge-page-mnt-dir>/libvirt/qemu. 96 /dev/hugepages/libvirt/ rw, 97 /dev/hugepages/libvirt/** mrwklix, 98 99 # Used by QEMU to get the maximum number of memory regions allowed in the vhost kernel module. 100 /sys/module/vhost/parameters/max_mem_regions r, 101 102 # Used by libvirt (cgroup-related): 103 /sys/fs/cgroup/unified/cgroup.controllers r, 104 /sys/fs/cgroup/cpuset/cpuset.cpus r, 105 106 # Non-systemd layout: https://libvirt.org/cgroups.html#currentLayoutGeneric 107 /sys/fs/cgroup/*/ r, 108 /sys/fs/cgroup/*/machine/ rw, 109 /sys/fs/cgroup/*/machine/** rw, 110 111 # systemd-layout: https://libvirt.org/cgroups.html#systemdLayout 112 /sys/fs/cgroup/*/machine.slice/machine-qemu*/{,**} rw, 113 114 @{PROC}/[0-9]*/cgroup r, 115 @{PROC}/cgroups r, 116 117 # Used by libvirt. 118 @{PROC}/filesystems r, 119 @{PROC}/mtrr w, 120 @{PROC}/@{pids}/environ r, 121 @{PROC}/@{pids}/sched r, 122 123 @{PROC}/*/status r, 124 125 @{PROC}/sys/fs/nr_open r, 126 127 # Libvirt needs access to the PCI config space in order to be able to reset devices. 128 /sys/devices/pci*/**/config rw, 129 130 # Spice 131 owner /{dev,run}/shm/spice.* rw, 132 133 # Used by libvirt to create lock files for /dev/pts/<num> devices 134 # when handling virsh console access requests. 135 /run/lock/ r, 136 /run/lock/LCK.._pts_* rwk, 137 138 # Used by LVM tools. 139 /run/lock/lvm/ rw, 140 /run/lock/lvm/** rwk, 141 # Files like /run/lvm/pvs_online, /run/lvm/vgs_online, /run/lvm/hints 142 /run/lvm/ rw, 143 /run/lvm/** rwlk, 144 /run/dmeventd-client rwlk, 145 /run/dmeventd-server rwlk, 146 147 # Used by targetcli tools to work with LIO. 148 /sys/kernel/config/target/ rw, 149 /sys/kernel/config/target/** rw, 150 151 # Used by targetcli. 152 /{var/,}run/targetcli.lock rwlk, 153 154 # Paths accessed by iscsid during its operation. 155 /run/lock/iscsi/ rw, 156 /run/lock/iscsi/** rwlk, 157 /sys/devices/virtual/iscsi_transport/tcp/** r, 158 /sys/devices/virtual/iscsi_transport/iser/** r, 159 /sys/class/iscsi_session/** rw, 160 /sys/class/iscsi_host/** r, 161 /sys/devices/platform/host*/scsi_host/host*/** rw, 162 /sys/devices/platform/host*/session*/connection*/iscsi_connection/connection*/** rw, 163 /sys/devices/platform/host*/session*/iscsi_session/session*/** rw, 164 /sys/devices/platform/host*/session*/target*/** rw, 165 /sys/devices/platform/host*/iscsi_host/host*/** rw, 166 167 # While the block-devices interface allows rw access, Libvirt also needs to be able to lock those. 168 /dev/sd{,[a-h]}[a-z] rwk, 169 /dev/sdi[a-v] rwk, 170 # os-brick needs access to those when detaching a scsi device from an instance. 171 /sys/block/sd{,[a-h]}[a-z]/device/delete rw, 172 /sys/block/sdi[a-v]/device/delete rw, 173 174 # Used by open-iscsi to avoid being killed by the OOM killer. 175 owner @{PROC}/@{pid}/oom_score_adj rw, 176 177 178 # Allow running utility processes under the specialized AppArmor profiles. 179 # These profiles will prevent utility processes escaping confinement. 180 capability mac_admin, 181 182 # MicroStack services such as libvirt use a server/client design where 183 # unix sockets are used for IPC. 184 capability chown, 185 186 # Required by Nova. 187 capability dac_override, 188 capability dac_read_search, 189 capability fowner, 190 191 # Used by libvirt to alter process capabilities via prctl. 192 capability setpcap, 193 # Used by libvirt to create device special files. 194 capability mknod, 195 196 # Allow libvirt to apply policy to spawned VM processes. 197 change_profile -> libvirt-[0-9a-f]*-[0-9a-f]*-[0-9a-f]*-[0-9a-f]*-[0-9a-f]*, 198 199 # Allow sending signals to the spawned VM processes. 200 signal (read, send) peer=libvirt-*, 201 202 # Allow reading certain proc entries, see ptrace(2) "Ptrace access mode checking". 203 # For ourselves: 204 ptrace (read, trace) peer=@{profile_name}, 205 # For VM processes libvirt spawns: 206 ptrace (read, trace) peer=libvirt-*, 207 208 # Used by neutron-ovn-agent. 209 unmount /run/netns/ovnmeta-*, 210 ` 211 212 const microStackSupportConnectedPlugSecComp = ` 213 # Description: allow MicroStack to operate by allowing the necessary system calls to be used by various services. 214 # (libvirt, qemu, qemu-img, Nova, Neutron, Keystone, Glance, Cinder) 215 216 # Note that this profile necessarily contains the union of all the syscalls each of the 217 # utilities requires. We rely on MicroStack to generate specific AppArmor profiles 218 # for each child process, to further restrict their abilities. 219 mknod - |S_IFBLK - 220 mknodat - - |S_IFBLK - 221 ` 222 223 type microStackInterface struct { 224 commonInterface 225 } 226 227 var microStackSupportConnectedPlugKmod = []string{ 228 `vhost`, // Core vhost module. 229 `vhost-net`, // Used to offload virtio interface data plane into the kernel module. 230 `vhost-scsi`, // Used to offload virtio-scsi device data plane into the kernel module. 231 `vhost-vsock`, // virtio-vsock device support. 232 `pci-stub`, // May be used for binding a PCI device driver to a stub driver. 233 `vfio`, // The core VFIO driver for secure device assignment https://www.kernel.org/doc/html/latest/driver-api/vfio.html 234 `vfio-pci`, // PCI-specific VFIO functionality. 235 `nbd`, // The Network Block Device driver used by Nova (e.g. for block live migration). 236 `dm-mod`, // Device mapper. 237 `dm-thin-pool`, // DM thin pools used by the LVM driver in Cinder. 238 `dm-snapshot`, // DM snapshots used by the LVM driver in Cinder. 239 `iscsi-tcp`, // A module providing iscsi initiator functionality used by Nova via os-brick. 240 `target-core-mod`, // A module providing ConfigFS infrastructure utilized in LIO (which is used by Cinder for iSCSI targets). 241 } 242 243 func init() { 244 registerIface(µStackInterface{commonInterface{ 245 name: "microstack-support", 246 summary: microStackSupportSummary, 247 implicitOnCore: true, 248 implicitOnClassic: true, 249 controlsDeviceCgroup: true, 250 baseDeclarationSlots: microStackSupportBaseDeclarationSlots, 251 baseDeclarationPlugs: microStackSupportBaseDeclarationPlugs, 252 connectedPlugAppArmor: microStackSupportConnectedPlugAppArmor, 253 connectedPlugSecComp: microStackSupportConnectedPlugSecComp, 254 connectedPlugKModModules: microStackSupportConnectedPlugKmod, 255 serviceSnippets: []string{`Delegate=true`}, 256 }}) 257 }