2020-01-29 11:44:45 +00:00
|
|
|
# Encrypted Persistent Volume Claims
|
|
|
|
|
|
|
|
## Proposal
|
|
|
|
|
|
|
|
Subject of this proposal is to add support for encryption of RBD volumes in
|
2020-10-09 05:44:09 +00:00
|
|
|
Ceph-CSI with type LUKS version 2.
|
2020-01-29 11:44:45 +00:00
|
|
|
|
|
|
|
Some but not all the benefits of this approach:
|
|
|
|
|
|
|
|
* guarantee encryption in transit to rbd without using messenger v2
|
|
|
|
* extra security layer to application with special regulatory needs
|
|
|
|
* at rest encryption can be disabled to selectively allow encryption only where
|
|
|
|
required
|
|
|
|
|
|
|
|
## Document Terminology
|
|
|
|
|
|
|
|
* volume encryption: encryption of a volume attached by rbd
|
|
|
|
* encryption at rest: encryption of physical disk done by ceph
|
2021-12-20 09:21:47 +00:00
|
|
|
* LUKS: Linux Unified Key Setup: stores all the needed setup information for
|
2020-01-29 11:44:45 +00:00
|
|
|
dm-crypt on the disk
|
|
|
|
* dm-crypt: linux kernel device-mapper crypto target
|
|
|
|
* cryptsetup: the command line tool to interface with dm-crypt
|
|
|
|
|
|
|
|
## Proposed Solution
|
|
|
|
|
|
|
|
The proposed solution in this document, is to address the volume encryption
|
|
|
|
requirement by using dm-crypt module through cryptsetup cli interface.
|
|
|
|
|
|
|
|
### Implementation Summary
|
|
|
|
|
2021-12-20 09:21:47 +00:00
|
|
|
* Encryption is implemented using cryptsetup with LUKS extension. A good
|
|
|
|
introduction to LUKS and dm-crypt in general can be found
|
2020-01-29 11:44:45 +00:00
|
|
|
[here](https://wiki.archlinux.org/index.php/Dm-crypt/Device_encryption#Encrypting_devices_with_cryptsetup)
|
|
|
|
Functions to implement necessary interaction are implemented in a separate
|
|
|
|
`cryptsetup.go` file.
|
2022-11-09 13:37:26 +00:00
|
|
|
* LuksFormat
|
|
|
|
* LuksOpen
|
|
|
|
* LuksClose
|
|
|
|
* LuksStatus
|
2020-01-29 11:44:45 +00:00
|
|
|
|
|
|
|
* `CreateVolume`: refactored to prepare for encryption (tag image that it
|
|
|
|
requires encryption later), before returning, if encrypted volume option is
|
|
|
|
set.
|
|
|
|
* `NodeStageVolume`: refactored to call `encryptDevice` method on the very first
|
|
|
|
volume attach request
|
|
|
|
* `NodeStageVolume`: refactored to open encrypted device (`openEncryptedDevice`)
|
|
|
|
* `openEncryptedDevice`: looks up for a passphrase matching the volume id,
|
2021-12-20 09:21:47 +00:00
|
|
|
returns the new device path in the form: `/dev/mapper/luks-<volume_id>`. On
|
|
|
|
the worker node where the attach is scheduled:
|
2020-01-29 11:44:45 +00:00
|
|
|
|
|
|
|
```shell
|
|
|
|
$ lsblk
|
|
|
|
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
|
|
|
|
sda 8:0 0 10G 0 disk
|
|
|
|
└─sda1 8:1 0 10G 0 part /
|
|
|
|
sdb 8:16 0 20G 0 disk
|
|
|
|
rbd0 253:0 0 1G 0 disk
|
|
|
|
└─luks-pvc-8a710f4c934811e9 252:0 0 1020M 0 crypt /var/lib/kubelet/pods/9eaceaef-936c-11e9-b396-005056af3de0/volumes/kubernetes.io~csi/pvc-8a710f4c934811e9/mount
|
|
|
|
```
|
|
|
|
|
|
|
|
* `detachRBDDevice`: calls `LuksClose` function to remove the LUKS mapping
|
|
|
|
before detaching the volume.
|
|
|
|
|
|
|
|
* StorageClass extended with following parameters:
|
2021-12-20 09:21:47 +00:00
|
|
|
1. `encrypted` ("true" or "false")
|
|
|
|
2. `encryptionKMSID` (string representing kms configuration of choice)
|
|
|
|
ceph-csi plugin may support different kms vendors with different type of
|
|
|
|
authentication
|
2020-01-29 11:44:45 +00:00
|
|
|
|
|
|
|
* New KMS Configuration created.
|
|
|
|
|
|
|
|
#### Annotated YAML for RBD StorageClass
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
apiVersion: storage.k8s.io/v1
|
|
|
|
kind: StorageClass
|
|
|
|
metadata:
|
2021-12-20 09:21:47 +00:00
|
|
|
name: csi-rbd
|
2020-01-29 11:44:45 +00:00
|
|
|
provisioner: rbd.csi.ceph.com
|
|
|
|
parameters:
|
2021-12-20 09:21:47 +00:00
|
|
|
# String representing Ceph cluster configuration
|
|
|
|
clusterID: <cluster-id>
|
|
|
|
# ceph pool
|
|
|
|
pool: rbd
|
|
|
|
|
|
|
|
# RBD image features, CSI creates image with image-format 2
|
|
|
|
# CSI RBD currently supports only `layering` feature.
|
|
|
|
imageFeatures: layering
|
|
|
|
|
|
|
|
# The secrets have to contain Ceph credentials with required access
|
|
|
|
# to the 'pool'.
|
|
|
|
csi.storage.k8s.io/provisioner-secret-name: csi-rbd-secret
|
|
|
|
csi.storage.k8s.io/provisioner-secret-namespace: default
|
|
|
|
csi.storage.k8s.io/controller-expand-secret-name: csi-rbd-secret
|
|
|
|
csi.storage.k8s.io/controller-expand-secret-namespace: default
|
|
|
|
csi.storage.k8s.io/node-stage-secret-name: csi-rbd-secret
|
|
|
|
csi.storage.k8s.io/node-stage-secret-namespace: default
|
|
|
|
# Specify the filesystem type of the volume. If not specified,
|
|
|
|
# csi-provisioner will set default as `ext4`.
|
|
|
|
csi.storage.k8s.io/fstype: ext4
|
|
|
|
|
|
|
|
# Encrypt volumes
|
|
|
|
encrypted: "true"
|
|
|
|
|
|
|
|
# Use external key management system for encryption passphrases by specifying
|
|
|
|
# a unique ID matching KMS ConfigMap. The ID is only used for correlation to
|
|
|
|
# configmap entry.
|
|
|
|
encryptionKMSID: <kms-id>
|
2020-01-29 11:44:45 +00:00
|
|
|
|
|
|
|
reclaimPolicy: Delete
|
|
|
|
```
|
|
|
|
|
|
|
|
And kms configuration:
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
---
|
|
|
|
apiVersion: v1
|
|
|
|
kind: ConfigMap
|
|
|
|
data:
|
|
|
|
config.json: |-
|
2020-02-06 16:23:14 +00:00
|
|
|
{
|
|
|
|
"<kms-id>": {
|
|
|
|
"encryptionKMSType": "kmsType",
|
2020-01-29 11:44:45 +00:00
|
|
|
kms specific config...
|
|
|
|
}
|
2020-02-06 16:23:14 +00:00
|
|
|
}
|
2020-01-29 11:44:45 +00:00
|
|
|
metadata:
|
|
|
|
name: ceph-csi-encryption-kms-config
|
|
|
|
```
|
2021-02-19 12:41:30 +00:00
|
|
|
|
|
|
|
### Implementation Details
|
|
|
|
|
|
|
|
The main components that are used to support encrypted volumes:
|
|
|
|
|
|
|
|
1. the `EncryptionKMS` interface
|
2021-12-20 09:21:47 +00:00
|
|
|
|
|
|
|
* an instance is configured per volume object (`rbdVolume.KMS`)
|
|
|
|
* used to authenticate with a master key or token
|
|
|
|
* can store the KEK (Key-Encryption-Key) for encrypting and decrypting the
|
|
|
|
DEKs (Data-Encryption-Key)
|
|
|
|
|
2021-02-19 12:41:30 +00:00
|
|
|
1. the `DEKStore` interface
|
2021-12-20 09:21:47 +00:00
|
|
|
|
|
|
|
* saves and fetches the DEK (Data-Encryption-Key)
|
|
|
|
* can be provided by a KMS, or by other components (like `rbdVolume`)
|
|
|
|
|
2021-02-19 12:41:30 +00:00
|
|
|
1. the `VolumeEncryption` type
|
2021-12-20 09:21:47 +00:00
|
|
|
|
|
|
|
* combines `EncryptionKMS` and `DEKStore` into a single place
|
|
|
|
* easy to configure from other components or subsystems
|
|
|
|
* provides a simple API for all KMS operations
|