Skip to content

Commit

Permalink
tests/*/luks: add blackbox tests for luks
Browse files Browse the repository at this point in the history
Fixes #1554
  • Loading branch information
prestist committed Jun 13, 2024
1 parent 334361d commit 6278609
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 0 deletions.
59 changes: 59 additions & 0 deletions tests/negative/luks/creation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright 2023 CoreOS, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package luks

import (
"github.com/coreos/ignition/v2/tests/register"
"github.com/coreos/ignition/v2/tests/types"
)

func init() {
register.Register(register.NegativeTest, LuksFailToEncryptFormatedDevice())
}

// Fail to encrypt a device which is formatted without "WipeVolume"
func LuksFailToEncryptFormatedDevice() types.Test {
name := "luks.formatedDevice.noWipeVolume"
in := types.GetBaseDisk()
out := types.GetBaseDisk()
mntDevices := []types.MntDevice{
{
Label: "OEM",
Substitution: "$DEVICE",
},
}
config := `{
"ignition": { "version": "$version" },
"storage": {
"luks": [
{
"device": "$DEVICE",
"name": "$uuid1",
"wipeVolume": false
}
]
}
}`
configMinVersion := "3.2.0"

return types.Test{
Name: name,
In: in,
Out: out,
MntDevices: mntDevices,
Config: config,
ConfigMinVersion: configMinVersion,
}
}
105 changes: 105 additions & 0 deletions tests/positive/luks/creation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// Copyright 2023 CoreOS, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package luks

import (
"github.com/coreos/ignition/v2/tests/register"
"github.com/coreos/ignition/v2/tests/types"
)

func init() {
register.Register(register.PositiveTest, LuksWithKeyfileKey())
register.Register(register.PositiveTest, LuksWithTPM2())

}

func LuksWithKeyfileKey() types.Test {
name := "luks.formattedDevice.wipeVolume.keyfile"
in := types.GetBaseDisk()
out := types.GetBaseDisk()
mntDevices := []types.MntDevice{
{
Label: "OEM",
Substitution: "$DEVICE",
},
}
config := `{
"ignition": { "version": "$version" },
"storage": {
"luks": [
{
"device": "$DEVICE",
"name": "$uuid1",
"keyFile": {
"compression": "",
"source": "data:,REPLACE-THIS-WITH-YOUR-KEY-MATERIAL"
},
"wipeVolume": true
}
]
}
}`
configMinVersion := "3.2.0"
in[0].Partitions.GetPartition("OEM").FilesystemType = "ext4"
out[0].Partitions.GetPartition("OEM").FilesystemType = "crypto_LUKS"

return types.Test{
Name: name,
In: in,
Out: out,
MntDevices: mntDevices,
Config: config,
ConfigMinVersion: configMinVersion,
}
}

func LuksWithTPM2() types.Test {
name := "luks.formattedDevice.wipeVolume.tpm2"
in := types.GetBaseDisk()
out := types.GetBaseDisk()
mntDevices := []types.MntDevice{
{
Label: "OEM",
Substitution: "$DEVICE",
},
}
config := `{
"ignition": { "version": "$version" },
"storage": {
"luks": [
{
"clevis": {
"tpm2": true
},
"device": "$DEVICE",
"name": "$uuid1",
"wipeVolume": true
}
]
}
}`
configMinVersion := "3.2.0"
in[0].Partitions.GetPartition("OEM").FilesystemType = "ext4"
out[0].Partitions.GetPartition("OEM").FilesystemType = "crypto_LUKS"

return types.Test{
Name: name,
In: in,
Out: out,
MntDevices: mntDevices,
Config: config,
ConfigMinVersion: configMinVersion,
}
}
2 changes: 2 additions & 0 deletions tests/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
_ "github.com/coreos/ignition/v2/tests/negative/files"
_ "github.com/coreos/ignition/v2/tests/negative/filesystems"
_ "github.com/coreos/ignition/v2/tests/negative/general"
_ "github.com/coreos/ignition/v2/tests/negative/luks"
_ "github.com/coreos/ignition/v2/tests/negative/partitions"
_ "github.com/coreos/ignition/v2/tests/negative/proxy"
_ "github.com/coreos/ignition/v2/tests/negative/regression"
Expand All @@ -27,6 +28,7 @@ import (
_ "github.com/coreos/ignition/v2/tests/positive/files"
_ "github.com/coreos/ignition/v2/tests/positive/filesystems"
_ "github.com/coreos/ignition/v2/tests/positive/general"
_ "github.com/coreos/ignition/v2/tests/positive/luks"
_ "github.com/coreos/ignition/v2/tests/positive/partitions"
_ "github.com/coreos/ignition/v2/tests/positive/passwd"
_ "github.com/coreos/ignition/v2/tests/positive/proxy"
Expand Down

0 comments on commit 6278609

Please sign in to comment.