3.3. 在使用 KMS 时启用和禁用密钥轮转
安全常见实践需要定期加密密钥轮转。在使用 KMS 时,您可以启用或禁用密钥轮转。
3.3.1. 启用密钥轮转 复制链接链接已复制到粘贴板!
要启用密钥轮转,请将注解 keyrotation.csiaddons.openshift.io/schedule: <value> 添加到 ,PersistentVolumeClaims Namespace, 或 StorageClass (以优先级顺序减少)。
<value > 可以是 @hourly、@daily、@weekly、@monthly 或 @yearly。如果 <value > 为空,则默认为 @weekly。以下示例使用 @weekly。
只支持 RBD 支持的卷的密钥轮转。
注解命名空间
oc get namespace default
$ oc get namespace default
NAME STATUS AGE
default Active 5d2h
oc annotate namespace default "keyrotation.csiaddons.openshift.io/schedule=@weekly"
$ oc annotate namespace default "keyrotation.csiaddons.openshift.io/schedule=@weekly"
namespace/default annotated
Annotating StorageClass
oc get storageclass rbd-sc
$ oc get storageclass rbd-sc
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
rbd-sc rbd.csi.ceph.com Delete Immediate true 5d2h
oc annotate storageclass rbd-sc "keyrotation.csiaddons.openshift.io/schedule=@weekly"
$ oc annotate storageclass rbd-sc "keyrotation.csiaddons.openshift.io/schedule=@weekly"
storageclass.storage.k8s.io/rbd-sc annotated
注解 PersistentVolumeClaim
oc get pvc data-pvc
$ oc get pvc data-pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
data-pvc Bound pvc-f37b8582-4b04-4676-88dd-e1b95c6abf74 1Gi RWO default 20h
oc annotate pvc data-pvc "keyrotation.csiaddons.openshift.io/schedule=@weekly"
$ oc annotate pvc data-pvc "keyrotation.csiaddons.openshift.io/schedule=@weekly"
persistentvolumeclaim/data-pvc annotated
oc get encryptionkeyrotationcronjobs.csiaddons.openshift.io
$ oc get encryptionkeyrotationcronjobs.csiaddons.openshift.io
NAME SCHEDULE SUSPEND ACTIVE LASTSCHEDULE AGE
data-pvc-1642663516 @weekly 3s
oc annotate pvc data-pvc "keyrotation.csiaddons.openshift.io/schedule=*/1 * * * *" --overwrite=true
$ oc annotate pvc data-pvc "keyrotation.csiaddons.openshift.io/schedule=*/1 * * * *" --overwrite=true
persistentvolumeclaim/data-pvc annotated
oc get encryptionkeyrotationcronjobs.csiaddons.openshift.io
$ oc get encryptionkeyrotationcronjobs.csiaddons.openshift.io
NAME SCHEDULE SUSPEND ACTIVE LASTSCHEDULE AGE
data-pvc-1642664617 */1 * * * * 3s
3.3.2. 禁用密钥轮转 复制链接链接已复制到粘贴板!
您可以为以下内容禁用密钥轮转:
- 所有存储类的持久性卷声明(PVC)
- 特定的 PVC
为存储类的所有 PVC 禁用密钥轮转
要禁用所有 PVC 的密钥轮转,请更新存储类的注解:
oc get storageclass rbd-sc
$ oc get storageclass rbd-sc
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
rbd-sc rbd.csi.ceph.com Delete Immediate true 5d2h
oc annotate storageclass rbd-sc "keyrotation.csiaddons.openshift.io/enable: false"
$ oc annotate storageclass rbd-sc "keyrotation.csiaddons.openshift.io/enable: false"
storageclass.storage.k8s.io/rbd-sc annotated
为特定持久性卷声明禁用密钥轮转
为您要禁用密钥轮转的 PVC 识别
EncryptionKeyRotationCronJobCR:oc get encryptionkeyrotationcronjob -o jsonpath='{range .items[?(@.spec.jobTemplate.spec.target.persistentVolumeClaim=="<PVC_NAME>")]}{.metadata.name}{"\n"}{end}'$ oc get encryptionkeyrotationcronjob -o jsonpath='{range .items[?(@.spec.jobTemplate.spec.target.persistentVolumeClaim=="<PVC_NAME>")]}{.metadata.name}{"\n"}{end}'Copy to Clipboard Copied! Toggle word wrap Toggle overflow 其中
<PVC_NAME> 是您要禁用的 PVC 名称。将以下内容应用到上一步中的
EncryptionKeyRotationCronJobCR,以禁用密钥轮转:将
csiaddons.openshift.io/state注解从managed更新到unmanaged:oc annotate encryptionkeyrotationcronjob <encryptionkeyrotationcronjob_name> "csiaddons.openshift.io/state=unmanaged" --overwrite=true
$ oc annotate encryptionkeyrotationcronjob <encryptionkeyrotationcronjob_name> "csiaddons.openshift.io/state=unmanaged" --overwrite=trueCopy to Clipboard Copied! Toggle word wrap Toggle overflow 其中 <encryptionkeyrotationcronjob_name> 是
EncryptionKeyRotationCronJobCR 的名称。在
spec字段中添加suspend: true:oc patch encryptionkeyrotationcronjob <encryptionkeyrotationcronjob_name> -p '{"spec": {"suspend": true}}' --type=merge.$ oc patch encryptionkeyrotationcronjob <encryptionkeyrotationcronjob_name> -p '{"spec": {"suspend": true}}' --type=merge.Copy to Clipboard Copied! Toggle word wrap Toggle overflow
- 保存并退出。PVC 将禁用密钥轮转。