|
| 1 | +--- |
| 2 | +layout: blog |
| 3 | +title: 'Kubernetes 1.24: 防止未经授权的卷模式转换' |
| 4 | +date: 2022-05-18 |
| 5 | +slug: prevent-unauthorised-volume-mode-conversion-alpha |
| 6 | +--- |
| 7 | + |
| 8 | +<!-- |
| 9 | +layout: blog |
| 10 | +title: 'Kubernetes 1.24: Prevent unauthorised volume mode conversion' |
| 11 | +date: 2022-05-18 |
| 12 | +slug: prevent-unauthorised-volume-mode-conversion-alpha |
| 13 | +--> |
| 14 | + |
| 15 | +<!-- |
| 16 | +**Author:** Raunak Pradip Shah (Mirantis) |
| 17 | +--> |
| 18 | +**作者:** Raunak Pradip Shah (Mirantis) |
| 19 | + |
| 20 | +<!-- |
| 21 | +Kubernetes v1.24 introduces a new alpha-level feature that prevents unauthorised users |
| 22 | +from modifying the volume mode of a [`PersistentVolumeClaim`](/docs/concepts/storage/persistent-volumes/) created from an |
| 23 | +existing [`VolumeSnapshot`](/docs/concepts/storage/volume-snapshots/) in the Kubernetes cluster. |
| 24 | +--> |
| 25 | +Kubernetes v1.24 引入了一个新的 alpha 级特性,可以防止未经授权的用户修改基于 Kubernetes |
| 26 | +集群中已有的 [`VolumeSnapshot`](/zh/docs/concepts/storage/volume-snapshots/) |
| 27 | +创建的 [`PersistentVolumeClaim`](/zh/docs/concepts/storage/persistent-volumes/) 的卷模式。 |
| 28 | + |
| 29 | +<!-- |
| 30 | +### The problem |
| 31 | +--> |
| 32 | +### 问题 |
| 33 | + |
| 34 | +<!-- |
| 35 | +The [Volume Mode](/docs/concepts/storage/persistent-volumes/#volume-mode) determines whether a volume |
| 36 | +is formatted into a filesystem or presented as a raw block device. |
| 37 | +--> |
| 38 | +[卷模式](/zh/docs/concepts/storage/persistent-volumes/#volume-mode)确定卷是格式化为文件系统还是显示为原始块设备。 |
| 39 | + |
| 40 | +<!-- |
| 41 | +Users can leverage the `VolumeSnapshot` feature, which has been stable since Kubernetes v1.20, |
| 42 | +to create a `PersistentVolumeClaim` (shortened as PVC) from an existing `VolumeSnapshot` in |
| 43 | +the Kubernetes cluster. The PVC spec includes a `dataSource` field, which can point to an |
| 44 | +existing `VolumeSnapshot` instance. |
| 45 | +Visit [Create a PersistentVolumeClaim from a Volume Snapshot](/docs/concepts/storage/persistent-volumes/#create-persistent-volume-claim-from-volume-snapshot) for more details. |
| 46 | +--> |
| 47 | +用户可以使用自 Kubernetes v1.20 以来就稳定的 `VolumeSnapshot` 功能, |
| 48 | +基于 Kubernetes 集群中的已有的 `VolumeSnapshot` 创建一个 `PersistentVolumeClaim` (简称 PVC )。 |
| 49 | +PVC 规约包括一个 `dataSource` 字段,它可以指向一个已有的 `VolumeSnapshot` 实例。 |
| 50 | +查阅[基于卷快照创建 PVC](/zh/docs/concepts/storage/persistent-volumes/#create-persistent-volume-claim-from-volume-snapshot) |
| 51 | +获取更多详细信息。 |
| 52 | + |
| 53 | +<!-- |
| 54 | +When leveraging the above capability, there is no logic that validates whether the mode of the |
| 55 | +original volume, whose snapshot was taken, matches the mode of the newly created volume. |
| 56 | +--> |
| 57 | +当使用上述功能时,没有逻辑来验证快照所在的原始卷的模式是否与新创建的卷的模式匹配。 |
| 58 | + |
| 59 | +<!-- |
| 60 | +This presents a security gap that allows malicious users to potentially exploit an |
| 61 | +as-yet-unknown vulnerability in the host operating system. |
| 62 | +--> |
| 63 | +这引起了一个安全漏洞,允许恶意用户潜在地利用主机操作系统中的未知漏洞。 |
| 64 | + |
| 65 | +<!-- |
| 66 | +Many popular storage backup vendors convert the volume mode during the course of a |
| 67 | +backup operation, for efficiency purposes, which prevents Kubernetes from blocking |
| 68 | +the operation completely and presents a challenge in distinguishing trusted |
| 69 | +users from malicious ones. |
| 70 | +--> |
| 71 | +为了提高效率,许多流行的存储备份供应商在备份操作过程中转换卷模式, |
| 72 | +这使得 Kubernetes 无法完全阻止该操作,并在区分受信任用户和恶意用户方面带来挑战。 |
| 73 | + |
| 74 | +<!-- |
| 75 | +### Preventing unauthorised users from converting the volume mode |
| 76 | +--> |
| 77 | +### 防止未经授权的用户转换卷模式 |
| 78 | + |
| 79 | +<!-- |
| 80 | +In this context, an authorised user is one who has access rights to perform `Update` |
| 81 | +or `Patch` operations on `VolumeSnapshotContents`, which is a cluster-level resource. |
| 82 | +It is upto the cluster administrator to provide these rights only to trusted users |
| 83 | +or applications, like backup vendors. |
| 84 | +--> |
| 85 | +在这种情况下,授权用户是指有权对 `VolumeSnapshotContents`(集群级资源)执行 `Update` |
| 86 | +或 `Patch` 操作的用户。集群管理员只能向受信任的用户或应用程序(如备份供应商)提供这些权限。 |
| 87 | + |
| 88 | +<!-- |
| 89 | +If the alpha feature is [enabled](https://kubernetes-csi.github.io/docs/) in |
| 90 | +`snapshot-controller`, `snapshot-validation-webhook` and `external-provisioner`, |
| 91 | +then unauthorised users will not be allowed to modify the volume mode of a PVC |
| 92 | +when it is being created from a `VolumeSnapshot`. |
| 93 | +--> |
| 94 | +如果在 `snapshot-controller`、`snapshot-validation-webhook` 和 |
| 95 | +`external-provisioner` 中[启用](https://kubernetes-csi.github.io/docs/)了这个 alpha |
| 96 | +特性,则基于 `VolumeSnapshot` 创建 PVC 时,将不允许未经授权的用户修改其卷模式。 |
| 97 | + |
| 98 | +<!-- |
| 99 | +To convert the volume mode, an authorised user must do the following: |
| 100 | +--> |
| 101 | +如要转换卷模式,授权用户必须执行以下操作: |
| 102 | + |
| 103 | +<!-- |
| 104 | +1. Identify the `VolumeSnapshot` that is to be used as the data source for a newly |
| 105 | +created PVC in the given namespace. |
| 106 | +2. Identify the `VolumeSnapshotContent` bound to the above `VolumeSnapshot`. |
| 107 | +--> |
| 108 | +1. 确定要用作给定命名空间中新创建 PVC 的数据源的 `VolumeSnapshot`。 |
| 109 | +2. 确定绑定到上面 `VolumeSnapshot` 的 `VolumeSnapshotContent`。 |
| 110 | + |
| 111 | + ``` |
| 112 | + kubectl get volumesnapshot -n <namespace> |
| 113 | + ``` |
| 114 | +<!-- |
| 115 | +3. Add the annotation [`snapshot.storage.kubernetes.io/allowVolumeModeChange`](/docs/reference/labels-annotations-taints/#snapshot-storage-kubernetes-io-allowvolumemodechange) |
| 116 | +to the `VolumeSnapshotContent`. |
| 117 | +--> |
| 118 | +3. 给 `VolumeSnapshotContent` 添加 |
| 119 | + [`snapshot.storage.kubernetes.io/allowVolumeModeChange`](/zh/docs/reference/labels-annotations-taints/#snapshot-storage-kubernetes-io-allowvolumemodechange) |
| 120 | + 注解。 |
| 121 | + |
| 122 | +<!-- |
| 123 | +4.This annotation can be added either via software or manually by the authorised |
| 124 | +user. The `VolumeSnapshotContent` annotation must look like following manifest fragment: |
| 125 | +--> |
| 126 | +4. 此注解可通过软件添加或由授权用户手动添加。`VolumeSnapshotContent` 注解必须类似于以下清单片段: |
| 127 | + |
| 128 | + ```yaml |
| 129 | + kind: VolumeSnapshotContent |
| 130 | + metadata: |
| 131 | + annotations: |
| 132 | + - snapshot.storage.kubernetes.io/allowVolumeModeChange: "true" |
| 133 | + ... |
| 134 | + ``` |
| 135 | +<!-- |
| 136 | +**Note**: For pre-provisioned `VolumeSnapshotContents`, you must take an extra |
| 137 | +step of setting `spec.sourceVolumeMode` field to either `Filesystem` or `Block`, |
| 138 | +depending on the mode of the volume from which this snapshot was taken. |
| 139 | +--> |
| 140 | +**注意**:对于预先制备的 `VolumeSnapshotContents`,你必须采取额外的步骤设置 `spec.sourceVolumeMode` |
| 141 | +字段为 `Filesystem` 或 `Block`,这取决于快照所在卷的模式。 |
| 142 | + |
| 143 | +<!-- |
| 144 | +An example is shown below: |
| 145 | +--> |
| 146 | +如下为一个示例: |
| 147 | + |
| 148 | +```yaml |
| 149 | + apiVersion: snapshot.storage.k8s.io/v1 |
| 150 | + kind: VolumeSnapshotContent |
| 151 | + metadata: |
| 152 | + annotations: |
| 153 | + - snapshot.storage.kubernetes.io/allowVolumeModeChange: "true" |
| 154 | + name: new-snapshot-content-test |
| 155 | + spec: |
| 156 | + deletionPolicy: Delete |
| 157 | + driver: hostpath.csi.k8s.io |
| 158 | + source: |
| 159 | + snapshotHandle: 7bdd0de3-aaeb-11e8-9aae-0242ac110002 |
| 160 | + sourceVolumeMode: Filesystem |
| 161 | + volumeSnapshotRef: |
| 162 | + name: new-snapshot-test |
| 163 | + namespace: default |
| 164 | +``` |
| 165 | + |
| 166 | +<!-- |
| 167 | +Repeat steps 1 to 3 for all `VolumeSnapshotContents` whose volume mode needs to be |
| 168 | +converted during a backup or restore operation. |
| 169 | +--> |
| 170 | +对于在备份或恢复操作期间需要转换卷模式的所有 `VolumeSnapshotContents`,重复步骤 1 到 3。 |
| 171 | + |
| 172 | +<!-- |
| 173 | +If the annotation shown in step 4 above is present on a `VolumeSnapshotContent` |
| 174 | +object, Kubernetes will not prevent the volume mode from being converted. |
| 175 | +Users should keep this in mind before they attempt to add the annotation |
| 176 | +to any `VolumeSnapshotContent`. |
| 177 | +--> |
| 178 | +如果 `VolumeSnapshotContent` 对象上存在上面步骤 4 中显示的注解,Kubernetes 将不会阻止转换卷模式。 |
| 179 | +用户在尝试将注解添加到任何 `VolumeSnapshotContent` 之前,应该记住这一点。 |
| 180 | + |
| 181 | +<!-- |
| 182 | +### What's next |
| 183 | +--> |
| 184 | +### 接下来 |
| 185 | + |
| 186 | +<!-- |
| 187 | +[Enable this feature](https://kubernetes-csi.github.io/docs/) and let us know |
| 188 | +what you think! |
| 189 | +--> |
| 190 | +[启用此特性](https://kubernetes-csi.github.io/docs/)并让我们知道你的想法! |
| 191 | + |
| 192 | +<!-- |
| 193 | +We hope this feature causes no disruption to existing workflows while preventing |
| 194 | +malicious users from exploiting security vulnerabilities in their clusters. |
| 195 | +--> |
| 196 | +我们希望此功能不会中断现有工作流程,同时防止恶意用户利用集群中的安全漏洞。 |
| 197 | + |
| 198 | +<!-- |
| 199 | +For any issues, create a thread in the #sig-storage slack channel or an issue |
| 200 | +in the CSI external-snapshotter [repository](https://github.com/kubernetes-csi/external-snapshotter). |
| 201 | +--> |
| 202 | +若有任何问题,请在 #sig-storage slack 频道中创建一个会话, |
| 203 | +或在 CSI 外部快照存储[仓库](https://github.com/kubernetes-csi/external-snapshotter)中报告一个 issue。 |
0 commit comments