How to Encrypt Kubernetes ETCD with OVHcloud KMS
Objective
This guide explains how to set up the kube-apiserver encryption provider enabling Kubernetes clusters to encrypt and decrypt data at rest using OVHcloud KMS through the KMIP protocol.
Requirements
- An OVHcloud customer account.
- You must have ordered an OKMS domain.
Instructions
Installing the binary
The binary can be installed directly from Go packages.
Or you can build from sources.
Configuring OVHcloud KMS (OKMS)
To use OVHcloud KMS as an encryption provider for Kubernetes, you will need the following:
- An OVHcloud user and permissions to manage OKMS KMIP keys.
- An access certificate for your OKMS domain.
- A KMIP AES key in your OKMS.
Creating user and access rights
Create a IAM local user with access rights on your domain.
If you are using IAM policies instead, the user should have at least the following rights on the OKMS domain:
okms:kmip:encryptokms:kmip:decryptokms:kmip:locate
Otherwise, the user should be a member of a group with the ADMIN role.
Alternatively, it is possible to create a user using OVHcloud CLI:
Creating access certificate
Create an OKMS access certificate and link the user previously created.
Save the certificate cert.pem and the private key key.pem generated, as they will be required for the encryption provider configuration.
Creating KMIP AES key
To create a KMIP AES key, you can use the OKMS CLI:
Start by downloading the binary from the latest release or building from source.
Then you can create a key using :
Keep the Key ID of the key generated. For the rest of the guide we'll use the Key ID 70001308-5674-43fe-93dd-6270ecac0710 as an example.
For more information on how to use the okms-cli, refer to the GitHub repository.
Configuring encryption provider
The encryption provider can be run on the kube-apiserver hosts directly with the following command line:
The encryption provider supports the following options:
| Flag | Description | Default |
|---|---|---|
--client-cert | Path to the client certificate file for OVHcloud KMS authentication. | "" (required) |
--client-key | Path to the private key file associated with the client certificate. | "" (required) |
--kmip-addr | Address of the KMIP server. Available in your OVHcloud Control Panel on your OKMS domain page. (e.g., eu-west-rbx.okms.ovh.net:5696). | "" (required) |
--kmip-key-id | Identifier of the encryption key to use on the KMIP server. | "" (required) |
--sock | Path to the Unix socket the provider will listen on. Should be mounted inside the Kubernetes apiserver. | /var/run/okms_etcd_plugin.sock |
--timeout | Timeout for the gRPC server operations. | 10s |
--debug | Activate debug traces. | false |
Configuring Kubernetes
Based on the official Kubernetes guide for encrypting data with a KMS provider, add the following flags on your kube-apiserver:
Make sure to mount the directory containing the Unix socket that the KMS server is listening on into the kube-apiserver.
An example of encryption-config.yaml:
Validating configuration
Create a secret with kubectl create secret generic okms-test-secret -n default --from-literal=mykey=mydata and then check the contents of the secret in ETCD storage by running the following:
The output should be unreadable:
Implementing key rotation
To rotate your key, you will need to run two encryption providers, each listening on a different Unix socket.
Below is an example encryption configuration file for all API servers prior to using the new key:
After all API servers have been restarted and are able to decrypt using the new key, move the provider with the new key on top.
After all secrets have been re-encrypted with the new key, you can remove the old encryption provider.
Go further
Join our community of users.
Find out how to use Kubernetes External Secrets Operator with Secret Manager.