Skip to content

Commit

Permalink
fix(crypto): minimal encrypted volume size
Browse files Browse the repository at this point in the history
The minimal encrypted volume size should be bigger than 16MiB
because default LUKS2 header size is 16MiB.

Ref: 7033

Signed-off-by: James Lu <james.lu@suse.com>
  • Loading branch information
mantissahz authored and David Ko committed Nov 23, 2023
1 parent 23a9959 commit b8abca1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions csi/crypto/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ const (
CryptoKeyDefaultHash = "sha256"
CryptoKeyDefaultSize = "256"
CryptoDefaultPBKDF = "argon2i"

// Luks2MinimalVolumeSize the minimal volume size for the LUKS2format encryption.
// https://gitlab.com/cryptsetup/cryptsetup/-/wikis/FrequentlyAskedQuestions
// Section 10.10 What about the size of the LUKS2 header
// The default size is 16MB
Luks2MinimalVolumeSize = 16 * 1024 * 1024
)

// EncryptParams keeps the customized cipher options from the secret CR
Expand Down
6 changes: 6 additions & 0 deletions datastore/longhorn.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/longhorn/longhorn-manager/csi/crypto"
"github.com/longhorn/longhorn-manager/types"
"github.com/longhorn/longhorn-manager/util"

Expand Down Expand Up @@ -628,6 +629,11 @@ func CheckVolume(v *longhorn.Volume) error {
if v.Name == "" || size == 0 || v.Spec.NumberOfReplicas == 0 {
return fmt.Errorf("BUG: missing required field %+v", v)
}

if v.Spec.Encrypted && size <= crypto.Luks2MinimalVolumeSize {
return fmt.Errorf("invalid volume size %v, need to be bigger than 16MiB, default LUKS2 header size for encryption", v.Spec.Size)
}

errs := validation.IsDNS1123Label(v.Name)
if len(errs) != 0 {
return fmt.Errorf("invalid volume name: %+v", errs)
Expand Down

0 comments on commit b8abca1

Please sign in to comment.