|
| 1 | +// Copyright 2023 CoreOS, Inc. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package luks |
| 16 | + |
| 17 | +import ( |
| 18 | + "github.com/coreos/ignition/v2/tests/register" |
| 19 | + "github.com/coreos/ignition/v2/tests/types" |
| 20 | +) |
| 21 | + |
| 22 | +func init() { |
| 23 | + register.Register(register.PositiveTest, LuksWithStaticKey()) |
| 24 | + register.Register(register.PositiveTest, LuksWithOfflineTang()) |
| 25 | + // register.Register(register.PositiveTest, LuksWithTPM()) |
| 26 | + |
| 27 | +} |
| 28 | + |
| 29 | +func LuksWithStaticKey() types.Test { |
| 30 | + name := "static.filesystem.luks.encrypt" |
| 31 | + in := types.GetBaseDisk() |
| 32 | + out := types.GetBaseDisk() |
| 33 | + mntDevices := []types.MntDevice{ |
| 34 | + { |
| 35 | + Label: "OEM", |
| 36 | + Substitution: "$DEVICE", |
| 37 | + }, |
| 38 | + } |
| 39 | + config := `{ |
| 40 | + "ignition": { "version": "$version" }, |
| 41 | + "storage": { |
| 42 | + "disks": [ |
| 43 | + { |
| 44 | + "device": "$DEVICE", |
| 45 | + "partitions": [ |
| 46 | + { |
| 47 | + "label": "luks-device", |
| 48 | + "sizeMiB": 0, |
| 49 | + "startMiB": 0 |
| 50 | + } |
| 51 | + ], |
| 52 | + "wipe_table": true |
| 53 | + } |
| 54 | + ], |
| 55 | + "luks": [ |
| 56 | + { |
| 57 | + "device": "$DEVICE", |
| 58 | + "name": "luks-$UUID", |
| 59 | + "keyFile": { |
| 60 | + "compression": "", |
| 61 | + "source": "data:,REPLACE-THIS-WITH-YOUR-KEY-MATERIAL" |
| 62 | + }, |
| 63 | + "wipe_volume": true |
| 64 | + } |
| 65 | + ] |
| 66 | + } |
| 67 | + }` |
| 68 | + configMinVersion := "3.2.0" |
| 69 | + in[0].Partitions.GetPartition("OEM").FilesystemType = "ext4" |
| 70 | + out[0].Partitions.GetPartition("OEM").FilesystemType = "crypto_LUKS" |
| 71 | + |
| 72 | + return types.Test{ |
| 73 | + Name: name, |
| 74 | + In: in, |
| 75 | + Out: out, |
| 76 | + MntDevices: mntDevices, |
| 77 | + Config: config, |
| 78 | + ConfigMinVersion: configMinVersion, |
| 79 | + } |
| 80 | +} |
| 81 | + |
| 82 | +func LuksWithTPM() types.Test { |
| 83 | + name := "tpm.filesystem.luks.encrypt" |
| 84 | + in := types.GetBaseDisk() |
| 85 | + out := types.GetBaseDisk() |
| 86 | + mntDevices := []types.MntDevice{ |
| 87 | + { |
| 88 | + Label: "OEM", |
| 89 | + Substitution: "$DEVICE", |
| 90 | + }, |
| 91 | + } |
| 92 | + config := `{ |
| 93 | + "ignition": { "version": "$version" }, |
| 94 | + "storage": { |
| 95 | + "disks": [ |
| 96 | + { |
| 97 | + "device": "$DEVICE", |
| 98 | + "partitions": [ |
| 99 | + { |
| 100 | + "label": "luks-device", |
| 101 | + "sizeMiB": 0, |
| 102 | + "startMiB": 0 |
| 103 | + } |
| 104 | + ], |
| 105 | + "wipe_table": true |
| 106 | + } |
| 107 | + ], |
| 108 | + "luks": [ |
| 109 | + { |
| 110 | + "clevis": { |
| 111 | + "tpm2": true |
| 112 | + }, |
| 113 | + "device": "$DEVICE", |
| 114 | + "name": "luks-$UUID", |
| 115 | + "wipe_volume": true |
| 116 | + } |
| 117 | + ] |
| 118 | + } |
| 119 | + }` |
| 120 | + configMinVersion := "3.2.0" |
| 121 | + in[0].Partitions.GetPartition("OEM").FilesystemType = "ext4" |
| 122 | + out[0].Partitions.GetPartition("OEM").FilesystemType = "crypto_LUKS" |
| 123 | + |
| 124 | + return types.Test{ |
| 125 | + Name: name, |
| 126 | + In: in, |
| 127 | + Out: out, |
| 128 | + MntDevices: mntDevices, |
| 129 | + Config: config, |
| 130 | + ConfigMinVersion: configMinVersion, |
| 131 | + } |
| 132 | +} |
| 133 | + |
| 134 | +func LuksWithOfflineTang() types.Test { |
| 135 | + name := "tang.filesystem.luks.encrypt" |
| 136 | + in := types.GetBaseDisk() |
| 137 | + out := types.GetBaseDisk() |
| 138 | + mntDevices := []types.MntDevice{ |
| 139 | + { |
| 140 | + Label: "OEM", |
| 141 | + Substitution: "$DEVICE", |
| 142 | + }, |
| 143 | + } |
| 144 | + config := `{ |
| 145 | + "ignition": { "version": "$version" }, |
| 146 | + "storage": { |
| 147 | + "disks": [ |
| 148 | + { |
| 149 | + "device": "$DEVICE", |
| 150 | + "partitions": [ |
| 151 | + { |
| 152 | + "label": "luks-device", |
| 153 | + "sizeMiB": 0, |
| 154 | + "startMiB": 0 |
| 155 | + } |
| 156 | + ], |
| 157 | + "wipe_table": false |
| 158 | + } |
| 159 | + ], |
| 160 | + "luks": [{ |
| 161 | + "clevis": { |
| 162 | + "tang": [{ |
| 163 | + "thumbprint": "REPLACE-THIS-WITH-YOUR-TANG-THUMBPRINT", |
| 164 | + "url": "https://tang.example.com", |
| 165 | + "advertisement": "{\"payload\": \"...\",\"protected\":\"...\",\"signature\":\"...\"}" |
| 166 | + }] |
| 167 | + }, |
| 168 | + "device": "$DEVICE", |
| 169 | + "name": "luks-$UUID", |
| 170 | + "wipe_volume": true |
| 171 | +
|
| 172 | + }] |
| 173 | + } |
| 174 | + }` |
| 175 | + configMinVersion := "3.4.0" |
| 176 | + in[0].Partitions.GetPartition("OEM").FilesystemType = "ext4" |
| 177 | + out[0].Partitions.GetPartition("OEM").FilesystemType = "crypto_LUKS" |
| 178 | + |
| 179 | + return types.Test{ |
| 180 | + Name: name, |
| 181 | + In: in, |
| 182 | + Out: out, |
| 183 | + MntDevices: mntDevices, |
| 184 | + Config: config, |
| 185 | + ConfigMinVersion: configMinVersion, |
| 186 | + } |
| 187 | +} |
0 commit comments