Skip to content

Commit 0752a7d

Browse files
committed
tests/*/luks: add blackbox tests for luks
Fixes #1554
1 parent a470385 commit 0752a7d

File tree

3 files changed

+191
-0
lines changed

3 files changed

+191
-0
lines changed

tests/negative/luks/creation.go

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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.NegativeTest, LuksOnNonExtDevice())
24+
}
25+
26+
func LuksOnNonExtDevice() types.Test {
27+
name := "tang.filesystem.luks.encrypt"
28+
in := types.GetBaseDisk()
29+
out := types.GetBaseDisk()
30+
mntDevices := []types.MntDevice{
31+
{
32+
Label: "EFI-SYSTEM",
33+
Substitution: "$DEVICE",
34+
},
35+
}
36+
config := `{
37+
"ignition": { "version": "$version" },
38+
"storage": {
39+
"luks": [
40+
{
41+
"device": "$DEVICE",
42+
"name": "$UUID",
43+
"wipe_volume": true
44+
}
45+
]
46+
}
47+
}`
48+
configMinVersion := "3.2.0"
49+
50+
return types.Test{
51+
Name: name,
52+
In: in,
53+
Out: out,
54+
MntDevices: mntDevices,
55+
Config: config,
56+
ConfigMinVersion: configMinVersion,
57+
}
58+
}

tests/positive/luks/creation.go

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
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, LuksWithTPM())
25+
26+
}
27+
28+
func LuksWithStaticKey() types.Test {
29+
name := "static.filesystem.luks.encrypt"
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+
"disks": [
42+
{
43+
"device": "$DEVICE",
44+
"partitions": [
45+
{
46+
"label": "luks-device",
47+
"sizeMiB": 0,
48+
"startMiB": 0
49+
}
50+
],
51+
"wipe_table": true
52+
}
53+
],
54+
"luks": [
55+
{
56+
"device": "$DEVICE",
57+
"name": "$UUID",
58+
"keyFile": {
59+
"compression": "",
60+
"source": "data:,REPLACE-THIS-WITH-YOUR-KEY-MATERIAL"
61+
},
62+
"wipe_volume": true
63+
}
64+
]
65+
}
66+
}`
67+
configMinVersion := "3.2.0"
68+
in[0].Partitions.GetPartition("OEM").FilesystemType = "ext4"
69+
out[0].Partitions.GetPartition("OEM").FilesystemType = "crypto_LUKS"
70+
71+
return types.Test{
72+
Name: name,
73+
In: in,
74+
Out: out,
75+
MntDevices: mntDevices,
76+
Config: config,
77+
ConfigMinVersion: configMinVersion,
78+
}
79+
}
80+
81+
func LuksWithTPM() types.Test {
82+
name := "tpm.filesystem.luks.encrypt"
83+
in := types.GetBaseDisk()
84+
out := types.GetBaseDisk()
85+
mntDevices := []types.MntDevice{
86+
{
87+
Label: "OEM",
88+
Substitution: "$DEVICE",
89+
},
90+
}
91+
config := `{
92+
"ignition": { "version": "$version" },
93+
"storage": {
94+
"disks": [
95+
{
96+
"device": "$DEVICE",
97+
"partitions": [
98+
{
99+
"label": "luks-device",
100+
"sizeMiB": 0,
101+
"startMiB": 0
102+
}
103+
],
104+
"wipe_table": true
105+
}
106+
],
107+
"luks": [
108+
{
109+
"clevis": {
110+
"tpm2": true
111+
},
112+
"device": "$DEVICE",
113+
"name": "$UUID",
114+
"wipe_volume": true
115+
}
116+
]
117+
}
118+
}`
119+
configMinVersion := "3.2.0"
120+
in[0].Partitions.GetPartition("OEM").FilesystemType = "ext4"
121+
out[0].Partitions.GetPartition("OEM").FilesystemType = "crypto_LUKS"
122+
123+
return types.Test{
124+
Name: name,
125+
In: in,
126+
Out: out,
127+
MntDevices: mntDevices,
128+
Config: config,
129+
ConfigMinVersion: configMinVersion,
130+
}
131+
}

tests/registry/registry.go

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
_ "github.com/coreos/ignition/v2/tests/negative/files"
2020
_ "github.com/coreos/ignition/v2/tests/negative/filesystems"
2121
_ "github.com/coreos/ignition/v2/tests/negative/general"
22+
_ "github.com/coreos/ignition/v2/tests/negative/luks"
2223
_ "github.com/coreos/ignition/v2/tests/negative/partitions"
2324
_ "github.com/coreos/ignition/v2/tests/negative/proxy"
2425
_ "github.com/coreos/ignition/v2/tests/negative/regression"
@@ -27,6 +28,7 @@ import (
2728
_ "github.com/coreos/ignition/v2/tests/positive/files"
2829
_ "github.com/coreos/ignition/v2/tests/positive/filesystems"
2930
_ "github.com/coreos/ignition/v2/tests/positive/general"
31+
_ "github.com/coreos/ignition/v2/tests/positive/luks"
3032
_ "github.com/coreos/ignition/v2/tests/positive/partitions"
3133
_ "github.com/coreos/ignition/v2/tests/positive/passwd"
3234
_ "github.com/coreos/ignition/v2/tests/positive/proxy"

0 commit comments

Comments
 (0)