Skip to content

Commit 0f285fd

Browse files
authored
Merge pull request #44085 from sftim/20231125_explain_protection_encryption_keys
Explain more about protection for encryption keys (API data encryption at rest)
2 parents 8d5d1b4 + ada845e commit 0f285fd

File tree

1 file changed

+75
-14
lines changed

1 file changed

+75
-14
lines changed

content/en/docs/tasks/administer-cluster/encrypt-data.md

Lines changed: 75 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,72 @@ Using envelope encryption creates dependence on the key encryption key, which is
307307
In the KMS case, an attacker who intends to get unauthorised access to the plaintext
308308
values would need to compromise etcd **and** the third-party KMS provider.
309309

310-
## Write an encryption configuration file
310+
### Protection for encryption keys
311+
312+
You should take appropriate measures to protect the confidential information that allows decryption,
313+
whether that is a local encryption key, or an authentication token that allows the API server to
314+
call KMS.
315+
316+
Even when you rely on a provider to manage the use and lifecycle of the main encryption key (or keys), you are still responsible
317+
for making sure that access controls and other security measures for the managed encryption service are
318+
appropriate for your security needs.
319+
320+
## Encrypt your data {#encrypting-your-data}
321+
322+
### Generate the encryption key {#generate-key-no-kms}
323+
324+
{{< caution >}}
325+
Storing the raw encryption key in the EncryptionConfig only moderately improves your security posture,
326+
compared to no encryption.
327+
328+
For additional secrecy, consider using the `kms` provider as this relies on keys held outside your
329+
Kubernetes cluster. Implementations of `kms` can work with hardware security modules or with
330+
encryption services managed by your cloud provider.
331+
332+
To learn about setting
333+
up encryption at rest using KMS, see
334+
[Using a KMS provider for data encryption](/docs/tasks/administer-cluster/kms-provider/).
335+
The KMS provider plugin that you use may also come with additional specific documentation.
336+
{{< /caution >}}
337+
338+
Start by generating a new encryption key, and then encode it using base64:
339+
340+
{{< tabs name="generate_encryption_key" >}}
341+
{{% tab name="Linux" %}}
342+
Generate a 32-byte random key and base64 encode it. You can use this command:
343+
```shell
344+
head -c 32 /dev/urandom | base64
345+
```
346+
347+
You can use `/dev/hwrng` instead of `/dev/urandom` if you want to
348+
use your PC's built-in hardware entropy source. Not all Linux
349+
devices provide a hardware random generator.
350+
{{% /tab %}}
351+
{{% tab name="macOS" %}}
352+
<!-- localization note: this is similar to the Linux tab and the wording
353+
should match wherever the English text does -->
354+
Generate a 32-byte random key and base64 encode it. You can use this command:
355+
```shell
356+
head -c 32 /dev/urandom | base64
357+
```
358+
{{% /tab %}}
359+
{{% tab name="Windows" %}}
360+
Generate a 32-byte random key and base64 encode it. You can use this command:
361+
```powershell
362+
# Do not run this in a session where you have set a random number
363+
# generator seed.
364+
[Convert]::ToBase64String((1..32|%{[byte](Get-Random -Max 256)}))
365+
```
366+
{{% /tab %}}
367+
{{< /tabs >}}
368+
369+
370+
{{< note >}}
371+
Keep the encryption key confidential, including whilst you generate it and
372+
ideally even after you are no longer actively using it.
373+
{{< /note >}}
374+
375+
### Write an encryption configuration file
311376

312377
{{< caution >}}
313378
The encryption configuration file may contain keys that can decrypt content in etcd.
@@ -337,22 +402,15 @@ resources:
337402
# for example, during initial migration
338403
```
339404

340-
To create a new Secret, perform the following steps:
341-
342-
1. Generate a 32-byte random key and base64 encode it. If you're on Linux or macOS, run the following command:
343-
344-
```shell
345-
head -c 32 /dev/urandom | base64
346-
```
405+
To create a new encryption key (that does not use KMS), see
406+
[Generate the encryption key](#generate-key-no-kms).
347407

348-
1. Place that value in the `secret` field of the `EncryptionConfiguration` struct.
349-
1. Set the `--encryption-provider-config` flag on the `kube-apiserver` to point to
350-
the location of the config file.
408+
### Use the new encryption configuration file
351409

352-
You will need to mount the new encryption config file to the `kube-apiserver` static pod. Here is an example on how to do that:
410+
You will need to mount the new encryption config file to the `kube-apiserver` static pod. Here is an example on how to do that:
353411

354-
1. Save the new encryption config file to `/etc/kubernetes/enc/enc.yaml` on the control-plane node.
355-
1. Edit the manifest for the `kube-apiserver` static pod: `/etc/kubernetes/manifests/kube-apiserver.yaml` similarly to this:
412+
1. Save the new encryption config file to `/etc/kubernetes/enc/enc.yaml` on the control-plane node.
413+
1. Edit the manifest for the `kube-apiserver` static pod: `/etc/kubernetes/manifests/kube-apiserver.yaml` so that it is similar to:
356414

357415
```yaml
358416
---
@@ -399,6 +457,9 @@ Your config file contains keys that can decrypt the contents in etcd, so you mus
399457
permissions on your control-plane nodes so only the user who runs the `kube-apiserver` can read it.
400458
{{< /caution >}}
401459

460+
You now have encryption in place for **one** control plane host. A typical
461+
Kubernetes cluster has multiple control plane hosts, so there is more to do.
462+
402463
### Reconfigure other control plane hosts {#api-server-config-update-more}
403464

404465
If you have multiple API servers in your cluster, you should deploy the

0 commit comments

Comments
 (0)