Skip to content

Commit 7d688cc

Browse files
committed
fix: make encryption config provider default to luks2 if not set
Fixes: #7515 Rename `Kind` to `Provider` in the `v1alpha1_provider`. Signed-off-by: Artem Chernyshev <artem.chernyshev@talos-systems.com>
1 parent 80238a0 commit 7d688cc

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

internal/pkg/encryption/encryption.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const (
3737
func NewHandler(device *blockdevice.BlockDevice, partition *gpt.Partition, encryptionConfig config.Encryption, getSystemInformation helpers.SystemInformationGetter) (*Handler, error) {
3838
var provider encryption.Provider
3939

40-
switch encryptionConfig.Kind() {
40+
switch encryptionConfig.Provider() {
4141
case encryption.LUKS2:
4242
cipher, err := luks.ParseCipherKind(encryptionConfig.Cipher())
4343
if err != nil {
@@ -68,7 +68,7 @@ func NewHandler(device *blockdevice.BlockDevice, partition *gpt.Partition, encry
6868
opts...,
6969
)
7070
default:
71-
return nil, fmt.Errorf("unknown encryption kind %s", encryptionConfig.Kind())
71+
return nil, fmt.Errorf("unknown encryption kind %s", encryptionConfig.Provider())
7272
}
7373

7474
return &Handler{
@@ -116,7 +116,7 @@ func (h *Handler) Open(ctx context.Context) (string, error) {
116116
if err != nil {
117117
return "", err
118118
}
119-
} else if sb.Type() != h.encryptionConfig.Kind() {
119+
} else if sb.Type() != h.encryptionConfig.Provider() {
120120
return "", fmt.Errorf("failed to encrypt the partition %s, because it is not empty", partPath)
121121
}
122122

pkg/machinery/config/config/machine.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ type EncryptionKeyTPM interface{}
379379

380380
// Encryption defines settings for the partition encryption.
381381
type Encryption interface {
382-
Kind() string
382+
Provider() string
383383
Cipher() string
384384
KeySize() uint
385385
BlockSize() uint64

pkg/machinery/config/types/v1alpha1/v1alpha1_provider.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
specs "github.com/opencontainers/runtime-spec/specs-go"
1616
"github.com/siderolabs/crypto/x509"
1717
"github.com/siderolabs/gen/slices"
18+
"github.com/siderolabs/go-blockdevice/blockdevice/encryption"
1819
"github.com/siderolabs/go-blockdevice/blockdevice/util/disk"
1920
"github.com/siderolabs/go-pointer"
2021

@@ -1313,8 +1314,12 @@ func (p *DiskPartition) MountPoint() string {
13131314
return p.DiskMountPoint
13141315
}
13151316

1316-
// Kind implements the config.Provider interface.
1317-
func (e *EncryptionConfig) Kind() string {
1317+
// Provider implements the config.Provider interface.
1318+
func (e *EncryptionConfig) Provider() string {
1319+
if e.EncryptionProvider == "" {
1320+
return encryption.LUKS2
1321+
}
1322+
13181323
return e.EncryptionProvider
13191324
}
13201325

pkg/machinery/config/types/v1alpha1/v1alpha1_validation.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,19 +220,19 @@ func (c *Config) Validate(mode validation.RuntimeMode, options ...validation.Opt
220220
encryptionConfig := c.MachineConfig.SystemDiskEncryption().Get(label)
221221
if encryptionConfig != nil {
222222
if len(encryptionConfig.Keys()) == 0 {
223-
result = multierror.Append(result, fmt.Errorf("no encryption keys provided for the ephemeral partition encryption"))
223+
result = multierror.Append(result, fmt.Errorf("partition %q: no encryption keys provided", label))
224224
}
225225

226-
slotsInUse := map[int]bool{}
226+
slotsInUse := map[int]struct{}{}
227227
for _, key := range encryptionConfig.Keys() {
228-
if slotsInUse[key.Slot()] {
229-
result = multierror.Append(result, fmt.Errorf("encryption key slot %d is already in use", key.Slot()))
228+
if _, inUse := slotsInUse[key.Slot()]; inUse {
229+
result = multierror.Append(result, fmt.Errorf("partition %q: encryption key slot %d is already in use", label, key.Slot()))
230230
}
231231

232-
slotsInUse[key.Slot()] = true
232+
slotsInUse[key.Slot()] = struct{}{}
233233

234234
if key.NodeID() == nil && key.Static() == nil && key.KMS() == nil && key.TPM() == nil {
235-
result = multierror.Append(result, fmt.Errorf("encryption key at slot %d doesn't have any settings", key.Slot()))
235+
result = multierror.Append(result, fmt.Errorf("partition %q: encryption key at slot %d doesn't have the configuration parameters", label, key.Slot()))
236236
}
237237
}
238238
}

0 commit comments

Comments
 (0)