OpenShift 4 - 对 OpenShift 的 etcd 数据库加密

OpenShift / RHEL / DevSecOps 汇总目录
说明:本文已经在 OpenShift 4.14 的环境中验证

加密 etcd 数据库

OpenShift 对 etcd 数据库加密时只加密值,而不加密键。而资源类型、命名空间和对象名称是未加密的。

  1. 执行命令编辑 apiserver 对象。
$ oc edit apiserver
  1. 添加以下 YAML 配置。其中 aesgcm 用于 AES-GCM 加密,而 aescbc 用于 AES-CBC 加密。
spec:
  encryption:
    type: aesgcm
  1. 修改完 apiserver 后就会对 etcd 进行加密,整个过程需要持续一段时间。可以执行以下命令查看加密过程。
$ oc get openshiftapiserver -o=jsonpath='{range .items[0].status.conditions[?(@.type=="Encrypted")]}{.reason}{"\n"}{.message}{"\n"}'
EncryptionInProgress
Resource routes.route.openshift.io is being encrypted

当返回以下结果代表加密完成。

EncryptionCompleted
All resources encrypted: routes.route.openshift.io
  1. 执行以下命令可以看到在 etcd 中加密的对象类型,其中包括 secret 和 configmap。
$ oc get kubeapiserver -o=jsonpath='{range .items[0].status.conditions[?(@.type=="Encrypted")]}{.reason}{"\n"}{.message}{"\n"}'
EncryptionCompleted
All resources encrypted: secrets, configmaps

验证加密的 etcd 数据库

  1. 完成《OpenShift - 利用容器的特权配置实现对OpenShift攻击,以及如何使用 PSA 和 RHACS 防范风险》一文中“环境准备”和“获取 etcd 中的数据”场景。
  2. 执行命令查看从 OpenShift 集群中复制出来的 etcd 数据库文件,确认已经无法识别 Secret 中的数据了。
$ strings ~/db | grep my-secret -A 10
-/kubernetes.io/secrets/pod-security/my-secret
k8s:enc:aesgcm:v1:1:
fB/7J
JzCF6
A/kubernetes.io/secrets/pod-security/sa-privileged-dockercfg-6f4hv
sk8s:enc:aesgcm:v1:1:
]_ZodzH
1xse
,t]Fm
5EWg
a?~(

解密 etcd 数据库

  1. 参考加密 etcd 数据库的操作过程,只需要使用以下的 YAML 即可恢复已经加密的 etcd 数据库。
spec:
  encryption:
    type: identity
  1. 解密过程需要一定时间,可通过哟以下命令查看 kubeapiserver 状态。注意:在单节点 OpenShift 环境中会出现需要重新登陆的情况。
$ oc get kubeapiserver -o=jsonpath='{range .items[0].status.conditions[?(@.type=="Encrypted")]}{.reason}{"\n"}{.message}{"\n"}'
DecryptionInProgress
Encryption mode set to identity and decryption is not finished
  1. 解密完成后会有以下提示。
$ oc get kubeapiserver -o=jsonpath='{range .items[0].status.conditions[?(@.type=="Encrypted")]}{.reason}{"\n"}{.message}{"\n"}'
DecryptionCompleted
Encryption mode set to identity and everything is decrypted
  1. 解密后可再次使用《OpenShift - 利用容器的特权配置实现对OpenShift攻击,以及如何使用 PSA 和 RHACS 防范风险》一文中“环境准备”和“获取 etcd 中的数据”场景验证。
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值