説明
TKE クラスターで KMS による暗号化を有効にすると、etcd に保存する Kubernetes Secret が暗号化されます。ボリュームやネットワーク通信の暗号化は別途設定してください。
想定される影響
etcd の保存先が露出すると、資格情報やトークンが漏れるおそれがあります。保存時に暗号化しても、権限があれば Kubernetes 経由で読み取れるため、RBAC で Secret の読み取りを制限し、キーの利用権限も絞ってください。
対処方法
対応するクラスターの cluster_id を tencentcloud_kubernetes_encryption_protection に設定し、kms_configuration にキー ID とキーのリージョンを指定します。TKE にキーの利用権限を付与し、使用中のキーの無効化や削除を制限してください。
例
省略した VPC データソースを用意します。kms_region は実際のキーのリージョンに合わせてください。例では ap-guangzhou です。適用後、クラスターの etcd 暗号化状態と、ワークロードから必要な Secret を利用できることを確認します。
変更前
hcl
resource "tencentcloud_kubernetes_cluster" "platform_cluster" {
vpc_id = data.tencentcloud_vpc_subnets.vpc.instance_list.0.vpc_id
cluster_cidr = "10.32.0.0/16"
cluster_max_pod_num = 32
cluster_name = "tf_example_cluster"
cluster_desc = "TKE クラスターの例"
cluster_max_service_num = 32
cluster_deploy_type = "MANAGED_CLUSTER"
}
変更後
hcl
resource "tencentcloud_kubernetes_cluster" "platform_cluster" {
vpc_id = data.tencentcloud_vpc_subnets.vpc.instance_list.0.vpc_id
cluster_cidr = "10.32.0.0/16"
cluster_max_pod_num = 32
cluster_name = "tf_example_cluster"
cluster_desc = "TKE クラスターの例"
cluster_max_service_num = 32
cluster_deploy_type = "MANAGED_CLUSTER"
}
resource "tencentcloud_kms_key" "cluster_key" {
alias = "tf-example-kms-key"
description = "Kubernetes Secret の暗号化キー"
key_usage = "ENCRYPT_DECRYPT"
is_enabled = true
}
resource "tencentcloud_kubernetes_encryption_protection" "cluster_encryption" {
cluster_id = tencentcloud_kubernetes_cluster.platform_cluster.id
kms_configuration {
key_id = tencentcloud_kms_key.cluster_key.id
kms_region = "ap-guangzhou"
}
}