Skip to content

Commit 582f090

Browse files
authored
Merge pull request #40748 from windsonsea/secomp
[zh] sync /tutorials/security/seccomp.md
2 parents 670bc3c + 06ac68b commit 582f090

File tree

1 file changed

+53
-47
lines changed

1 file changed

+53
-47
lines changed

content/zh-cn/docs/tutorials/security/seccomp.md

Lines changed: 53 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ profiles that give only the necessary privileges to your container processes.
3333
-->
3434
Seccomp 代表安全计算(Secure Computing)模式,自 2.6.12 版本以来,一直是 Linux 内核的一个特性。
3535
它可以用来沙箱化进程的权限,限制进程从用户态到内核态的调用。
36-
Kubernetes 能使你自动将加载到 {{< glossary_tooltip text="节点" term_id="node" >}}上的
36+
Kubernetes 能使你自动将加载到{{< glossary_tooltip text="节点" term_id="node" >}}上的
3737
seccomp 配置文件应用到你的 Pod 和容器。
3838

3939
识别你的工作负载所需要的权限是很困难的。在本篇教程中,
@@ -137,6 +137,7 @@ ls profiles
137137
You should see three profiles listed at the end of the final step:
138138
-->
139139
你应该看到在最后一步的末尾列出有三个配置文件:
140+
140141
```
141142
audit.json fine-grained.json violation.json
142143
```
@@ -150,7 +151,6 @@ so each node of the cluster is a container. This allows for files
150151
to be mounted in the filesystem of each container similar to loading files
151152
onto a node.
152153
-->
153-
154154
## 使用 kind 创建本地 Kubernetes 集群 {#create-a-local-kubernetes-cluster-with-kind}
155155

156156
为简单起见,[kind](https://kind.sigs.k8s.io/) 可用来创建加载了 seccomp 配置文件的单节点集群。
@@ -163,6 +163,7 @@ Kind 在 Docker 中运行 Kubernetes,因此集群的每个节点都是一个
163163
Download that example kind configuration, and save it to a file named `kind.yaml`:
164164
-->
165165
下载该示例 kind 配置,并将其保存到名为 `kind.yaml` 的文件中:
166+
166167
```shell
167168
curl -L -O https://k8s.io/examples/pods/security/seccomp/kind.yaml
168169
```
@@ -233,6 +234,12 @@ of the kubelet. Use `docker exec` to run a command in the Pod:
233234
你应该会看到 `profiles/` 目录已成功加载到 kubelet 的默认 seccomp 路径中。
234235
使用 `docker exec` 在 Pod 中运行命令:
235236

237+
<!--
238+
```shell
239+
# Change 6a96207fed4b to the container ID you saw from "docker ps"
240+
docker exec -it 6a96207fed4b ls /var/lib/kubelet/seccomp/profiles
241+
```
242+
-->
236243
```shell
237244
# 将 6a96207fed4b 更改为你从 “docker ps” 看到的容器 ID
238245
docker exec -it 6a96207fed4b ls /var/lib/kubelet/seccomp/profiles
@@ -253,21 +260,17 @@ running within kind.
253260
-->
254261
## 启用使用 `RuntimeDefault` 作为所有工作负载的默认 seccomp 配置文件 {#enable-runtimedefault-as-default}
255262

256-
{{< feature-state state="beta" for_k8s_version="v1.25" >}}
263+
{{< feature-state state="stable" for_k8s_version="v1.27" >}}
257264

258265
<!--
259-
To use seccomp profile defaulting, you must run the kubelet with the `SeccompDefault`
260-
[feature gate](/docs/reference/command-line-tools-reference/feature-gates/) enabled
261-
(this is the default). You must also explicitly enable the defaulting behavior for each
262-
node where you want to use this with the corresponding `--seccomp-default`
263-
[command line flag](/docs/reference/command-line-tools-reference/kubelet).
264-
Both have to be enabled simultaneously to use the feature.
266+
To use seccomp profile defaulting, you must run the kubelet with the
267+
`--seccomp-default`
268+
[command line flag](/docs/reference/command-line-tools-reference/kubelet)
269+
enabled for each node where you want to use it.
265270
-->
266-
要使用 Seccomp(安全计算模式)配置文件来设定默认值,你必须要在启用 `SeccompDefault`
267-
[特性门控](/zh-cn/docs/reference/command-line-tools-reference/feature-gates/)的情况下运行 kubelet
268-
(这是默认值)。
269-
你还必须显式地启用每个节点的默认行为,以及相应的
270-
`--seccomp-default` [命令行标志](/zh-cn/docs/reference/command-line-tools-reference/kubelet)。两者必须同时启用才能使用该特性。
271+
要使用 Seccomp(安全计算模式)配置文件采用默认设置这一行为,你必须使用在想要启用此行为的每个节点上启用
272+
`--seccomp-default`
273+
[命令行标志](/zh-cn/docs/reference/command-line-tools-reference/kubelet)来运行 kubelet。
271274

272275
<!--
273276
If enabled, the kubelet will use the `RuntimeDefault` seccomp profile by default, which is
@@ -337,14 +340,11 @@ Kubernetes 项目建议你在部分节点上启用此特性门控,
337340
<!--
338341
Kubernetes {{< skew currentVersion >}} lets you configure the seccomp profile
339342
that applies when the spec for a Pod doesn't define a specific seccomp profile.
340-
This is a beta feature and the corresponding `SeccompDefault` [feature
341-
gate](/docs/reference/command-line-tools-reference/feature-gates/) is enabled by
342-
default. However, you still need to enable this defaulting for each node where
343-
you would like to use it.
343+
However, you still need to enable this defaulting for each node where you would
344+
like to use it.
344345
-->
345346
Kubernetes {{< skew currentVersion >}} 允许你配置 Seccomp 配置文件,
346347
当 Pod 的规约未定义特定的 Seccomp 配置文件时应用该配置文件。
347-
这是一个 Beta 特性,默认启用相应的 `SeccompDefault` [特性门控](/zh-cn/docs/reference/command-line-tools-reference/feature-gates/)
348348
但是,你仍然需要为要使用它的每个节点启用此默认设置。
349349

350350
<!--
@@ -368,8 +368,6 @@ the minimum required Kubernetes version and enables the `SeccompDefault` feature
368368
```yaml
369369
kind: Cluster
370370
apiVersion: kind.x-k8s.io/v1alpha4
371-
featureGates:
372-
SeccompDefault: true
373371
nodes:
374372
- role: control-plane
375373
image: kindest/node:v1.23.0@sha256:49824ab1727c04e56a21a5d8372a402fcd32ea51ac96a2706a12af38934f81ac
@@ -386,7 +384,6 @@ nodes:
386384
kind: JoinConfiguration
387385
nodeRegistration:
388386
kubeletExtraArgs:
389-
feature-gates: SeccompDefault=true
390387
seccomp-default: "true"
391388
```
392389
@@ -439,11 +436,11 @@ type in the security context of a pod or container to `RuntimeDefault`.
439436

440437
{{< note >}}
441438
<!--
442-
If you have the `SeccompDefault` [feature gate](/docs/reference/command-line-tools-reference/feature-gates/)
439+
If you have the `seccompDefault` [configuration](/docs/reference/config-api/kubelet-config.v1beta1/)
443440
enabled, then Pods use the `RuntimeDefault` seccomp profile whenever
444441
no other seccomp profile is specified. Otherwise, the default is `Unconfined`.
445442
-->
446-
如果你已经启用了 `SeccompDefault` [特性门控](/zh-cn/docs/reference/command-line-tools-reference/feature-gates/)
443+
如果你已经启用了 `seccompDefault` [配置](/zh-cn/docs/reference/config-api/kubelet-config.v1beta1/)
447444
只要没有指定其他 seccomp 配置文件,那么 Pod 就会使用 `RuntimeDefault` seccomp 配置文件。
448445
否则,默认值为 `Unconfined`
449446
{{< /note >}}
@@ -506,26 +503,15 @@ Here's a manifest for that Pod:
506503

507504
{{< note >}}
508505
<!--
509-
The functional support for the already deprecated seccomp annotations
510-
`seccomp.security.alpha.kubernetes.io/pod` (for the whole pod) and
511-
`container.seccomp.security.alpha.kubernetes.io/[name]` (for a single container)
512-
is going to be removed with a future release of Kubernetes. Please always use
513-
the native API fields in favor of the annotations.
514-
515-
Since Kubernetes v1.25, kubelets no longer support the annotations, use of the
516-
annotations in static pods is no longer supported, and the seccomp annotations
517-
are no longer auto-populated when pods with seccomp fields are created.
518-
Auto-population of the seccomp fields from the annotations is planned to be
519-
removed in a future release.
520-
-->
521-
已弃用的 seccomp 注解 `seccomp.security.alpha.kubernetes.io/pod`(针对整个 Pod)和
522-
`container.seccomp.security.alpha.kubernetes.io/[name]`(针对单个容器)
523-
将随着未来 Kubernetes 的发布而被删除。
524-
请在可能的情况下使用原生 API 字段而不是注解。
525-
526-
从 Kubernetes v1.25 开始,kubelet 不再支持这些注解,
527-
也不再支持在静态 Pod 中使用注解,并且当创建带有 seccomp 字段的 Pod 时不再自动填充 seccomp 注解。
528-
从注释中自动填充 seccomp 字段的特性,将计划在未来的版本中删除。
506+
Older versions of Kubernetes allowed you to configure seccomp
507+
behavior using {{< glossary_tooltip text="annotations" term_id="annotation" >}}.
508+
Kubernetes {{< skew currentVersion >}} only supports using fields within
509+
`.spec.securityContext` to configure seccomp, and this tutorial explains that
510+
approach.
511+
-->
512+
旧版本的 Kubernetes 允许你使用{{< glossary_tooltip text="注解" term_id="annotation" >}}配置
513+
seccomp 行为。Kubernetes {{< skew currentVersion >}} 仅支持使用位于 `.spec.securityContext`
514+
内的字段来配置 seccomp。本教程将阐述这个方法。
529515
{{< /note >}}
530516

531517
<!--
@@ -592,6 +578,12 @@ container belonging to that control plane container:
592578
现在,你可以使用 `curl` 从 kind 控制平面容器内部访问该端点,位于该服务所公开的端口上。
593579
使用 `docker exec` 在属于该控制平面容器的容器中运行 `curl` 命令:
594580

581+
<!--
582+
```shell
583+
# Change 6a96207fed4b to the control plane container ID you saw from "docker ps"
584+
docker exec -it 6a96207fed4b curl localhost:32373
585+
```
586+
-->
595587
```shell
596588
# 将 6a96207fed4b 更改为你从 “docker ps” 看到的控制平面容器 ID
597589
docker exec -it 6a96207fed4b curl localhost:32373
@@ -625,6 +617,7 @@ For example:
625617
如果你在控制平面容器中 `curl` 端点,你会看到更多的写入。
626618

627619
例如:
620+
628621
```
629622
Jul 6 15:37:40 my-machine kernel: [369128.669452] audit: type=1326 audit(1594067860.484:14536): auid=4294967295 uid=0 gid=0 ses=4294967295 pid=29064 comm="http-echo" exe="/http-echo" sig=0 arch=c000003e syscall=51 compat=0 ip=0x46fe1f code=0x7ffc0000
630623
Jul 6 15:37:40 my-machine kernel: [369128.669453] audit: type=1326 audit(1594067860.484:14537): auid=4294967295 uid=0 gid=0 ses=4294967295 pid=29064 comm="http-echo" exe="/http-echo" sig=0 arch=c000003e syscall=54 compat=0 ip=0x46fdba code=0x7ffc0000
@@ -683,7 +676,7 @@ kubectl apply -f https://k8s.io/examples/pods/security/seccomp/ga/violation-pod.
683676
The Pod creates, but there is an issue.
684677
If you check the status of the Pod, you should see that it failed to start.
685678
-->
686-
Pod 创建,但存在问题。
679+
Pod 已创建,但存在问题。
687680
如果你检查 Pod 状态,你应该看到它没有启动。
688681

689682
```shell
@@ -732,7 +725,7 @@ The manifest for this example is:
732725
如果你看一看 `fine-grained.json` 配置文件,
733726
你会注意到第一个示例的 syslog 中看到的一些系统调用,
734727
其中配置文件设置为 `"defaultAction": "SCMP_ACT_LOG"`
735-
现在的配置文件设置 `"defaultAction": "SCMP_ACT_ERRNO"`,
728+
现在的配置文件设置 `"defaultAction": "SCMP_ACT_ERRNO"`
736729
但在 `"action": "SCMP_ACT_ALLOW"` 块中明确允许一组系统调用。
737730
理想情况下,容器将成功运行,并且你看到没有消息发送到 `syslog`
738731

@@ -769,6 +762,12 @@ mention calls from `http-echo`:
769762
-->
770763
打开一个新的终端窗口并使用 `tail` 来监视提到来自 `http-echo` 的调用的日志条目:
771764

765+
<!--
766+
```shell
767+
# The log path on your computer might be different from "/var/log/syslog"
768+
tail -f /var/log/syslog | grep 'http-echo'
769+
```
770+
-->
772771
```shell
773772
# 你计算机上的日志路径可能与 “/var/log/syslog” 不同
774773
tail -f /var/log/syslog | grep 'http-echo'
@@ -796,6 +795,7 @@ kubectl get service fine-pod
796795
The output is similar to:
797796
-->
798797
输出类似于:
798+
799799
```
800800
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
801801
fine-pod NodePort 10.111.36.142 <none> 5678:32373/TCP 72s
@@ -806,6 +806,12 @@ Use `curl` to access that endpoint from inside the kind control plane container:
806806
-->
807807
使用 `curl` 从 kind 控制平面容器内部访问端点:
808808

809+
<!--
810+
```shell
811+
# Change 6a96207fed4b to the control plane container ID you saw from "docker ps"
812+
docker exec -it 6a96207fed4b curl localhost:32373
813+
```
814+
-->
809815
```shell
810816
# 将 6a96207fed4b 更改为你从 “docker ps” 看到的控制平面容器 ID
811817
docker exec -it 6a96207fed4b curl localhost:32373
@@ -847,4 +853,4 @@ You can learn more about Linux seccomp:
847853
你可以了解有关 Linux seccomp 的更多信息:
848854

849855
* [seccomp 概述](https://lwn.net/Articles/656307/)
850-
* [Docker 的 Seccomp 安全配置文件](https://docs.docker.com/engine/security/seccomp/)
856+
* [Docker 的 Seccomp 安全配置文件](https://docs.docker.com/engine/security/seccomp/)

0 commit comments

Comments
 (0)