Enhancement: Encrypt Kubernetes Secrets at rest in k3s #76

Closed
opened 2026-11-30 19:35:17 +01:00 by claude-bot · 0 comments

Goal

Encrypt all Kubernetes Secrets in etcd with secretbox before merging the OpenBao branch (#65). Merging it deploys OpenBao, and cert-manager then stores its private keys as Secrets.

Branch: enhancement/enable-secrets-encryption

What's affected

k3s encrypts Secrets for the whole cluster, so the app stacks don't need changes. Checked on 2026-12-01, using names only:

Where Sensitive data in Secrets
cert-manager Cloudflare API token, Let's Encrypt account key, webhook CA key
Longhorn UI login, UI certificate key, webhook keys
Heimdall Certificate key
Monitoring Grafana admin login, database password and certificate key; admission webhook key; Prometheus config
k3s and Traefik k3s API certificate key, node password hashes, Traefik chart values
Helm Release data, which can include chart passwords
OpenBao (not deployed) CA and server private keys

Not covered: data in volumes, Secrets mounted in pods, root access to a master, or anyone allowed to read Secrets. The encryption key is stored on the masters, so full VM backups can include it. Volume encryption and access permissions need separate tickets.

How it's done

  • Fresh installs: Pulumi sets this up through 02-k8s-bootstrap.
  • Running cluster: this needs a one-time manual change. 02 only runs the k3s installer on a fresh install and ignores later changes to those commands. Adding the flags also doesn't encrypt existing Secrets. Both setups must use the same settings.

1. Update Pulumi and write the runbook

  • In 02-k8s-bootstrap/index.ts, add --secrets-encryption and --secrets-encryption-provider=secretbox to all 3 master installs. Workers don't need them. Keep the rule that ignores changes to existing commands.
  • Run npm run typecheck and pulumi preview. The preview must show no changes to existing install commands. Include both outputs in the PR.
  • Add docs/runbooks/k3s-secrets-encryption.md with the exact steps for the live change and checks. Mention secretbox in the cluster rebuild runbook.

Don't deploy 02 or use --target-replace for this change. Merge the PR after the live change has been checked, so a replacement master doesn't join with different settings.

2. Turn on encryption in the running cluster

Follow the runbook, with deployments paused. First check that all nodes are Ready, etcd is healthy and each master can be reached directly over SSH. Use the same first master throughout. Restart one master at a time, starting with that one. Wait until it's Ready and etcd is healthy before restarting the next.

  1. Check that encryption is disabled and has no configuration file. Then enable it on the first master only. This doesn't create a key or encrypt anything yet.
  2. On all 3 masters, turn on encryption and select secretbox in a separate k3s config file. Don't change the existing config. First check that the new file doesn't already exist and that k3s doesn't use a custom config path.
  3. Restart all 3 masters. Encryption should still be disabled, at stage start, with matching hashes. Check that both settings are active on all 3 masters, because key rotation uses the server's setting to choose the encryption type.
  4. Rotate the keys once, on the first master. This creates the secretbox key and re-encrypts existing Secrets. Wait for reencrypt_finished.
  5. Restart all 3 masters again. Check that encryption is enabled, the stage is reencrypt_finished, the hashes match and the active key is XSalsa20-POLY1305.

If a check fails, stop. Don't repeat key rotation, force re-encryption or delete k3s files. Never interrupt key rotation, and don't restart any masters until it finishes. A crash during this step could stop the cluster from starting (k3s issue 13763), and we haven't confirmed a fix.

Using secretbox from the start is based on the v1.36.2+k3s1 server code. It hasn't been tested, and the k3s guide for existing clusters doesn't cover it.

3. Check that it worked

  • Check that nodes, etcd and apps are healthy, and that each master's API can read Secrets. Don't print their values.
  • In etcd, check an existing Secret and a new test Secret with a fake value. Both must start with k8s:enc:secretbox:v1:. Only show this prefix, then delete the test Secret.
  • Check for etcd snapshots from before encryption finished, because their Secrets aren't encrypted. Once a newer snapshot exists, delete the old ones, including any copies.

Done when

  • The status and etcd checks confirm that new and existing Secrets use secretbox.
  • The old, unencrypted snapshots have been deleted.
  • The Pulumi code and docs are merged, and the preview shows no changes to existing install commands.
  • The result is added to #65, so this ticket no longer blocks OpenBao.

Don't put tokens, keys, Secret values or internal IPs in this issue, the repo or logs.

References

## Goal Encrypt all Kubernetes Secrets in etcd with `secretbox` **before merging the OpenBao branch (#65)**. Merging it deploys OpenBao, and cert-manager then stores its private keys as Secrets. Branch: `enhancement/enable-secrets-encryption` ## What's affected k3s encrypts Secrets for the whole cluster, so the app stacks don't need changes. Checked on 2026-12-01, using names only: | Where | Sensitive data in Secrets | |---|---| | cert-manager | Cloudflare API token, Let's Encrypt account key, webhook CA key | | Longhorn | UI login, UI certificate key, webhook keys | | Heimdall | Certificate key | | Monitoring | Grafana admin login, database password and certificate key; admission webhook key; Prometheus config | | k3s and Traefik | k3s API certificate key, node password hashes, Traefik chart values | | Helm | Release data, which can include chart passwords | | OpenBao (not deployed) | CA and server private keys | **Not covered:** data in volumes, Secrets mounted in pods, root access to a master, or anyone allowed to read Secrets. The encryption key is stored on the masters, so full VM backups can include it. Volume encryption and access permissions need separate tickets. ## How it's done - **Fresh installs:** Pulumi sets this up through `02-k8s-bootstrap`. - **Running cluster:** this needs a one-time manual change. `02` only runs the k3s installer on a fresh install and ignores later changes to those commands. Adding the flags also doesn't encrypt existing Secrets. Both setups must use the same settings. ## 1. Update Pulumi and write the runbook - [x] In `02-k8s-bootstrap/index.ts`, add `--secrets-encryption` and `--secrets-encryption-provider=secretbox` to all 3 master installs. Workers don't need them. Keep the rule that ignores changes to existing commands. - [x] Run `npm run typecheck` and `pulumi preview`. The preview must show no changes to existing install commands. Include both outputs in the PR. - [x] Add `docs/runbooks/k3s-secrets-encryption.md` with the exact steps for the live change and checks. Mention `secretbox` in the cluster rebuild runbook. **Don't deploy `02` or use `--target-replace` for this change.** Merge the PR after the live change has been checked, so a replacement master doesn't join with different settings. ## 2. Turn on encryption in the running cluster Follow the runbook, with deployments paused. First check that all nodes are `Ready`, etcd is healthy and each master can be reached directly over SSH. Use the same first master throughout. Restart **one master at a time**, starting with that one. Wait until it's `Ready` and etcd is healthy before restarting the next. 1. [x] Check that encryption is disabled and has no configuration file. Then enable it on the first master **only**. This doesn't create a key or encrypt anything yet. 2. [x] On **all 3 masters**, turn on encryption and select `secretbox` in a separate k3s config file. Don't change the existing config. First check that the new file doesn't already exist and that k3s doesn't use a custom config path. 3. [x] Restart all 3 masters. Encryption should still be disabled, at stage `start`, with matching hashes. Check that **both settings are active on all 3 masters**, because key rotation uses the server's setting to choose the encryption type. 4. [x] Rotate the keys **once**, on the first master. This creates the `secretbox` key and re-encrypts existing Secrets. Wait for `reencrypt_finished`. 5. [x] Restart all 3 masters again. Check that encryption is enabled, the stage is `reencrypt_finished`, the hashes match and the active key is `XSalsa20-POLY1305`. **If a check fails, stop.** Don't repeat key rotation, force re-encryption or delete k3s files. **Never interrupt key rotation**, and don't restart any masters until it finishes. A crash during this step could stop the cluster from starting (k3s issue 13763), and we haven't confirmed a fix. Using `secretbox` from the start is based on the `v1.36.2+k3s1` server code. It hasn't been tested, and the k3s guide for existing clusters doesn't cover it. ## 3. Check that it worked - [x] Check that nodes, etcd and apps are healthy, and that each master's API can read Secrets. Don't print their values. - [x] In etcd, check an existing Secret and a new test Secret with a fake value. Both must start with `k8s:enc:secretbox:v1:`. Only show this prefix, then delete the test Secret. - [ ] Check for etcd snapshots from before encryption finished, because their Secrets aren't encrypted. Once a newer snapshot exists, delete the old ones, including any copies. ## Done when - [x] The status and etcd checks confirm that new and existing Secrets use `secretbox`. - [ ] The old, unencrypted snapshots have been deleted. - [x] The Pulumi code and docs are merged, and the preview shows no changes to existing install commands. - [x] The result is added to #65, so this ticket no longer blocks OpenBao. Don't put tokens, keys, Secret values or internal IPs in this issue, the repo or logs. ## References - [k3s: Turn on Secrets encryption](https://docs.k3s.io/cli/secrets-encrypt) - [k3s: Encryption types](https://docs.k3s.io/security/secrets-encryption) - [k3s: Config files](https://docs.k3s.io/installation/configuration) - [k3s: Snapshots](https://docs.k3s.io/cli/etcd-snapshot) - [k3s PR 13370: Support for existing clusters (included in v1.36.2+k3s1)](https://github.com/k3s-io/k3s/pull/13370) - [k3s issue 13763: Crash during key rotation](https://github.com/k3s-io/k3s/issues/13763)
kasun added a new dependency 2026-12-01 02:28:39 +01:00
claude-bot Bot closed this issue 2026-12-01 03:09:49 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Blocks
Reference: kasun/homelab-infrastructure-as-code#76