Skip to content

Commit 48c7322

Browse files
authored
Merge pull request #46132 from my-git9/pt-13426
[zh-cn] sync security/apparmor.md
2 parents 3a4c488 + 5fd25c7 commit 48c7322

File tree

1 file changed

+76
-96
lines changed

1 file changed

+76
-96
lines changed

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

Lines changed: 76 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -13,37 +13,17 @@ weight: 30
1313

1414
<!-- overview -->
1515

16-
{{< feature-state for_k8s_version="v1.4" state="beta" >}}
17-
18-
<!--
19-
[AppArmor](https://apparmor.net/) is a Linux kernel security module that supplements the standard Linux user and group based
20-
permissions to confine programs to a limited set of resources. AppArmor can be configured for any
21-
application to reduce its potential attack surface and provide greater in-depth defense. It is
22-
configured through profiles tuned to allow the access needed by a specific program or container,
23-
such as Linux capabilities, network access, file permissions, etc. Each profile can be run in either
24-
*enforcing* mode, which blocks access to disallowed resources, or *complain* mode, which only reports
25-
violations.
26-
-->
27-
[AppArmor](https://apparmor.net/) 是一个 Linux 内核安全模块,
28-
它补充了基于标准 Linux 用户和组的权限,将程序限制在一组有限的资源中。
29-
AppArmor 可以配置为任何应用程序减少潜在的攻击面,并且提供更加深入的防御。
30-
它通过调整配置文件进行配置,以允许特定程序或容器所需的访问,
31-
如 Linux 权能字、网络访问、文件权限等。
32-
每个配置文件都可以在 **强制(enforcing)**
33-
模式(阻止访问不允许的资源)或 **投诉(complain)** 模式(仅报告冲突)下运行。
34-
35-
<!--
36-
On Kubernetes, AppArmor can help you to run a more secure deployment by restricting what containers are allowed to
37-
do, and/or provide better auditing through system logs. However, it is important to keep in mind
38-
that AppArmor is not a silver bullet and can only do so much to protect against exploits in your
39-
application code. It is important to provide good, restrictive profiles, and harden your
40-
applications and cluster from other angles as well.
41-
-->
42-
在 Kubernetes 中,AppArmor 可以通过限制允许容器执行的操作,
43-
和/或通过系统日志提供更好的审计来帮助你运行更安全的部署。
44-
但是,重要的是要记住 AppArmor 不是灵丹妙药,
45-
只能做部分事情来防止应用程序代码中的漏洞。
46-
提供良好的限制性配置文件,并从其他角度强化你的应用程序和集群非常重要。
16+
{{< feature-state feature_gate_name="AppArmor" >}}
17+
18+
<!--
19+
This page shows you how to load AppArmor profiles on your nodes and enforce
20+
those profiles in Pods. To learn more about how Kubernetes can confine Pods using
21+
AppArmor, see
22+
[Linux kernel security constraints for Pods and containers](/docs/concepts/security/linux-kernel-security-constraints/#apparmor).
23+
-->
24+
本页面向你展示如何在节点上加载 AppArmor 配置文件并在 Pod 中强制应用这些配置文件。
25+
要了解有关 Kubernetes 如何使用 AppArmor 限制 Pod 的更多信息,请参阅
26+
[Pod 和容器的 Linux 内核安全约束](/zh-cn/docs/concepts/security/linux-kernel-security-constraints/#apparmor)
4727

4828
## {{% heading "objectives" %}}
4929

@@ -85,7 +65,7 @@ AppArmor 是一个可选的内核模块和 Kubernetes 特性,因此请在继
8565
```
8666

8767
<!--
88-
The Kubelet verifies that AppArmor is enabled on the host before admitting a pod with AppArmor
68+
The kubelet verifies that AppArmor is enabled on the host before admitting a pod with AppArmor
8969
explicitly configured.
9070
-->
9171
kubelet 会先验证主机上是否已启用 AppArmor,然后再接纳显式配置了 AppArmor 的 Pod。
@@ -103,7 +83,7 @@ AppArmor 是一个可选的内核模块和 Kubernetes 特性,因此请在继
10383
<!--
10484
3. Profile is loaded -- AppArmor is applied to a Pod by specifying an AppArmor profile that each
10585
container should be run with. If any of the specified profiles is not loaded in the
106-
kernel, the Kubelet will reject the Pod. You can view which profiles are loaded on a
86+
kernel, the kubelet will reject the Pod. You can view which profiles are loaded on a
10787
node by checking the `/sys/kernel/security/apparmor/profiles` file. For example:
10888
-->
10989
3. 配置文件已加载 —— 通过指定每个容器应使用的 AppArmor 配置文件,
@@ -139,44 +119,44 @@ AppArmor 是一个可选的内核模块和 Kubernetes 特性,因此请在继
139119

140120
{{< note >}}
141121
<!--
142-
AppArmor is currently in beta, so options are specified as annotations. Once support graduates to
143-
general availability, the annotations will be replaced with first-class fields.
122+
Prior to Kubernetes v1.30, AppArmor was specified through annotations. Use the documentation version
123+
selector to view the documentation with this deprecated API.
144124
-->
145-
AppArmor 目前处于 Beta 阶段,因此选项以注解形式设定
146-
一旦 AppArmor 支持进入正式发布阶段,注解将被替换为一阶的资源字段
125+
在 Kubernetes v1.30 之前,AppArmor 是通过注解指定的
126+
使用文档版本选择器查看包含此已弃用 API 的文档
147127
{{< /note >}}
148128

149129
<!--
150-
AppArmor profiles are specified *per-container*. To specify the AppArmor profile to run a Pod
151-
container with, add an annotation to the Pod's metadata:
130+
AppArmor profiles can be specified at the pod level or container level. The container AppArmor
131+
profile takes precedence over the pod profile.
152132
-->
153-
AppArmor 配置文件是按**逐个容器**的形式来设置的。
154-
要指定用来运行 Pod 容器的 AppArmor 配置文件,请向 Pod 的 metadata 添加注解:
133+
AppArmor 配置文件可以在 Pod 级别或容器级别指定。容器
134+
AppArmor 配置文件优先于 Pod 配置文件。
155135

156136
```yaml
157-
container.apparmor.security.beta.kubernetes.io/<container_name>: <profile_ref>
137+
securityContext:
138+
appArmorProfile:
139+
type: <profile_type>
158140
```
159141
160142
<!--
161-
Where `<container_name>` is the name of the container to apply the profile to, and `<profile_ref>`
162-
specifies the profile to apply. The `<profile_ref>` can be one of:
143+
Where `<profile_type>` is one of:
163144
-->
164-
`<container_name>` 的名称是配置文件所针对的容器的名称,`<profile_def>` 则设置要应用的配置文件。
165-
`<profile_ref>` 可以是以下取值之一:
145+
其中 `<profile_type>` 是以下之一:
166146

167147
<!--
168-
* `runtime/default` to apply the runtime's default profile
169-
* `localhost/<profile_name>` to apply the profile loaded on the host with the name `<profile_name>`
170-
* `unconfined` to indicate that no profiles will be loaded
148+
* `RuntimeDefault` to use the runtime's default profile
149+
* `Localhost` to use a profile loaded on the host (see below)
150+
* `Unconfined` to run without AppArmor
171151
-->
172-
* `runtime/default` 应用运行时的默认配置
173-
* `localhost/<profile_name>` 应用在主机上加载的名为 `<profile_name>` 的配置文件
174-
* `unconfined` 表示不加载配置文件
152+
* `RuntimeDefault` 使用运行时的默认配置文件
153+
* `Localhost` 使用主机上加载的配置文件(见下文)
154+
* `Unconfined` 无需 AppArmor 即可运行
175155

176156
<!--
177-
See the [API Reference](#api-reference) for the full details on the annotation and profile name formats.
157+
See the [API Reference](#api-reference) for the full details on the AppArmor profile API.
178158
-->
179-
有关注解和配置文件名称格式的详细信息,请参阅 [API 参考](#api-reference)。
159+
有关 AppArmor 配置文件 API 的完整详细信息,请参阅 [API 参考](#api-reference)。
180160

181161
<!--
182162
To verify that the profile was applied, you can check that the container's root process is
@@ -195,7 +175,7 @@ The output should look something like this:
195175
输出应如下所示:
196176

197177
```
198-
k8s-apparmor-example-deny-write (enforce)
178+
cri-containerd.apparmor.d (enforce)
199179
```
200180
201181
<!--
@@ -222,9 +202,9 @@ k8s-apparmor-example-deny-write (enforce)
222202
**本例假设你已经设置了一个集群使用 AppArmor 支持。**
223203

224204
<!--
225-
First, load the profile you want to use onto your Nodes. This profile denies all file writes:
205+
First, load the profile you want to use onto your Nodes. This profile blocks all file write operations:
226206
-->
227-
首先,将要使用的配置文件加载到节点上,此配置文件拒绝所有文件写入
207+
首先,将要使用的配置文件加载到节点上,该配置文件阻止所有文件写入操作
228208

229209
```
230210
#include <tunables/global>
@@ -323,9 +303,11 @@ apiVersion: v1
323303
kind: Pod
324304
metadata:
325305
name: hello-apparmor-2
326-
annotations:
327-
container.apparmor.security.beta.kubernetes.io/hello: localhost/k8s-apparmor-example-allow-write
328306
spec:
307+
securityContext:
308+
appArmorProfile:
309+
type: Localhost
310+
localhostProfile: k8s-apparmor-example-allow-write
329311
containers:
330312
- name: hello
331313
image: busybox:1.28
@@ -384,11 +366,11 @@ An Event provides the error message with the reason, the specific wording is run
384366
### 使用配置文件设置节点 {#setting-up-nodes-with-profiles}
385367

386368
<!--
387-
Kubernetes does not currently provide any built-in mechanisms for loading AppArmor profiles onto
369+
Kubernetes {{< skew currentVersion >}} does not currently provide any built-in mechanisms for loading AppArmor profiles onto
388370
Nodes. Profiles can be loaded through custom infrastructure or tools like the
389371
[Kubernetes Security Profiles Operator](https://github.com/kubernetes-sigs/security-profiles-operator).
390372
-->
391-
Kubernetes 目前不提供任何本地机制来将 AppArmor 配置文件加载到节点上。
373+
Kubernetes {{< skew currentVersion >}} 目前不提供任何本地机制来将 AppArmor 配置文件加载到节点上。
392374
可以通过自定义基础设施或工具(例如 [Kubernetes Security Profiles Operator](https://github.com/kubernetes-sigs/security-profiles-operator)
393375
加载配置文件。
394376

@@ -440,58 +422,56 @@ AppArmor 将详细消息记录到 `dmesg`,
440422
更多详细信息参见 [AppArmor 失败](https://gitlab.com/apparmor/apparmor/wikis/AppArmor_Failures)
441423

442424
<!--
443-
## API Reference
425+
## Specifying AppArmor confinement
444426
-->
445-
## API 参考 {#api-reference}
427+
## 指定 AppArmor 限制 {#specifying-apparmor-confinement}
446428

429+
{{< caution >}}
447430
<!--
448-
### Pod Annotation
431+
Prior to Kubernetes v1.30, AppArmor was specified through annotations. Use the documentation version
432+
selector to view the documentation with this deprecated API.
449433
-->
450-
### Pod 注解 {#pod-annotation}
434+
在 Kubernetes v1.30 之前,AppArmor 是通过注解指定的。使用文档版本选择器查看包含此已弃用 API 的文档。
435+
{{< /caution >}}
451436

452437
<!--
453-
Specifying the profile a container will run with:
438+
### AppArmor profile within security context {#appArmorProfile}
454439
-->
455-
指定容器将使用的配置文件:
440+
### 安全上下文中的 AppArmor 配置文件 {#appArmorProfile}
456441

457442
<!--
458-
- **key**: `container.apparmor.security.beta.kubernetes.io/<container_name>`
459-
Where `<container_name>` matches the name of a container in the Pod.
460-
A separate profile can be specified for each container in the Pod.
461-
- **value**: a profile reference, described below
462-
-->
463-
- **键名**`container.apparmor.security.beta.kubernetes.io/<container_name>`
464-
其中 `<container_name>` 与 Pod 中某容器的名称匹配。
465-
可以为 Pod 中的每个容器指定单独的配置文件。
466-
- **键值**:对配置文件的引用,如下所述
443+
You can specify the `appArmorProfile` on either a container's `securityContext` or on a Pod's
444+
`securityContext`. If the profile is set at the pod level, it will be used as the default profile
445+
for all containers in the pod (including init, sidecar, and ephemeral containers). If both a pod & container
446+
AppArmor profile are set, the container's profile will be used.
467447
468-
<!--
469-
### Profile Reference
448+
An AppArmor profile has 2 fields:
470449
-->
471-
### 配置文件引用 {#profile-reference}
450+
你可以在容器的 `securityContext` 或 Pod 的 `securityContext` 中设置 `appArmorProfile`
451+
如果在 Pod 级别设置配置文件,该配置将被用作 Pod 中所有容器(包括 Init、Sidecar 和临时容器)的默认配置文件。
452+
如果同时设置了 Pod 和容器 AppArmor 配置文件,则将使用容器的配置文件。
453+
454+
AppArmor 配置文件有 2 个字段:
472455

473456
<!--
474-
- `runtime/default`: Refers to the default runtime profile.
475-
- Equivalent to not specifying a profile, except it still requires AppArmor to be enabled.
476-
- In practice, many container runtimes use the same OCI default profile, defined here:
477-
https://github.com/containers/common/blob/main/pkg/apparmor/apparmor_linux_template.go
478-
- `localhost/<profile_name>`: Refers to a profile loaded on the node (localhost) by name.
479-
- The possible profile names are detailed in the
480-
[core policy reference](https://gitlab.com/apparmor/apparmor/wikis/AppArmor_Core_Policy_Reference#profile-names-and-attachment-specifications).
481-
- `unconfined`: This effectively disables AppArmor on the container.
457+
`type` _(required)_ - indicates which kind of AppArmor profile will be applied. Valid options are:
458+
- `Localhost` - a profile pre-loaded on the node (specified by `localhostProfile`).
459+
- `RuntimeDefault` - the container runtime's default profile.
460+
- `Unconfined` - no AppArmor enforcement.
482461
-->
483-
- `runtime/default`:指默认运行时配置文件。
484-
- 等同于不指定配置文件,只是它仍然需要启用 AppArmor。
485-
- 实际上,许多容器运行时使用相同的 OCI 默认配置文件,在此处定义:
486-
https://github.com/containers/common/blob/main/pkg/apparmor/apparmor_linux_template.go
487-
- `localhost/<profile_name>`:按名称引用加载到节点(localhost)上的配置文件。
488-
- 可能的配置文件名在[核心策略参考](https://gitlab.com/apparmor/apparmor/wikis/AppArmor_Core_Policy_Reference#profile-names-and-attachment-specifications)
489-
- `unconfined`:这相当于为容器禁用 AppArmor。
462+
`type` **(必需)** - 指示将应用哪种 AppArmor 配置文件。有效选项是:
463+
- `Localhost` - 节点上预加载的配置文件(由 `localhostProfile` 指定)。
464+
- `RuntimeDefault` - 容器运行时的默认配置文件。
465+
- `Unconfined` - 没有 AppArmor 强制执行。
490466

491467
<!--
492-
Any other profile reference format is invalid.
468+
`localhostProfile` - The name of a profile loaded on the node that should be used.
469+
The profile must be preconfigured on the node to work.
470+
This option must be provided if and only if the `type` is `Localhost`.
493471
-->
494-
任何其他配置文件引用格式无效。
472+
`localhostProfile` - 在节点上加载的、应被使用的配置文件的名称。
473+
该配置文件必须在节点上预先配置才能工作。
474+
当且仅当 `type``Localhost` 时,必须提供此选项。
495475

496476
## {{% heading "whatsnext" %}}
497477

0 commit comments

Comments
 (0)