| Serge Bazanski | e50ec39 | 2020-06-30 21:41:39 +0200 | [diff] [blame] | 1 | // Copyright 2020 The Monogon Project Authors. |
| 2 | // |
| 3 | // SPDX-License-Identifier: Apache-2.0 |
| 4 | // |
| 5 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | // you may not use this file except in compliance with the License. |
| 7 | // You may obtain a copy of the License at |
| 8 | // |
| 9 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | // |
| 11 | // Unless required by applicable law or agreed to in writing, software |
| 12 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | // See the License for the specific language governing permissions and |
| 15 | // limitations under the License. |
| 16 | |
| 17 | package localstorage |
| 18 | |
| 19 | // Localstorage is a replacement for the old 'storage' internal library. It is currently unused, but will become |
| 20 | // so as the node code gets rewritten. |
| 21 | |
| 22 | // The library is centered around the idea of a declarative filesystem tree defined as mutually recursive Go structs. |
| 23 | // This structure is then Placed onto an abstract real filesystem (eg. a local POSIX filesystem at /), and a handle |
| 24 | // to that placed filesystem is then used by the consumers of this library to refer to subsets of the tree (that now |
| 25 | // correspond to locations on a filesystem). |
| 26 | // |
| 27 | // Every member of the storage hierarchy must either be, or inherit from Directory or File. In order to be placed |
| Lorenz Brun | fa5c2fc | 2020-09-28 13:32:12 +0200 | [diff] [blame] | 28 | // correctly, Directory embedding structures must use `dir:` or `file:` tags for child Directories and files |
| Serge Bazanski | e50ec39 | 2020-06-30 21:41:39 +0200 | [diff] [blame] | 29 | // respectively. The content of the tag specifies the path part that this element will be placed at. |
| 30 | // |
| 31 | // Full placement path(available via FullPath()) format is placement implementation-specific. However, they're always |
| 32 | // strings. |
| 33 | |
| 34 | import ( |
| 35 | "sync" |
| 36 | |
| Serge Bazanski | 77cb6c5 | 2020-12-19 00:09:22 +0100 | [diff] [blame] | 37 | "git.monogon.dev/source/nexantic.git/metropolis/node/core/localstorage/declarative" |
| Serge Bazanski | e50ec39 | 2020-06-30 21:41:39 +0200 | [diff] [blame] | 38 | ) |
| 39 | |
| 40 | type Root struct { |
| 41 | declarative.Directory |
| Serge Bazanski | c2c7ad9 | 2020-07-13 17:20:09 +0200 | [diff] [blame] | 42 | // UEFI ESP partition, mounted from plaintext storage. |
| 43 | ESP ESPDirectory `dir:"esp"` |
| 44 | // Persistent Data partition, mounted from encrypted and authenticated storage. |
| 45 | Data DataDirectory `dir:"data"` |
| 46 | // FHS-standard /etc directory, containes /etc/hosts, /etc/machine-id, and other compatibility files. |
| 47 | Etc EtcDirectory `dir:"etc"` |
| 48 | // Ephemeral data, used by runtime, stored in tmpfs. Things like sockets, temporary config files, etc. |
| Serge Bazanski | cb883e2 | 2020-07-06 17:47:55 +0200 | [diff] [blame] | 49 | Ephemeral EphemeralDirectory `dir:"ephemeral"` |
| Serge Bazanski | c2c7ad9 | 2020-07-13 17:20:09 +0200 | [diff] [blame] | 50 | // FHS-standard /tmp directory, used by ioutil.TempFile. |
| 51 | Tmp TmpDirectory `dir:"tmp"` |
| Serge Bazanski | e50ec39 | 2020-06-30 21:41:39 +0200 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | type PKIDirectory struct { |
| 55 | declarative.Directory |
| 56 | CACertificate declarative.File `file:"ca.pem"` |
| 57 | Certificate declarative.File `file:"cert.pem"` |
| 58 | Key declarative.File `file:"cert-key.pem"` |
| 59 | } |
| 60 | |
| 61 | // ESPDirectory is the EFI System Partition. |
| 62 | type ESPDirectory struct { |
| 63 | declarative.Directory |
| 64 | LocalUnlock ESPLocalUnlockFile `file:"local_unlock.bin"` |
| 65 | // Enrolment is the configuration/provisioning file for this node, containing information required to begin |
| 66 | // joining the cluster. |
| 67 | Enrolment declarative.File `file:"enrolment.pb"` |
| 68 | } |
| 69 | |
| 70 | // ESPLocalUnlockFile is the localUnlock file, encrypted by the TPM of this node. After decrypting by the TPM it is used |
| 71 | // in conjunction with the globalUnlock key (retrieved from the existing cluster) to decrypt the local data partition. |
| 72 | type ESPLocalUnlockFile struct { |
| 73 | declarative.File |
| 74 | } |
| 75 | |
| 76 | // DataDirectory is an xfs partition mounted via cryptsetup/LUKS, with a key derived from {global,local}Unlock keys. |
| 77 | type DataDirectory struct { |
| 78 | declarative.Directory |
| 79 | |
| 80 | // flagLock locks canMount and mounted. |
| 81 | flagLock sync.Mutex |
| 82 | // canMount is set by Root when it is initialized. It is required to be set for mounting the data directory. |
| 83 | canMount bool |
| 84 | // mounted is set by DataDirectory when it is mounted. It ensures it's only mounted once. |
| 85 | mounted bool |
| 86 | |
| Serge Bazanski | c2c7ad9 | 2020-07-13 17:20:09 +0200 | [diff] [blame] | 87 | Containerd declarative.Directory `dir:"containerd"` |
| 88 | Etcd DataEtcdDirectory `dir:"etcd"` |
| 89 | Kubernetes DataKubernetesDirectory `dir:"kubernetes"` |
| 90 | Node PKIDirectory `dir:"node_pki"` |
| 91 | Volumes DataVolumesDirectory `dir:"volumes"` |
| Serge Bazanski | e50ec39 | 2020-06-30 21:41:39 +0200 | [diff] [blame] | 92 | } |
| 93 | |
| Serge Bazanski | cb883e2 | 2020-07-06 17:47:55 +0200 | [diff] [blame] | 94 | type DataEtcdDirectory struct { |
| 95 | declarative.Directory |
| 96 | PeerPKI PKIDirectory `dir:"peer_pki"` |
| 97 | PeerCRL declarative.File `file:"peer_crl"` |
| 98 | Data declarative.Directory `dir:"data"` |
| 99 | } |
| 100 | |
| Serge Bazanski | c2c7ad9 | 2020-07-13 17:20:09 +0200 | [diff] [blame] | 101 | type DataKubernetesDirectory struct { |
| 102 | declarative.Directory |
| 103 | ClusterNetworking DataKubernetesClusterNetworkingDirectory `dir:"clusternet"` |
| 104 | Kubelet DataKubernetesKubeletDirectory `dir:"kubelet"` |
| 105 | } |
| 106 | |
| 107 | type DataKubernetesClusterNetworkingDirectory struct { |
| 108 | declarative.Directory |
| 109 | Key declarative.File `file:"private.key"` |
| 110 | } |
| 111 | |
| 112 | type DataKubernetesKubeletDirectory struct { |
| 113 | declarative.Directory |
| 114 | Kubeconfig declarative.File `file:"kubeconfig"` |
| 115 | PKI PKIDirectory `dir:"pki"` |
| 116 | |
| 117 | Plugins struct { |
| 118 | declarative.Directory |
| Serge Bazanski | 662b5b3 | 2020-12-21 13:49:00 +0100 | [diff] [blame] | 119 | VFS declarative.File `file:"dev.monogon.metropolis.vfs.sock"` |
| Serge Bazanski | c2c7ad9 | 2020-07-13 17:20:09 +0200 | [diff] [blame] | 120 | } `dir:"plugins"` |
| 121 | |
| 122 | PluginsRegistry struct { |
| 123 | declarative.Directory |
| Serge Bazanski | 662b5b3 | 2020-12-21 13:49:00 +0100 | [diff] [blame] | 124 | VFSReg declarative.File `file:"dev.monogon.metropolis.vfs-reg.sock"` |
| Serge Bazanski | c2c7ad9 | 2020-07-13 17:20:09 +0200 | [diff] [blame] | 125 | } `dir:"plugins_registry"` |
| 126 | } |
| 127 | |
| 128 | type DataVolumesDirectory struct { |
| 129 | declarative.Directory |
| 130 | } |
| 131 | |
| Serge Bazanski | e50ec39 | 2020-06-30 21:41:39 +0200 | [diff] [blame] | 132 | type EtcDirectory struct { |
| 133 | declarative.Directory |
| 134 | Hosts declarative.File `file:"hosts"` |
| Serge Bazanski | c2c7ad9 | 2020-07-13 17:20:09 +0200 | [diff] [blame] | 135 | MachineID declarative.File `file:"machine-id"` |
| Serge Bazanski | e50ec39 | 2020-06-30 21:41:39 +0200 | [diff] [blame] | 136 | } |
| Serge Bazanski | cb883e2 | 2020-07-06 17:47:55 +0200 | [diff] [blame] | 137 | |
| 138 | type EphemeralDirectory struct { |
| 139 | declarative.Directory |
| Serge Bazanski | c2c7ad9 | 2020-07-13 17:20:09 +0200 | [diff] [blame] | 140 | Consensus EphemeralConsensusDirectory `dir:"consensus"` |
| 141 | Containerd EphemeralContainerdDirectory `dir:"containerd"` |
| 142 | FlexvolumePlugins declarative.Directory `dir:"flexvolume_plugins"` |
| Serge Bazanski | cb883e2 | 2020-07-06 17:47:55 +0200 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | type EphemeralConsensusDirectory struct { |
| 146 | declarative.Directory |
| 147 | ClientSocket declarative.File `file:"client.sock"` |
| 148 | } |
| Serge Bazanski | c2c7ad9 | 2020-07-13 17:20:09 +0200 | [diff] [blame] | 149 | |
| 150 | type EphemeralContainerdDirectory struct { |
| 151 | declarative.Directory |
| 152 | ClientSocket declarative.File `file:"client.sock"` |
| 153 | RunSCLogsFIFO declarative.File `file:"runsc-logs.fifo"` |
| 154 | Tmp declarative.Directory `dir:"tmp"` |
| 155 | RunSC declarative.Directory `dir:"runsc"` |
| 156 | IPAM declarative.Directory `dir:"ipam"` |
| 157 | } |
| 158 | |
| 159 | type TmpDirectory struct { |
| 160 | declarative.Directory |
| 161 | } |