# Kubernetes 密钥以明文形式存储在 etcd 中

- **ID:** `security/kubernetes-secret-etcd-plaintext`
- **领域:** security
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

Kubernetes 密钥是 base64 编码的，但除非配置了静态加密，否则在 etcd 中不会加密存储，任何有权访问 etcd 的人都会暴露敏感数据。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Kubernetes 1.24 | active | — | — |
| Kubernetes 1.28 | active | — | — |
| etcd 3.5 | active | — | — |

## 解决方案

1. ```
   为 Kubernetes 密钥启用静态加密。编辑 kube-apiserver 配置，添加包含 `aescbc` 等提供程序的 EncryptionConfiguration 文件。示例：`--encryption-provider-config=/etc/kubernetes/enc/enc.yaml`。
   ```
2. ```
   使用外部密钥管理系统，如 HashiCorp Vault 或 AWS Secrets Manager，并在应用程序中引用它们，而不是将密钥存储在 etcd 中。
   ```
3. ```
   将 etcd 访问限制为仅控制平面节点，并对所有 etcd 连接使用 TLS 客户端认证。
   ```

## 无效尝试

- **** — Setting base64 encoding as encryption is a common misconception; base64 is not encryption and can be trivially decoded. (90% 失败率)
- **** — Using network policies to restrict etcd access doesn't protect against attackers who compromise a pod with etcd access. (50% 失败率)
- **** — Deleting the secret from etcd without cleaning up backups leaves the plaintext data in backup snapshots. (70% 失败率)
