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