更新时间:2025-05-16 GMT+08:00
在CCE集群中使用密钥Secret的安全配置建议
当前CCE已为secret资源配置了静态加密,用户创建的secret在CCE的集群的etcd里会被加密存储。当前secret主要有环境变量和文件挂载两种使用方式。不论使用哪种方式,CCE传递给用户的仍然是用户配置时的数据。因此建议:
- 用户不应在日志中对相关敏感信息进行记录;
- 通过文件挂载的方式secret时,默认在容器内映射的文件权限为0644,建议为其配置更严格的权限,例如:
apiversion: v1 kind: Pod metadata: name: mypod spec: containers: - name: mypod image: redis volumeMounts: - name: foo mountPath: "/etc/foo" volumes: - name: foo secret: secretName: mysecret defaultMode: 256其中“defaultMode: 256”,256为10进制,对应八进制的0400权限。
- 使用文件挂载的方式时,通过配置secret的文件名实现文件在容器中“隐藏”的效果:
apiVersion: v1 kind: Secret metadata: name: dotfile-secret data: .secret-file: dmFsdWUtMg0KDQo= --- apiVersion: v1 kind: Pod metadata: name: secret-dotfiles-pod spec: volumes: - name: secret-volume secret: secretName: dotfile-secret containers: - name: dotfile-test-container image: k8s.gcr.io/busybox command: - ls - "-1" - "/etc/secret-volume" volumeMounts: - name: secret-volume readOnly: true mountPath: "/etc/secret-volume"这样.secret-file目录在/etc/secret-volume/路径下通过ls -l命令查看不到,但可以通过ls -al命令查看到。
- 用户应在创建secret前自行加密敏感信息,使用时解密。
使用Bound ServiceAccount Token访问集群
基于Secret的ServiceAccount Token由于token不支持设置过期时间、不支持自动刷新,并且由于存放在secret中,pod被删除后token仍然存在secret中,一旦泄露可能导致安全风险。1.23版本以及以上版本CCE集群推荐使用Bound Service Account Token,该方式支持设置过期时间,并且和pod生命周期一致,可减少凭据泄露风险。例如:
apiVersion: apps/v1
kind: Deployment
metadata:
name: security-token-example
namespace: security-example
spec:
replicas: 1
selector:
matchLabels:
app: security-token-example
label: security-token-example
template:
metadata:
annotations:
seccomp.security.alpha.kubernetes.io/pod: runtime/default
labels:
app: security-token-example
label: security-token-example
spec:
serviceAccountName: test-sa
containers:
- image: ...
imagePullPolicy: Always
name: security-token-example
volumes:
- name: test-projected
projected:
defaultMode: 420
sources:
- serviceAccountToken:
expirationSeconds: 1800
path: token
- configMap:
items:
- key: ca.crt
path: ca.crt
name: kube-root-ca.crt
- downwardAPI:
items:
- fieldRef:
apiVersion: v1
fieldPath: metadata.namespace
path: namespace
具体可参考管理服务账号。
使用CCE密钥管理(对接 DEW)插件
CCE密钥管理(dew-provider)插件用于对接数据加密服务(Data Encryption Workshop, DEW)。该插件允许用户将存储在集群外部(即专门存储敏感信息的数据加密服务)的凭据挂载至业务Pod内,从而将敏感信息与集群环境解耦,有效避免程序硬编码或明文配置等问题导致的敏感信息泄密。
父主题: 安全