blob: 1b1946a19dcfe4507a6d7217883faf94c27752f9 [file] [log] [blame]
Serge Bazanskie50ec392020-06-30 21:41:39 +02001// 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
17package 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 Brunfa5c2fc2020-09-28 13:32:12 +020028// correctly, Directory embedding structures must use `dir:` or `file:` tags for child Directories and files
Serge Bazanskie50ec392020-06-30 21:41:39 +020029// 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
34import (
35 "sync"
36
Serge Bazanski77cb6c52020-12-19 00:09:22 +010037 "git.monogon.dev/source/nexantic.git/metropolis/node/core/localstorage/declarative"
Serge Bazanskie50ec392020-06-30 21:41:39 +020038)
39
40type Root struct {
41 declarative.Directory
Serge Bazanskic2c7ad92020-07-13 17:20:09 +020042 // 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 Bazanskicb883e22020-07-06 17:47:55 +020049 Ephemeral EphemeralDirectory `dir:"ephemeral"`
Serge Bazanskic2c7ad92020-07-13 17:20:09 +020050 // FHS-standard /tmp directory, used by ioutil.TempFile.
51 Tmp TmpDirectory `dir:"tmp"`
Serge Bazanskie50ec392020-06-30 21:41:39 +020052}
53
54type 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.
62type 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.
72type 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.
77type 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 Bazanskic2c7ad92020-07-13 17:20:09 +020087 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 Bazanskie50ec392020-06-30 21:41:39 +020092}
93
Serge Bazanskicb883e22020-07-06 17:47:55 +020094type 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 Bazanskic2c7ad92020-07-13 17:20:09 +0200101type DataKubernetesDirectory struct {
102 declarative.Directory
103 ClusterNetworking DataKubernetesClusterNetworkingDirectory `dir:"clusternet"`
104 Kubelet DataKubernetesKubeletDirectory `dir:"kubelet"`
105}
106
107type DataKubernetesClusterNetworkingDirectory struct {
108 declarative.Directory
109 Key declarative.File `file:"private.key"`
110}
111
112type DataKubernetesKubeletDirectory struct {
113 declarative.Directory
114 Kubeconfig declarative.File `file:"kubeconfig"`
115 PKI PKIDirectory `dir:"pki"`
116
117 Plugins struct {
118 declarative.Directory
Serge Bazanski662b5b32020-12-21 13:49:00 +0100119 VFS declarative.File `file:"dev.monogon.metropolis.vfs.sock"`
Serge Bazanskic2c7ad92020-07-13 17:20:09 +0200120 } `dir:"plugins"`
121
122 PluginsRegistry struct {
123 declarative.Directory
Serge Bazanski662b5b32020-12-21 13:49:00 +0100124 VFSReg declarative.File `file:"dev.monogon.metropolis.vfs-reg.sock"`
Serge Bazanskic2c7ad92020-07-13 17:20:09 +0200125 } `dir:"plugins_registry"`
126}
127
128type DataVolumesDirectory struct {
129 declarative.Directory
130}
131
Serge Bazanskie50ec392020-06-30 21:41:39 +0200132type EtcDirectory struct {
133 declarative.Directory
134 Hosts declarative.File `file:"hosts"`
Serge Bazanskic2c7ad92020-07-13 17:20:09 +0200135 MachineID declarative.File `file:"machine-id"`
Serge Bazanskie50ec392020-06-30 21:41:39 +0200136}
Serge Bazanskicb883e22020-07-06 17:47:55 +0200137
138type EphemeralDirectory struct {
139 declarative.Directory
Serge Bazanskic2c7ad92020-07-13 17:20:09 +0200140 Consensus EphemeralConsensusDirectory `dir:"consensus"`
141 Containerd EphemeralContainerdDirectory `dir:"containerd"`
142 FlexvolumePlugins declarative.Directory `dir:"flexvolume_plugins"`
Serge Bazanskicb883e22020-07-06 17:47:55 +0200143}
144
145type EphemeralConsensusDirectory struct {
146 declarative.Directory
147 ClientSocket declarative.File `file:"client.sock"`
148}
Serge Bazanskic2c7ad92020-07-13 17:20:09 +0200149
150type 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
159type TmpDirectory struct {
160 declarative.Directory
161}