|
| 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, LuksWithKeyfileKey()) |
| 24 | + register.Register(register.PositiveTest, LuksWithTPM2()) |
| 25 | + |
| 26 | +} |
| 27 | + |
| 28 | +func LuksWithKeyfileKey() types.Test { |
| 29 | + name := "luks.formattedDevice.wipeVolume.keyfile" |
| 30 | + in := types.GetBaseDisk() |
| 31 | + out := types.GetBaseDisk() |
| 32 | + mntDevices := []types.MntDevice{ |
| 33 | + { |
| 34 | + Label: "OEM", |
| 35 | + Substitution: "$DEVICE", |
| 36 | + }, |
| 37 | + } |
| 38 | + config := `{ |
| 39 | + "ignition": { "version": "$version" }, |
| 40 | + "storage": { |
| 41 | + "luks": [ |
| 42 | + { |
| 43 | + "device": "$DEVICE", |
| 44 | + "name": "$uuid1", |
| 45 | + "keyFile": { |
| 46 | + "compression": "", |
| 47 | + "source": "data:,REPLACE-THIS-WITH-YOUR-KEY-MATERIAL" |
| 48 | + }, |
| 49 | + "wipeVolume": true |
| 50 | + } |
| 51 | + ] |
| 52 | + } |
| 53 | + }` |
| 54 | + configMinVersion := "3.2.0" |
| 55 | + in[0].Partitions.GetPartition("OEM").FilesystemType = "ext4" |
| 56 | + out[0].Partitions.GetPartition("OEM").FilesystemType = "crypto_LUKS" |
| 57 | + |
| 58 | + return types.Test{ |
| 59 | + Name: name, |
| 60 | + In: in, |
| 61 | + Out: out, |
| 62 | + MntDevices: mntDevices, |
| 63 | + Config: config, |
| 64 | + ConfigMinVersion: configMinVersion, |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +func LuksWithTPM2() types.Test { |
| 69 | + name := "luks.formattedDevice.wipeVolume.tpm2" |
| 70 | + in := types.GetBaseDisk() |
| 71 | + out := types.GetBaseDisk() |
| 72 | + mntDevices := []types.MntDevice{ |
| 73 | + { |
| 74 | + Label: "OEM", |
| 75 | + Substitution: "$DEVICE", |
| 76 | + }, |
| 77 | + } |
| 78 | + config := `{ |
| 79 | + "ignition": { "version": "$version" }, |
| 80 | + "storage": { |
| 81 | + "luks": [ |
| 82 | + { |
| 83 | + "clevis": { |
| 84 | + "tpm2": true |
| 85 | + }, |
| 86 | + "device": "$DEVICE", |
| 87 | + "name": "$uuid1", |
| 88 | + "wipeVolume": true |
| 89 | + } |
| 90 | + ] |
| 91 | + } |
| 92 | + }` |
| 93 | + configMinVersion := "3.2.0" |
| 94 | + in[0].Partitions.GetPartition("OEM").FilesystemType = "ext4" |
| 95 | + out[0].Partitions.GetPartition("OEM").FilesystemType = "crypto_LUKS" |
| 96 | + |
| 97 | + return types.Test{ |
| 98 | + Name: name, |
| 99 | + In: in, |
| 100 | + Out: out, |
| 101 | + MntDevices: mntDevices, |
| 102 | + Config: config, |
| 103 | + ConfigMinVersion: configMinVersion, |
| 104 | + } |
| 105 | +} |
0 commit comments