2018-07-31 09:31:12 +00:00
# CSI RBD Plugin
2019-02-07 09:58:38 +00:00
The RBD CSI plugin is able to provision new RBD images and
2019-02-18 04:47:31 +00:00
attach and mount those to workloads.
2018-07-31 09:31:12 +00:00
## Building
2019-05-24 11:03:33 +00:00
CSI plugin can be compiled in a form of a binary file or in a form of a
2019-02-07 09:58:38 +00:00
Docker image. When compiled as a binary file, the result is stored in
2019-05-08 04:27:13 +00:00
`_output/` directory with the name `cephcsi` . When compiled as an image, it's
2019-05-24 11:03:33 +00:00
stored in the local Docker image store with name `cephcsi` .
2018-07-31 09:31:12 +00:00
Building binary:
2019-02-07 09:58:38 +00:00
2018-07-31 09:31:12 +00:00
```bash
2019-05-08 04:27:13 +00:00
make cephcsi
2018-07-31 09:31:12 +00:00
```
Building Docker image:
2019-02-07 09:58:38 +00:00
2018-07-31 09:31:12 +00:00
```bash
2019-05-24 11:03:33 +00:00
make image-cephcsi
2018-07-31 09:31:12 +00:00
```
## Configuration
**Available command line arguments:**
2020-06-24 06:44:02 +00:00
| Option | Default value | Description |
| ------------------------ | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `--endpoint` | `unix://tmp/csi.sock` | CSI endpoint, must be a UNIX socket |
| `--drivername` | `rbd.csi.ceph.com` | Name of the driver (Kubernetes: `provisioner` field in StorageClass must correspond to this value) |
| `--nodeid` | _empty_ | This node's ID |
2020-08-21 12:12:28 +00:00
| `--type` | _empty_ | Driver type: `[rbd/cephfs]` . If the driver type is set to `rbd` it will act as a `rbd plugin` or if it's set to `cephfs` will act as a `cephfs plugin` |
2020-06-24 06:44:02 +00:00
| `--instanceid` | "default" | Unique ID distinguishing this instance of Ceph CSI among other instances, when sharing Ceph clusters across CSI instances for provisioning |
| `--pidlimit` | _0_ | Configure the PID limit in cgroups. The container runtime can restrict the number of processes/tasks which can cause problems while provisioning (or deleting) a large number of volumes. A value of `-1` configures the limit to the maximum, `0` does not configure limits at all. |
| `--metricsport` | `8080` | TCP port for liveness metrics requests |
| `--metricspath` | `"/metrics"` | Path of prometheus endpoint where metrics will be available |
| `--enablegrpcmetrics` | `false` | [Deprecated] Enable grpc metrics collection and start prometheus server |
| `--polltime` | `"60s"` | Time interval in between each poll |
| `--timeout` | `"3s"` | Probe timeout in seconds |
| `--histogramoption` | `0.5,2,6` | [Deprecated] Histogram option for grpc metrics, should be comma separated value (ex:= "0.5,2,6" where start=0.5 factor=2, count=6) |
| `--domainlabels` | _empty_ | Kubernetes node labels to use as CSI domain labels for topology aware provisioning, should be a comma separated value (ex:= "failure-domain/region,failure-domain/zone") |
| `--rbdhardmaxclonedepth` | `8` | Hard limit for maximum number of nested volume clones that are taken before a flatten occurs |
| `--rbdsoftmaxclonedepth` | `4` | Soft limit for maximum number of nested volume clones that are taken before a flatten occurs |
2020-06-24 08:12:12 +00:00
| `--skipforceflatten` | `false` | skip image flattening on kernel < 5.2 which support mapping of rbd images which has the deep-flatten feature |
2020-07-01 05:27:11 +00:00
| `--maxsnapshotsonimage` | `450` | Maximum number of snapshots allowed on rbd image without flattening |
2018-07-31 09:31:12 +00:00
**Available volume parameters:**
2019-08-21 09:28:02 +00:00
| Parameter | Required | Description |
| --------------------------------------------------------------------------------------------------- | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `clusterID` | yes | String representing a Ceph cluster, must be unique across all Ceph clusters in use for provisioning, cannot be greater than 36 bytes in length, and should remain immutable for the lifetime of the Ceph cluster in use |
| `pool` | yes | Ceph pool into which the RBD image shall be created |
2019-09-10 09:56:08 +00:00
| `dataPool` | no | Ceph pool used for the data of the RBD images. |
2020-06-24 06:44:02 +00:00
| `volumeNamePrefix` | no | Prefix to use for naming RBD images (defaults to `csi-vol-` ). |
2020-02-24 13:19:42 +00:00
| `snapshotNamePrefix` | no | Prefix to use for naming RBD snapshot images (defaults to `csi-snap-` ). |
2021-01-15 09:41:21 +00:00
| `imageFeatures` | yes | RBD image features. CSI RBD currently supports only `layering` feature. See [man pages ](http://docs.ceph.com/docs/master/man/8/rbd/#cmdoption-rbd-image-feature ) Note that the required support for [object-map and fast-diff were added in 5.3 and journaling does not have KRBD support yet ](https://docs.ceph.com/en/latest/rbd/rbd-config-ref/#image-features ) which is why they are unsupported here. deep-flatten is added for cloned images. |
2020-09-08 05:23:28 +00:00
| `mapOptions` | no | Map options to use when mapping rbd image. See [krbd ](https://docs.ceph.com/docs/master/man/8/rbd/#kernel-rbd-krbd-options ) and [nbd ](https://docs.ceph.com/docs/master/man/8/rbd-nbd/#options ) options. |
| `unmapOptions` | no | Unmap options to use when unmapping rbd image. See [krbd ](https://docs.ceph.com/docs/master/man/8/rbd/#kernel-rbd-krbd-options ) and [nbd ](https://docs.ceph.com/docs/master/man/8/rbd-nbd/#options ) options. |
2019-08-06 10:09:25 +00:00
| `csi.storage.k8s.io/provisioner-secret-name` , `csi.storage.k8s.io/node-stage-secret-name` | yes (for Kubernetes) | name of the Kubernetes Secret object containing Ceph client credentials. Both parameters should have the same value |
| `csi.storage.k8s.io/provisioner-secret-namespace` , `csi.storage.k8s.io/node-stage-secret-namespace` | yes (for Kubernetes) | namespaces of the above Secret objects |
2019-08-21 09:28:02 +00:00
| `mounter` | no | if set to `rbd-nbd` , use `rbd-nbd` on nodes that have `rbd-nbd` and `nbd` kernel modules to map rbd images |
2020-06-10 10:52:52 +00:00
| `encrypted` | no | disabled by default, use `"true"` to enable LUKS encryption on PVC and `"false"` to disable it. **Do not change for existing storageclasses** |
2020-02-06 16:23:14 +00:00
| `encryptionKMSID` | no | required if encryption is enabled and a kms is used to store passphrases |
2018-07-31 09:31:12 +00:00
2019-04-22 21:35:39 +00:00
**NOTE:** An accompanying CSI configuration file, needs to be provided to the
2019-05-28 19:03:18 +00:00
running pods. Refer to [Creating CSI configuration ](../examples/README.md#creating-csi-configuration )
2019-04-22 21:35:39 +00:00
for more information.
2019-05-28 19:03:18 +00:00
**NOTE:** A suggested way to populate and retain uniqueness of the clusterID is
2019-04-22 21:35:39 +00:00
to use the output of `ceph fsid` of the Ceph cluster to be used for
provisioning.
2019-03-07 21:03:33 +00:00
2019-02-07 09:58:38 +00:00
**Required secrets:**
2019-06-01 21:26:42 +00:00
User credentials, with required access to the pool being used in the storage class,
is required for provisioning new RBD images.
2018-07-31 09:31:12 +00:00
## Deployment with Kubernetes
2019-12-19 15:35:58 +00:00
Requires Kubernetes 1.14+
2019-07-25 06:49:44 +00:00
2019-12-19 15:35:58 +00:00
Use the [rbd templates ](../deploy/rbd/kubernetes )
2018-07-31 09:31:12 +00:00
2019-02-07 09:58:38 +00:00
Your Kubernetes cluster must allow privileged pods (i.e. `--allow-privileged`
flag must be set to true for both the API server and the kubelet). Moreover, as
stated in the [mount propagation
docs](https://kubernetes.io/docs/concepts/storage/volumes/#mount-propagation),
the Docker daemon of the cluster nodes must allow shared mounts.
2018-07-31 09:31:12 +00:00
YAML manifests are located in `deploy/rbd/kubernetes` .
**Deploy RBACs for sidecar containers and node plugins:**
```bash
2019-02-07 09:58:38 +00:00
kubectl create -f csi-provisioner-rbac.yaml
kubectl create -f csi-nodeplugin-rbac.yaml
2018-07-31 09:31:12 +00:00
```
2019-02-07 09:58:38 +00:00
Those manifests deploy service accounts, cluster roles and cluster role
bindings. These are shared for both RBD and CephFS CSI plugins, as they require
the same permissions.
2018-07-31 09:31:12 +00:00
2020-01-21 08:22:43 +00:00
**Deploy PodSecurityPolicy resources for sidecar containers and node plugins:**
**NOTE:** These manifests are required only if [PodSecurityPolicy ](https://kubernetes.io/docs/reference/access-authn-authz/admission-controllers/#podsecuritypolicy )
admission controller is active on your cluster.
```bash
kubectl create -f csi-provisioner-psp.yaml
kubectl create -f csi-nodeplugin-psp.yaml
```
2019-04-22 21:35:39 +00:00
**Deploy ConfigMap for CSI plugins:**
```bash
kubectl create -f csi-config-map.yaml
```
2020-06-10 06:23:03 +00:00
The configmap deploys an empty CSI configuration that is mounted as a volume
2019-04-22 21:35:39 +00:00
within the Ceph CSI plugin pods. To add a specific Ceph clusters configuration
details, refer to [Creating CSI configuration for RBD based
provisioning](../examples/README.md#creating-csi-configuration-for-rbd-based-provisioning)
for more information.
2018-07-31 09:31:12 +00:00
**Deploy CSI sidecar containers:**
```bash
2019-02-07 09:58:38 +00:00
kubectl create -f csi-rbdplugin-provisioner.yaml
2018-07-31 09:31:12 +00:00
```
2020-10-23 01:53:34 +00:00
Deploys deployment of provision which includes external-provisioner
2019-03-27 06:06:20 +00:00
,external-attacher,csi-snapshotter sidecar containers and CSI RBD plugin.
2018-07-31 09:31:12 +00:00
**Deploy RBD CSI driver:**
```bash
2019-02-07 09:58:38 +00:00
kubectl create -f csi-rbdplugin.yaml
2018-07-31 09:31:12 +00:00
```
2019-03-27 06:06:20 +00:00
Deploys a daemon set with two containers: CSI node-driver-registrar and the CSI
RBD driver.
2018-07-31 09:31:12 +00:00
## Verifying the deployment in Kubernetes
2019-02-20 10:00:18 +00:00
After successfully completing the steps above, you should see output similar to this:
2018-07-31 09:31:12 +00:00
```bash
$ kubectl get all
NAME READY STATUS RESTARTS AGE
2019-06-20 19:30:40 +00:00
pod/csi-rbdplugin-fptqr 3/3 Running 0 21s
pod/csi-rbdplugin-provisioner-0 5/5 Running 0 22s
2018-07-31 09:31:12 +00:00
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
2019-06-20 19:30:40 +00:00
service/csi-rbdplugin-provisioner ClusterIP 10.104.2.130 < none > 8080/TCP 23s
2018-07-31 09:31:12 +00:00
...
```
2019-04-22 21:35:39 +00:00
Once the CSI plugin configuration is updated with details from a Ceph cluster of
choice, you can try deploying a demo pod from examples/rbd using the
instructions [provided ](../examples/README.md#deploying-the-storage-class ) to
test the deployment further.
2018-07-31 09:31:12 +00:00
2019-01-07 16:25:40 +00:00
## Deployment with Helm
The same requirements from the Kubernetes section apply here, i.e. Kubernetes
version, privileged flag and shared mounts.
2019-09-26 09:55:12 +00:00
The Helm chart is located in `charts/ceph-csi-rbd` .
2019-01-07 16:25:40 +00:00
**Deploy Helm Chart:**
2019-09-26 09:55:12 +00:00
[See the Helm chart readme for installation instructions. ](../charts/ceph-csi-rbd/README.md )
2019-12-13 11:41:32 +00:00
## Encryption for RBD volumes
> Enabling encryption on volumes created without encryption is **not supported**
>
> Enabling encryption for storage class that has PVs created without encryption
> is **not supported**
Volumes provisioned with Ceph RBD do not have encryption by default. It is
possible to encrypt them with ceph-csi by using LUKS encryption.
### Life-cycle for encrypted volumes
**Create volume**:
* create volume request received
* volume requested to be created in Ceph
* encrypted state "requiresEncryption" is saved in image-meta in Ceph
**Attach volume**:
* attach volume request received
* volume is attached to provisioner container
* on first time attachment
(no file system on the attached device, checked with blkid)
2020-01-29 11:44:45 +00:00
* new passphrase is generated and stored in selected KMS if KMS is in use
2020-10-08 05:36:03 +00:00
* device is encrypted with LUKS using a passphrase from K8s secrets.
2019-12-13 11:41:32 +00:00
* image-meta updated to "encrypted" in Ceph
2020-01-29 11:44:45 +00:00
* passphrase is retrieved from selected KMS if KMS is in use
2019-12-13 11:41:32 +00:00
* device is open and device path is changed to use a mapper device
* mapper device is used instead of original one with usual workflow
**Detach volume**:
* mapper device closed and device path changed to original volume path
* volume is detached as usual
2020-01-29 11:44:45 +00:00
* passphrase removed from KMS if needed (with failures ignored)
2019-12-13 11:41:32 +00:00
### Encryption configuration
To encrypt rbd volumes with LUKS you need to set encryption passphrase in
secrets under `encryptionPassphrase` key and switch `encrypted` option in
StorageClass to `"true"` . This is not supported for storage classes that already
2020-10-08 05:36:03 +00:00
have PVs provisioned. The `node-stage-secret-name` and the `provisioner-secret-name`
should carry this key and value for encryption to work.
To use different passphrase you need to have different storage classes and point
to a different K8s secrets `csi.storage.k8s.io/node-stage-secret-name`
and `csi.storage.k8s.io/provisioner-secret-name` which carry new passphrase value
for `encryptionPassphrase` key in these secrets.
2019-12-13 11:41:32 +00:00
2020-01-29 11:44:45 +00:00
### Encryption KMS configuration
To further improve security robustness it is possible to use unique passphrases
generated for each volume and stored in a Key Management System (KMS). Currently
HashiCorp Vault is the only KMS supported.
2020-12-10 15:47:20 +00:00
There are two options to use Hashicorp Vault as a KMS:
1. with Kubernetes ServiceAccount
1. with a Vault Token per Tenant (a Kubernetes Namespace)
2020-02-06 16:23:14 +00:00
To use Vault as KMS set `encryptionKMSID` to a unique identifier for Vault
configuration. You will also need to create vault configuration similar to the
2020-12-10 15:49:53 +00:00
[example ](../examples/kms/vault/kms-config.yaml ) and use same
`encryptionKMSID` .
2020-12-10 15:47:20 +00:00
To use the Kubernetes ServiceAccount to access Vault, the configuration must
include `encryptionKMSType: "vault"` . If Tenants are expected to place their
Vault Token in a Kubernetes Secret in their Namespace, set `encryptionKMSType:
"vaulttokens"`.
In order for ceph-csi to be able to access the configuration you will need to
have it mounted to csi-rbdplugin containers in both daemonset (so kms client
can be instantiated to encrypt/decrypt volumes) and deployment pods (so kms
client can be instantiated to delete passphrase on volume delete)
`ceph-csi-encryption-kms-config` configmap.
2020-02-06 16:23:14 +00:00
> Note: kms configuration must be a map of string values only
> (`map[string]string`) so for numerical and boolean values make sure to put
> quotes around.
2020-01-29 11:44:45 +00:00
2020-12-10 15:47:20 +00:00
When the Tenants need to provide their own Vault Token, they will need to place
it in a Kubernetes Secret (by default) called `ceph-csi-kms-token` , where the
Vault Token is stored in the `token` key as shown in [the
example](../examples/kms/vault/tenant-token.yaml).
#### Configuring HashiCorp Vault with Kubernetes ServiceAccount
2020-01-29 11:44:45 +00:00
Using Vault as KMS you need to configure Kubernetes authentication method as
described in [official
documentation](https://www.vaultproject.io/docs/auth/kubernetes.html).
If token reviewer is used, you will need to configure service account for
2020-12-10 15:49:53 +00:00
that also like in
[example ](../examples/kms/vault/csi-vaulttokenreview-rbac.yaml ) to be able to
review jwt tokens.
2020-01-29 11:44:45 +00:00
Configure a role(s) for service accounts used for ceph-csi:
* provisioner service account (`rbd-csi-provisioner`) requires only **delete**
2020-06-10 10:52:52 +00:00
permissions to delete passphrases on PVC delete
2020-01-29 11:44:45 +00:00
* nodeplugin service account (`rbd-csi-nodeplugin`) requires **create** and
**read** permissions to save new keys and retrieve existing
2019-12-13 11:41:32 +00:00
### Encryption prerequisites
In order for encryption to work you need to make sure that `dm-crypt` kernel
module is enabled on the nodes running ceph-csi attachers.
If custom image is built for the rbd-plugin instance, make sure that it contains
`cryptsetup` tool installed to be able to use encryption.