secretの暗号化設定

K3sは、保存時のsecretの暗号化を有効にすることをサポートしています。サーバーを初めて起動する際に、フラグ --secrets-encryption を渡すと、以下のことが自動的に行われます:

  • AES-CBCキーの生成

  • 生成されたキーを使用して暗号化設定ファイルの生成

  • 暗号化設定ファイルをKubeAPIに暗号化プロバイダー設定として渡す

secretの暗号化は、サーバーを再起動せずに既存のサーバーで有効にすることはできません。
スクリプトからインストールする場合は curl -sfL https://get.k3s.io | sh -s - server --secrets-encryption を使用するか、設定オプションに記載されている他の方法を使用してください。

Choosing Encryption Provider

Version Gate

Available as of the April 2025 releases: v1.30.12+k3s1, v1.31.8+k3s1, v1.32.4+k3s1, v1.33.0+k3s1.

Using the --secrets-encryption-provider flag, you can choose from the following K3s-supported encryption providers:

  • aescbc: AES-CBC with PKCS#7 padding. This is the default provider.

  • secretbox: XSalsa20 and Poly1305

Migrating Providers

You can migrate from the aescbc provider to the secretbox provider by following these steps:

  1. Ensure that the secretbox provider is supported by your K3s version.

  2. Update/Add the secrets-encryption-provider flag in your K3s configuration file to secretbox.

  3. Rotate the encryption keys, following the Encryption Key Rotation section below.

Generated encryption config file

When you start the server with --secrets-encryption, K3s will generate an encryption config file at /var/lib/rancher/k3s/server/cred/encryption-config.json.

Below is an example of the generated encryption config file with the default aescbc provider:

{
  "kind": "EncryptionConfiguration",
  "apiVersion": "apiserver.config.k8s.io/v1",
  "resources": [
    {
      "resources": [
        "secrets"
      ],
      "providers": [
        {
          "aescbc": {
            "keys": [
              {
                "name": "aescbckey",
                "secret": "xxxxxxxxxxxxxxxxxxx"
              }
            ]
          }
        },
        {
          "identity": {}
        }
      ]
    }
  ]
}

secretの暗号化ツール

K3sには secrets-encrypt というユーティリティツールが含まれており、以下の自動制御を可能にします:

  • secretの暗号化の無効化/有効化

  • 新しい暗号化キーの追加

  • 暗号化キーのローテーションおよび削除

  • secretの再暗号化

詳細については、k3s secrets-encrypt コマンドのドキュメントを参照してください。