1
1
---
2
2
layout : blog
3
- title : " Kubernetes的取证容器检查点 "
3
+ title : " Kubernetes 的取证容器检查点 "
4
4
date : 2022-12-05
5
5
slug : forensic-container-checkpointing-alpha
6
6
---
@@ -27,29 +27,28 @@ sandbox environment multiple times without the original container being aware
27
27
of it. Forensic container checkpointing was introduced as an alpha feature in
28
28
Kubernetes v1.25.
29
29
-->
30
- 取证容器检查点(Forensic container checkpointing)基于 [ CRIU] [ criu ] (Checkpoint/Restore
31
- In Userspace ,用户空间的检查点/恢复),并允许创建正在运行的容器的有状态副本,而容器不知道它正在被
32
- 检查。容器的副本,可以在沙箱环境中被多次分析和恢复,而原始容器并不知道。取证容器检查点是作为一个
33
- alpha 特性在 Kubernetes v1.25 中引入的。
30
+ 取证容器检查点(Forensic container checkpointing)基于 [ CRIU] [ criu ] (Checkpoint/Restore In Userspace ,用户空间的检查点/恢复),
31
+ 并允许创建正在运行的容器的有状态副本,而容器不知道它正在被检查。容器的副本,可以在沙箱环境中被多次分析和恢复,而原始容器并不知道。
32
+ 取证容器检查点是作为一个 alpha 特性在 Kubernetes v1.25 中引入的。
34
33
35
34
<!--
36
35
## How does it work?
37
36
-->
38
- ## 它是如何工作的?
37
+ ## 工作原理
39
38
40
39
<!--
41
40
With the help of CRIU it is possible to checkpoint and restore containers.
42
41
CRIU is integrated in runc, crun, CRI-O and containerd and forensic container
43
42
checkpointing as implemented in Kubernetes uses these existing CRIU
44
43
integrations.
45
44
-->
46
- 在 CRIU 的帮助下,检查(checkpoint)和恢复容器成为可能。CRIU 集成在 runc、crun、CRI-O 和
47
- containerd 中, 而在 Kubernetes 中实现的取证容器检查点使用这些现有的 CRIU 集成。
45
+ 在 CRIU 的帮助下,检查(checkpoint)和恢复容器成为可能。CRIU 集成在 runc、crun、CRI-O 和 containerd 中,
46
+ 而在 Kubernetes 中实现的取证容器检查点使用这些现有的 CRIU 集成。
48
47
49
48
<!--
50
49
## Why is it important?
51
50
-->
52
- ## 为什么重要 ?
51
+ ## 这一特性为何重要 ?
53
52
54
53
<!--
55
54
With the help of CRIU and the corresponding integrations it is possible to get
@@ -61,10 +60,9 @@ checkpoint and analysing the container in a sandboxed environment offers the
61
60
possibility to inspect the container without the original container and maybe
62
61
attacker being aware of the inspection.
63
62
-->
64
- 借助 CRIU 和相应的集成,可以获得磁盘上正在运行的容器的所有信息和状态,供以后进行取证分析。取证分析
65
- 对于在不阻止或影响可疑容器的情况下,对其进行检查可能很重要。如果容器确实受到攻击,攻击者可能会检测到
66
- 检查容器的企图。获取检查点并在沙箱环境中分析容器,提供了在原始容器和可能的攻击者不知道检查的情况下检
67
- 查容器的可能性。
63
+ 借助 CRIU 和相应的集成,可以获得磁盘上正在运行的容器的所有信息和状态,供以后进行取证分析。
64
+ 取证分析对于在不阻止或影响可疑容器的情况下,对其进行检查可能很重要。如果容器确实受到攻击,攻击者可能会检测到检查容器的企图。
65
+ 获取检查点并在沙箱环境中分析容器,提供了在原始容器和可能的攻击者不知道检查的情况下检查容器的可能性。
68
66
69
67
<!--
70
68
In addition to the forensic container checkpointing use case, it is also
@@ -73,8 +71,8 @@ the internal state. Especially for stateful containers with long initialization
73
71
times restoring from a checkpoint might save time after a reboot or enable much
74
72
faster startup times.
75
73
-->
76
- 除了取证容器检查点用例,还可以在不丢失内部状态的情况下,将容器从一个节点迁移到另一个节点。特别是对于
77
- 初始化时间长的有状态容器 ,从检查点恢复,可能会节省重新启动后的时间,或者实现更快的启动时间。
74
+ 除了取证容器检查点用例,还可以在不丢失内部状态的情况下,将容器从一个节点迁移到另一个节点。
75
+ 特别是对于初始化时间长的有状态容器 ,从检查点恢复,可能会节省重新启动后的时间,或者实现更快的启动时间。
78
76
79
77
<!--
80
78
## How do I use container checkpointing?
@@ -87,8 +85,7 @@ make sure to enable the `ContainerCheckpoint` gate before you can use the new
87
85
feature.
88
86
-->
89
87
90
- 该功能在[ 特性门] [ container-checkpoint-feature-gate ] 后面,因此在使用新功能之前,请确保启用
91
- ContainerCheckpoint 特性门。
88
+ 该功能在[ 特性门] [ container-checkpoint-feature-gate ] 后面,因此在使用新功能之前,请确保启用了 ContainerCheckpoint 特性门。
92
89
93
90
<!--
94
91
The runtime must also support container checkpointing:
@@ -118,16 +115,15 @@ is also necessary to install CRIU. Usually runc or crun depend on CRIU and
118
115
therefore it is installed automatically.
119
116
-->
120
117
要将取证容器检查点与 CRI-O 结合使用,需要使用命令行选项--enable-criu-support=true 启动运行时。
121
- Kubernetes 方面,你需要在启用 ContainerCheckpoint 特性门的情况下运行你的集群。由于检查点功能
122
- 是由 CRIU 提供的,因此也有必要安装 CRIU。 通常 runc 或 crun 依赖于 CRIU,因此它是自动安装的。
118
+ Kubernetes 方面,你需要在启用 ContainerCheckpoint 特性门的情况下运行你的集群。由于检查点功能是由 CRIU 提供的,因此也有必要安装 CRIU。
119
+ 通常 runc 或 crun 依赖于 CRIU,因此它是自动安装的。
123
120
124
121
<!--
125
122
It is also important to mention that at the time of writing the checkpointing functionality is
126
123
to be considered as an alpha level feature in CRI-O and Kubernetes and the
127
124
security implications are still under consideration.
128
125
-->
129
- 值得一提的是,在编写本文时,检查点功能被认为是 CRI-O 和 Kubernetes 中的一个 alpha 级特性,
130
- 其安全影响仍在评估之中。
126
+ 值得一提的是,在编写本文时,检查点功能被认为是 CRI-O 和 Kubernetes 中的一个 alpha 级特性,其安全影响仍在评估之中。
131
127
132
128
<!--
133
129
Once containers and pods are running it is possible to create a checkpoint.
@@ -140,23 +136,22 @@ checkpoint:
140
136
curl -X POST "https://localhost:10250/checkpoint/namespace/podId/container"
141
137
```
142
138
-->
143
- 一旦容器和 pod 开始运行,就可以创建一个检查点。[ 检查点] [ kubelet-checkpoint-api ] 目前只在
144
- kubelet 级别暴露。 要检查一个容器,可以在运行该容器的节点上运行 curl,并触发一个检查点:
139
+ 一旦容器和 pod 开始运行,就可以创建一个检查点。[ 检查点] [ kubelet-checkpoint-api ] 目前只在 ** kubelet ** 级别暴露。
140
+ 要检查一个容器,可以在运行该容器的节点上运行 curl,并触发一个检查点:
145
141
146
142
``` shell
147
143
curl -X POST " https://localhost:10250/checkpoint/namespace/podId/container"
148
144
```
149
145
150
146
<!--
151
147
For a container named *counter* in a pod named *counters* in a namespace named
152
- *default* the ** kubelet* * API endpoint is reachable at:
148
+ *default* the *kubelet* API endpoint is reachable at:
153
149
154
150
```shell
155
151
curl -X POST "https://localhost:10250/checkpoint/default/counters/counter"
156
152
```
157
153
-->
158
- 对于名为 default 的命名空间中名为 counters 的 pod 中的名为 counter 的容器,kubelet API
159
- 端点可在以下位置访问:
154
+ 对于名为 ** default** 的命名空间中名为 ** counters** 的 pod 中的名为 ** counter** 的容器, ** kubelet** API 端点可在以下位置访问:
160
155
161
156
``` shell
162
157
curl -X POST " https://localhost:10250/checkpoint/default/counters/counter"
@@ -171,8 +166,7 @@ use of the *kubelet* `checkpoint` API:
171
166
--insecure --cert /var/run/kubernetes/client-admin.crt --key /var/run/kubernetes/client-admin.key
172
167
```
173
168
-->
174
- 为了完整起见,以下 curl 命令行选项对于让 curl 接受 kubelet 的自签名证书并授权使用 kubelet
175
- 检查点 API 是必要的:
169
+ 为了完整起见,以下 curl 命令行选项对于让 curl 接受 ** kubelet** 的自签名证书并授权使用 ** kubelet** 检查点 API 是必要的:
176
170
177
171
``` shell
178
172
--insecure --cert /var/run/kubernetes/client-admin.crt --key /var/run/kubernetes/client-admin.key
@@ -189,8 +183,8 @@ Once the checkpointing has finished the checkpoint should be available at
189
183
190
184
You could then use that tar archive to restore the container somewhere else.
191
185
-->
192
- 触发这个 kubelet API 将从 CRI-O 请求创建一个检查点,CRI-O 从你的低级运行时(例如,runc)
193
- 请求一个检查点。 看到这个请求,runc 调用 criu 工具来执行实际的检查点操作。
186
+ 触发这个 ** kubelet** API 将从 CRI-O 请求创建一个检查点,CRI-O 从你的低级运行时(例如,runc)请求一个检查点。
187
+ 看到这个请求,runc 调用 criu 工具来执行实际的检查点操作。
194
188
195
189
检查点操作完成后,检查点应该位于
196
190
` /var/lib/kubelet/checkpoints/checkpoint-<pod-name>_<namespace-name>-<container-name>-<timestamp>.tar `
@@ -210,9 +204,8 @@ during restore, I recommend that you use the latest version of CRI-O from the
210
204
manually create certain directories Kubernetes would create before starting the
211
205
container.
212
206
-->
213
- 使用检查点 tar 归档文件,可以在 Kubernetes 之外的 CRI-O 沙箱实例中恢复容器。为了在恢复过程中
214
- 获得更好的用户体验,我建议你使用 main CRI-O GitHub 分支中最新版本的 CRI-O。如果你使用的是
215
- CRI-O v1.25,你需要在启动容器之前手动创建 Kubernetes 会创建的某些目录。
207
+ 使用检查点 tar 归档文件,可以在 Kubernetes 之外的 CRI-O 沙箱实例中恢复容器。为了在恢复过程中获得更好的用户体验,我建议你使用 CRI-O GitHub 的 ** main** 分支中最新版本的 CRI-O。
208
+ 如果你使用的是 CRI-O v1.25,你需要在启动容器之前手动创建 Kubernetes 会创建的某些目录。
216
209
217
210
<!--
218
211
The first step to restore a container outside of Kubernetes is to create a pod sandbox
@@ -222,7 +215,7 @@ using *crictl*:
222
215
crictl runp pod-config.json
223
216
```
224
217
-->
225
- 在 Kubernetes 外恢复容器的第一步是使用 crictl 创建一个 pod 沙箱:
218
+ 在 Kubernetes 外恢复容器的第一步是使用 ** crictl** 创建一个 pod 沙箱:
226
219
227
220
``` shell
228
221
crictl runp pod-config.json
@@ -319,10 +312,10 @@ The security implications of starting CRI-O with CRIU support are not yet clear
319
312
and therefore the functionality as well as the image format should be used with
320
313
care.
321
314
-->
322
- 生成的镜像未经标准化,只能与 CRI-O 结合使用。请将此镜像格式视为 pre-alpha 格式。社区正在 [ 讨论 ] [ image-spec-discussion ]
323
- 如何标准化这样的检查点镜像格式。重要的是要记住,这种尚未标准化的镜像格式只有在 CRI-O 已经用
324
- ` --enable-criu-support=true ` 启动时才有效。在 CRIU 支持下启动 CRI-O 的安全影响尚不清楚,
325
- 因此应谨慎使用功能和镜像格式。
315
+ 生成的镜像未经标准化,只能与 CRI-O 结合使用。请将此镜像格式视为 pre-alpha 格式。
316
+ 社区正在 [ 讨论 ] [ image-spec-discussion ] 如何标准化这样的检查点镜像格式。
317
+ 重要的是要记住,这种尚未标准化的镜像格式只有在 CRI-O 已经用 ` --enable-criu-support=true ` 启动时才有效。
318
+ 在 CRIU 支持下启动 CRI-O 的安全影响尚不清楚, 因此应谨慎使用功能和镜像格式。
326
319
327
320
<!--
328
321
Now, you'll need to push that image to a container image registry. For example:
@@ -354,8 +347,7 @@ spec:
354
347
nodeName: <destination-node>
355
348
```
356
349
-->
357
- 要恢复此检查点镜像(container-image-registry.example/user/checkpoint-image: latest ),
358
- 该镜像需要在 Pod 的规范中列出。下面是一个清单示例:
350
+ 要恢复此检查点镜像(container-image-registry.example/user/checkpoint-image: latest ),该镜像需要在 Pod 的规范中列出。下面是一个清单示例:
359
351
360
352
``` yaml
361
353
apiVersion : v1
@@ -379,26 +371,23 @@ instead of the usual steps to create and start a container,
379
371
CRI-O fetches the checkpoint data and restores the container from that
380
372
specified checkpoint.
381
373
-->
382
- Kubernetes 将新的 Pod 调度到一个节点上。该节点上的 kubelet 指示容器运行时(本例中为 CRI-O)
383
- 基于指定为 `registry/user/checkpoint-image:latest` 的镜像创建并启动容器。CRI-O 检测到
384
- ` registry/user/checkpoint-image:latest` 是对检查点数据的引用,而不是容器镜像。然后,与创建
385
- 和启动容器的通常步骤不同,CRI-O 获取检查点数据,并从指定的检查点恢复容器。
374
+ Kubernetes 将新的 Pod 调度到一个节点上。该节点上的 kubelet 指示容器运行时(本例中为 CRI-O)基于指定为 `registry/user/checkpoint-image:latest` 的镜像创建并启动容器。
375
+ CRI-O 检测到 `registry/user/checkpoint-image:latest` 是对检查点数据的引用,而不是容器镜像。
376
+ 然后,与创建和启动容器的通常步骤不同,CRI-O 获取检查点数据,并从指定的检查点恢复容器。
386
377
387
378
<!--
388
379
The application in that Pod would continue running as if the checkpoint had not been taken;
389
380
within the container, the application looks and behaves like any other container that had been
390
381
started normally and not restored from a checkpoint.
391
382
-->
392
- 该 Pod 中的应用程序将继续运行,就像检查点未被获取一样;在该容器中,应用程序的外观和行为,与正常
393
- 启动且未从检查点恢复的任何其他容器相似。
383
+ 该 Pod 中的应用程序将继续运行,就像检查点未被获取一样;在该容器中,应用程序的外观和行为,与正常启动且未从检查点恢复的任何其他容器相似。
394
384
395
385
<!--
396
386
With these steps, it is possible to replace a Pod running on one node
397
387
with a new equivalent Pod that is running on a different node,
398
388
and without losing the state of the containers in that Pod.
399
389
-->
400
- 通过这些步骤,可以用在不同节点上运行的新的等效 Pod,替换在一个节点上运行的 Pod,而不会丢失该 Pod
401
- 中容器的状态。
390
+ 通过这些步骤,可以用在不同节点上运行的新的等效 Pod,替换在一个节点上运行的 Pod,而不会丢失该 Pod中容器的状态。
402
391
403
392
<!--
404
393
# # How do I get involved?
@@ -428,7 +417,7 @@ can be analyzed.
428
417
-->
429
418
有关如何分析容器检查点的详细信息,请参阅后续文章[取证容器分析][forensic-container-analysis]。
430
419
431
- [forensic-container-analysis] : /blog/2023/03/10/forensic-container-analysis/
420
+ [forensic-container-analysis] : /zh-cn/ blog/2023/03/10/forensic-container-analysis/
432
421
[criu] : https://criu.org/
433
422
[containerd-checkpoint-restore-pr] : https://github.com/containerd/containerd/pull/6965
434
423
[container-checkpoint-feature-gate] : https://kubernetes.io/docs/reference/command-line-tools-reference/feature-gates/
0 commit comments