Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

controllers: Add logic to Create cephfs encrypted storageclass #2605

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion api/v1/storagecluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,18 +456,33 @@ type EncryptionSpec struct {
Enable bool `json:"enable,omitempty"`
// +optional
ClusterWide bool `json:"clusterWide,omitempty"`
// Configure the RBD encrypted storage class
// +optional
StorageClass bool `json:"storageClass,omitempty"`
// StorageClassName specifies the name of the storage class created for ceph encrypted block pools
// +kubebuilder:validation:MaxLength=253
// +kubebuilder:validation:Pattern=^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
StorageClassName string `json:"storageClassName,omitempty"`
StorageClassName string `json:"storageClassName,omitempty"`
// Configure the CephFS encrypted storage class
// +optional
CephFS StorageClassSpec `json:"cephFS,omitempty"`
KeyManagementService KeyManagementServiceSpec `json:"kms,omitempty"`
// KeyRotation defines options for Key Rotation.
// +optional
KeyRotation KeyRotationSpec `json:"keyRotation,omitempty"`
}

type StorageClassSpec struct {
// Create storage class
// +optional
StorageClass bool `json:"storageClass,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this to be pointer to bool or just bool

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

anything can be fine, I kept it as bool to align with the old flag.

// StorageClassName specifies the name of the storage class
// +optional
// +kubebuilder:validation:MaxLength=253
// +kubebuilder:validation:Pattern=^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
StorageClassName string `json:"storageClassName,omitempty"`
}

// KeyRotationSpec represents the settings for Key Rotation.
type KeyRotationSpec struct {
// Enable represents whether the key rotation is enabled.
Expand Down
16 changes: 16 additions & 0 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions config/crd/bases/ocs.openshift.io_storageclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,19 @@ spec:
description: EncryptionSpec defines if encryption should be enabled
for the Storage Cluster It is optional and defaults to false.
properties:
cephFS:
description: Configure the CephFS encrypted storage class
properties:
storageClass:
description: Create storage class
type: boolean
storageClassName:
description: StorageClassName specifies the name of the storage
class
maxLength: 253
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
type: string
type: object
clusterWide:
type: boolean
enable:
Expand Down Expand Up @@ -595,6 +608,7 @@ spec:
type: boolean
type: object
storageClass:
description: Configure the RBD encrypted storage class
type: boolean
storageClassName:
description: StorageClassName specifies the name of the storage
Expand Down
7 changes: 7 additions & 0 deletions controllers/storagecluster/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ func generateNameForEncryptedCephBlockPoolSC(initData *ocsv1.StorageCluster) str
return fmt.Sprintf("%s-ceph-rbd-encrypted", initData.Name)
}

func generateNameForEncryptedCephFileSystemSC(initData *ocsv1.StorageCluster) string {
if initData.Spec.Encryption.CephFS.StorageClassName != "" {
return initData.Spec.Encryption.CephFS.StorageClassName
}
return fmt.Sprintf("%s-cephfs-encrypted", initData.Name)
}

func generateNameForCephNetworkFilesystemSC(initData *ocsv1.StorageCluster) string {
if initData.Spec.NFS.StorageClassName != "" {
return initData.Spec.NFS.StorageClassName
Expand Down
8 changes: 7 additions & 1 deletion controllers/storagecluster/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -849,10 +849,16 @@ func validateCustomStorageClassNames(sc *ocsv1.StorageCluster) error {
}
if sc.Spec.Encryption.StorageClass && sc.Spec.Encryption.KeyManagementService.Enable && sc.Spec.Encryption.StorageClassName != "" {
if _, ok := scMap[sc.Spec.Encryption.StorageClassName]; ok {
duplicateNames = append(duplicateNames, "Encryption")
duplicateNames = append(duplicateNames, "RBD-Encryption")
}
scMap[sc.Spec.Encryption.StorageClassName] = true
}
if sc.Spec.Encryption.CephFS.StorageClass && sc.Spec.Encryption.KeyManagementService.Enable && sc.Spec.Encryption.CephFS.StorageClassName != "" {
if _, ok := scMap[sc.Spec.Encryption.CephFS.StorageClassName]; ok {
duplicateNames = append(duplicateNames, "CephFS-Encryption")
}
scMap[sc.Spec.Encryption.CephFS.StorageClassName] = true
}

if len(duplicateNames) > 0 {
return fmt.Errorf("Duplicate StorageClass name(s) provided: %v", duplicateNames)
Expand Down
29 changes: 25 additions & 4 deletions controllers/storagecluster/storageclasses.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,18 @@ func newEncryptedCephBlockPoolStorageClassConfiguration(initData *ocsv1.StorageC
return encryptedStorageClassConfig
}

// newEncryptedCephFileSystemStorageClassConfiguration generates configuration options for an encrypted Ceph File System StorageClass.
// when user has asked for PV encryption during deployment.
func newEncryptedCephFileSystemStorageClassConfiguration(initData *ocsv1.StorageCluster, serviceName string) StorageClassConfiguration {
allowVolumeExpansion := true
encryptedStorageClassConfig := newCephFilesystemStorageClassConfiguration(initData)
encryptedStorageClassConfig.storageClass.ObjectMeta.Name = generateNameForEncryptedCephFileSystemSC(initData)
encryptedStorageClassConfig.storageClass.Parameters["encrypted"] = "true"
encryptedStorageClassConfig.storageClass.Parameters["encryptionKMSID"] = serviceName
encryptedStorageClassConfig.storageClass.AllowVolumeExpansion = &allowVolumeExpansion
return encryptedStorageClassConfig
}

// newCephOBCStorageClassConfiguration generates configuration options for a Ceph Object Store StorageClass.
func newCephOBCStorageClassConfiguration(initData *ocsv1.StorageCluster) StorageClassConfiguration {
reclaimPolicy := corev1.PersistentVolumeReclaimDelete
Expand Down Expand Up @@ -475,13 +487,22 @@ func (r *StorageClusterReconciler) newStorageClassConfigurations(initData *ocsv1
if initData.Spec.ExternalStorage.Enable || !skip {
ret = append(ret, newCephOBCStorageClassConfiguration(initData))
}
// encrypted Ceph Block Pool storageclass will be returned only if
// storage-class encryption + kms is enabled and KMS ConfigMap is available
if initData.Spec.Encryption.StorageClass && initData.Spec.Encryption.KeyManagementService.Enable {

if initData.Spec.Encryption.KeyManagementService.Enable {
kmsConfig, err := getKMSConfigMap(KMSConfigMapName, initData, r.Client)

if err == nil && kmsConfig != nil {
serviceName := kmsConfig.Data["KMS_SERVICE_NAME"]
ret = append(ret, newEncryptedCephBlockPoolStorageClassConfiguration(initData, serviceName))
// encrypted Ceph Block Pool storageclass will be returned only if
// storage-class encryption + kms is enabled and KMS ConfigMap is available
if initData.Spec.Encryption.StorageClass {
ret = append(ret, newEncryptedCephBlockPoolStorageClassConfiguration(initData, serviceName))
}
// encrypted Ceph File System storageclass will be returned only if
// storage-class encryption + kms is enabled and KMS ConfigMap is available
if initData.Spec.Encryption.CephFS.StorageClass {
ret = append(ret, newEncryptedCephFileSystemStorageClassConfiguration(initData, serviceName))
}
} else {
r.Log.Error(err, "Error while getting ConfigMap.", "ConfigMap", klog.KRef(initData.Namespace, KMSConfigMapName))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,19 @@ spec:
description: EncryptionSpec defines if encryption should be enabled
for the Storage Cluster It is optional and defaults to false.
properties:
cephFS:
description: Configure the CephFS encrypted storage class
properties:
storageClass:
description: Create storage class
type: boolean
storageClassName:
description: StorageClassName specifies the name of the storage
class
maxLength: 253
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
type: string
type: object
clusterWide:
type: boolean
enable:
Expand Down Expand Up @@ -595,6 +608,7 @@ spec:
type: boolean
type: object
storageClass:
description: Configure the RBD encrypted storage class
type: boolean
storageClassName:
description: StorageClassName specifies the name of the storage
Expand Down
14 changes: 14 additions & 0 deletions deploy/ocs-operator/manifests/storagecluster.crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,19 @@ spec:
description: EncryptionSpec defines if encryption should be enabled
for the Storage Cluster It is optional and defaults to false.
properties:
cephFS:
description: Configure the CephFS encrypted storage class
properties:
storageClass:
description: Create storage class
type: boolean
storageClassName:
description: StorageClassName specifies the name of the storage
class
maxLength: 253
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
type: string
type: object
clusterWide:
type: boolean
enable:
Expand Down Expand Up @@ -594,6 +607,7 @@ spec:
type: boolean
type: object
storageClass:
description: Configure the RBD encrypted storage class
type: boolean
storageClassName:
description: StorageClassName specifies the name of the storage
Expand Down
6 changes: 4 additions & 2 deletions functests/ocs/cluster_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ func ClusterUpgradeTest() {
"CephFilesystems": "custom-cephfs-sc",
"CephNonResilientPools": "custom-ceph-non-resilient-rbd-sc",
"NFS": "custom-ceph-nfs-sc",
"Encryption": "custom-ceph-rbd-encrypted-sc",
"EncryptedRBD": "custom-ceph-rbd-encrypted-sc",
"EncryptedCephFS": "custom-cephfs-encrypted-sc",
}
err = deployManager.AddCustomStorageClassName(customSCName)
gomega.Expect(err).To(gomega.BeNil())
Expand All @@ -102,7 +103,8 @@ func ClusterUpgradeTest() {
"CephFilesystems": "custom-cephfs-new-sc",
"CephNonResilientPools": "custom-ceph-non-resilient-rbd-new-sc",
"NFS": "custom-ceph-nfs-new-sc",
"Encryption": "custom-ceph-rbd-encrypted-new-sc",
"EncryptionRBD": "custom-ceph-rbd-encrypted-new-sc",
"EncryptionCephFS": "custom-cephfs-encrypted-sc",
}
err = deployManager.AddCustomStorageClassName(customSCNameNew)
gomega.Expect(err).To(gomega.BeNil())
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions pkg/deploy-manager/storagecluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,9 +473,11 @@ func (t *DeployManager) AddCustomStorageClassName(customSCNames map[string]strin
}

if sc.Spec.Encryption.StorageClass && sc.Spec.Encryption.KeyManagementService.Enable {
sc.Spec.Encryption = ocsv1.EncryptionSpec{
StorageClassName: customSCNames["Encryption"],
}
sc.Spec.Encryption.StorageClassName = customSCNames["EncryptedRBD"]
}

if sc.Spec.Encryption.CephFS.StorageClass && sc.Spec.Encryption.KeyManagementService.Enable {
sc.Spec.Encryption.CephFS.StorageClassName = customSCNames["EncryptedCephFS"]
}

err = t.Client.Update(context.TODO(), sc)
Expand Down Expand Up @@ -510,6 +512,9 @@ func (t *DeployManager) VerifyStorageClassesExist(oldSC map[string]bool) (bool,
if sc.Spec.Encryption.StorageClassName != "" {
expectedSC[sc.Spec.Encryption.StorageClassName] = true
}
if sc.Spec.Encryption.CephFS.StorageClassName != "" {
expectedSC[sc.Spec.Encryption.CephFS.StorageClassName] = true
}

for name := range expectedSC {
if !currentSC[name] {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading