From 1f9a614e08ad492775fafecd23a7de7fa610c919 Mon Sep 17 00:00:00 2001 From: Rakshith R Date: Tue, 22 Mar 2022 16:19:45 +0530 Subject: [PATCH] csi: add CSI encryption support Ceph-CSI supports LUKS encryption for RBD volumes. This commit adds support for the same by adding capability of mounting required `rook-ceph-csi-kms-config` configmap into csi-rbdplugin-provisioner and nodeplugin pods. Required documentations, helm charts and examples yamls are also updated. Resolved: #7032 Signed-off-by: Rakshith R (cherry picked from commit 2e18d5bbaab89279f8565f3853a7bc5f219b33a5) --- Documentation/ceph-csi-drivers.md | 71 +++++++++++++++++++ Documentation/helm-operator.md | 1 + .../charts/rook-ceph/templates/configmap.yaml | 1 + deploy/charts/rook-ceph/values.yaml | 2 + deploy/examples/csi/rbd/storageclass.yaml | 9 +++ deploy/examples/operator-openshift.yaml | 3 + deploy/examples/operator.yaml | 3 + pkg/operator/ceph/csi/spec.go | 5 ++ .../rbd/csi-rbdplugin-provisioner-dep.yaml | 12 ++++ .../ceph/csi/template/rbd/csi-rbdplugin.yaml | 12 ++++ 10 files changed, 119 insertions(+) diff --git a/Documentation/ceph-csi-drivers.md b/Documentation/ceph-csi-drivers.md index bb5f5be85..47ce98943 100644 --- a/Documentation/ceph-csi-drivers.md +++ b/Documentation/ceph-csi-drivers.md @@ -176,3 +176,74 @@ CSI-Addons supports the following operations: - [Annotating PersistentVolumeClaims](https://github.com/csi-addons/kubernetes-csi-addons/blob/v0.3.0/docs/reclaimspace.md#annotating-perstentvolumeclaims) - Network Fencing - [Creating a NetworkFence](https://github.com/csi-addons/kubernetes-csi-addons/blob/v0.3.0/docs/networkfence.md) + +## Enable RBD Encryption Support + +Ceph-CSI supports encrypting individual RBD PersistentVolumeClaim with LUKS encryption. More details can be found +[here](https://github.com/ceph/ceph-csi/blob/v3.6.0/docs/deploy-rbd.md#encryption-for-rbd-volumes) +with full list of supported encryption configurations. A sample configmap can be found +[here](https://github.com/ceph/ceph-csi/blob/v3.6.0/examples/kms/vault/kms-config.yaml). + +> NOTE: Rook also supports OSD encryption (see `encryptedDevice` option [here](ceph-cluster-crd.md#osd-configuration-settings)). +Using both RBD PVC encryption and OSD encryption together will lead to double encryption and may reduce read/write performance. + +Unlike OSD encryption, existing ceph clusters can also enable Ceph-CSI RBD PVC encryption support and multiple kinds of encryption +KMS can be used on the same ceph cluster using different storageclasses. + +Following steps demonstrate how to enable support for encryption: + +* Create the `rook-ceph-csi-kms-config` configmap with required encryption configuration in +the same namespace where the Rook operator is deployed. An example is shown below: + +```yaml +apiVersion: v1 +kind: ConfigMap +metadata: + name: rook-ceph-csi-kms-config + namespace: rook-ceph +data: + config.json: |- + { + "user-secret-metadata": { + "encryptionKMSType": "metadata", + "secretName": "storage-encryption-secret" + } + } +``` + +* Update the `rook-ceph-operator-config` configmap and patch the + following configurations + +```bash +kubectl patch cm rook-ceph-operator-config -nrook-ceph -p $'data:\n "CSI_ENABLE_ENCRYPTION": "true"' +``` + +* Create necessary resources (secrets, configmaps etc) as required by the encryption type. +In this case, create `storage-encryption-secret` secret in the namespace of pvc as shown: + +```yaml +apiVersion: v1 +kind: Secret +metadata: + name: storage-encryption-secret + namespace: rook-ceph +stringData: + encryptionPassphrase: test-encryption +``` + +* Create a new [storageclass](../deploy/examples/csi/rbd/storageclass.yaml) with additional parameters +`encrypted: "true"` and `encryptionKMSID: ""`. An example is show below: + +```yaml +apiVersion: storage.k8s.io/v1 +kind: StorageClass +metadata: + name: rook-ceph-block-encrypted +parameters: + # additional parameters required for encryption + encrypted: "true" + encryptionKMSID: "user-secret-metadata" +# ... +``` + +* PVCs created using the new storageclass will be encrypted. \ No newline at end of file diff --git a/Documentation/helm-operator.md b/Documentation/helm-operator.md index 5eb1c5094..869218ada 100644 --- a/Documentation/helm-operator.md +++ b/Documentation/helm-operator.md @@ -83,6 +83,7 @@ The following tables lists the configurable parameters of the rook-operator char | `csi.enableGrpcMetrics` | Enable Ceph CSI GRPC Metrics. | `false` | | `csi.enableCSIHostNetwork` | Enable Host Networking for Ceph CSI nodeplugins. | `false` | | `csi.enablePluginSelinuxHostMount` | Enable Host mount for /etc/selinux directory for Ceph CSI nodeplugins. | `false` | +| `csi.enableCSIEncryption` | Enable Ceph CSI PVC encryption support. | `false` | | `csi.provisionerTolerations` | Array of tolerations in YAML format which will be added to CSI provisioner deployment. | | | `csi.provisionerNodeAffinity` | The node labels for affinity of the CSI provisioner deployment (***) | | | `csi.pluginTolerations` | Array of tolerations in YAML format which will be added to CephCSI plugin DaemonSet | | diff --git a/deploy/charts/rook-ceph/templates/configmap.yaml b/deploy/charts/rook-ceph/templates/configmap.yaml index f5ec06fad..2c2398325 100644 --- a/deploy/charts/rook-ceph/templates/configmap.yaml +++ b/deploy/charts/rook-ceph/templates/configmap.yaml @@ -14,6 +14,7 @@ data: CSI_ENABLE_CEPHFS_SNAPSHOTTER: {{ .Values.csi.enableCephfsSnapshotter | quote }} CSI_ENABLE_RBD_SNAPSHOTTER: {{ .Values.csi.enableRBDSnapshotter | quote }} CSI_PLUGIN_ENABLE_SELINUX_HOST_MOUNT: {{ .Values.csi.enablePluginSelinuxHostMount | quote }} + CSI_ENABLE_ENCRYPTION: {{ .Values.csi.enableCSIEncryption | quote }} CSI_ENABLE_OMAP_GENERATOR: {{ .Values.csi.enableOMAPGenerator | quote }} {{- if .Values.csi.pluginPriorityClassName }} CSI_PLUGIN_PRIORITY_CLASSNAME: {{ .Values.csi.pluginPriorityClassName | quote }} diff --git a/deploy/charts/rook-ceph/values.yaml b/deploy/charts/rook-ceph/values.yaml index b28ecc0a4..a788be80d 100644 --- a/deploy/charts/rook-ceph/values.yaml +++ b/deploy/charts/rook-ceph/values.yaml @@ -70,6 +70,8 @@ csi: enableRBDSnapshotter: true # set to false if the selinux is not enabled or unavailable in cluster nodes. enablePluginSelinuxHostMount : false + # set to true to enable Ceph CSI pvc encryption support. + enableCSIEncryption: false # (Optional) set user created priorityclassName for csi plugin pods. # pluginPriorityClassName: system-node-critical diff --git a/deploy/examples/csi/rbd/storageclass.yaml b/deploy/examples/csi/rbd/storageclass.yaml index 0e926b70f..f0002c4c8 100644 --- a/deploy/examples/csi/rbd/storageclass.yaml +++ b/deploy/examples/csi/rbd/storageclass.yaml @@ -47,6 +47,15 @@ parameters: # https://docs.ceph.com/docs/master/man/8/rbd-nbd/#options # unmapOptions: force + # (optional) Set it to true to encrypt each volume with encryption keys + # from a key management system (KMS) + # encrypted: "true" + + # (optional) Use external key management system (KMS) for encryption key by + # specifying a unique ID matching a KMS ConfigMap. The ID is only used for + # correlation to configmap entry. + # encryptionKMSID: + # RBD image format. Defaults to "2". imageFormat: "2" diff --git a/deploy/examples/operator-openshift.yaml b/deploy/examples/operator-openshift.yaml index ad0a83a80..d2871f890 100644 --- a/deploy/examples/operator-openshift.yaml +++ b/deploy/examples/operator-openshift.yaml @@ -119,6 +119,9 @@ data: ROOK_CSI_ENABLE_NFS: "false" ROOK_CSI_ENABLE_GRPC_METRICS: "false" + # Set to true to enable Ceph CSI pvc encryption support. + CSI_ENABLE_ENCRYPTION: "false" + # Set to true to enable host networking for CSI CephFS and RBD nodeplugins. This may be necessary # in some network configurations where the SDN does not provide access to an external cluster or # there is significant drop in read/write performance. diff --git a/deploy/examples/operator.yaml b/deploy/examples/operator.yaml index 966c0948d..169f0b8ad 100644 --- a/deploy/examples/operator.yaml +++ b/deploy/examples/operator.yaml @@ -34,6 +34,9 @@ data: ROOK_CSI_ENABLE_NFS: "false" ROOK_CSI_ENABLE_GRPC_METRICS: "false" + # Set to true to enable Ceph CSI pvc encryption support. + CSI_ENABLE_ENCRYPTION: "false" + # Set to true to enable host networking for CSI CephFS and RBD nodeplugins. This may be necessary # in some network configurations where the SDN does not provide access to an external cluster or # there is significant drop in read/write performance. diff --git a/pkg/operator/ceph/csi/spec.go b/pkg/operator/ceph/csi/spec.go index 6511a02be..c4375ca7b 100644 --- a/pkg/operator/ceph/csi/spec.go +++ b/pkg/operator/ceph/csi/spec.go @@ -63,6 +63,7 @@ type Param struct { EnableCSIAddonsSideCar bool MountCustomCephConf bool EnableOIDCTokenProjection bool + EnableCSIEncryption bool LogLevel uint8 CephFSGRPCMetricsPort uint16 CephFSLivenessMetricsPort uint16 @@ -349,6 +350,10 @@ func (r *ReconcileCSI) startDrivers(ver *version.Info, ownerInfo *k8sutil.OwnerI tp.EnableCSIAddonsSideCar = true } + if strings.EqualFold(k8sutil.GetValue(r.opConfig.Parameters, "CSI_ENABLE_ENCRYPTION", "false"), "true") { + tp.EnableCSIEncryption = true + } + if strings.EqualFold(k8sutil.GetValue(r.opConfig.Parameters, "CSI_CEPHFS_PLUGIN_UPDATE_STRATEGY", rollingUpdate), onDelete) { tp.CephFSPluginUpdateStrategy = onDelete } else { diff --git a/pkg/operator/ceph/csi/template/rbd/csi-rbdplugin-provisioner-dep.yaml b/pkg/operator/ceph/csi/template/rbd/csi-rbdplugin-provisioner-dep.yaml index f0432742e..f45491590 100644 --- a/pkg/operator/ceph/csi/template/rbd/csi-rbdplugin-provisioner-dep.yaml +++ b/pkg/operator/ceph/csi/template/rbd/csi-rbdplugin-provisioner-dep.yaml @@ -230,6 +230,10 @@ spec: mountPath: /run/secrets/tokens readOnly: true {{ end }} + {{ if .EnableCSIEncryption }} + - name: rook-ceph-csi-kms-config + mountPath: /etc/ceph-csi-encryption-kms-config/ + {{ end }} - name: liveness-prometheus image: {{ .CSIPluginImage }} args: @@ -300,3 +304,11 @@ spec: expirationSeconds: 3600 audience: ceph-csi-kms {{ end }} + {{ if .EnableCSIEncryption }} + - name: rook-ceph-csi-kms-config + configMap: + name: rook-ceph-csi-kms-config + items: + - key: config.json + path: config.json + {{ end }} diff --git a/pkg/operator/ceph/csi/template/rbd/csi-rbdplugin.yaml b/pkg/operator/ceph/csi/template/rbd/csi-rbdplugin.yaml index eb3ec2f5c..0f54d487b 100644 --- a/pkg/operator/ceph/csi/template/rbd/csi-rbdplugin.yaml +++ b/pkg/operator/ceph/csi/template/rbd/csi-rbdplugin.yaml @@ -128,6 +128,10 @@ spec: mountPath: /run/secrets/tokens readOnly: true {{ end }} + {{ if .EnableCSIEncryption }} + - name: rook-ceph-csi-kms-config + mountPath: /etc/ceph-csi-encryption-kms-config/ + {{ end }} {{ if .EnableCSIAddonsSideCar }} - name: csi-addons securityContext: @@ -265,3 +269,11 @@ spec: expirationSeconds: 3600 audience: ceph-csi-kms {{ end }} + {{ if .EnableCSIEncryption }} + - name: rook-ceph-csi-kms-config + configMap: + name: rook-ceph-csi-kms-config + items: + - key: config.json + path: config.json + {{ end }}