Skip to content

Commit 883668e

Browse files
authored
Merge pull request #29823 from howieyuen/concept-1
[zh]sync content/zh/docs/concepts/configuration/secret.md
2 parents d924a67 + 6aaf609 commit 883668e

File tree

1 file changed

+64
-46
lines changed
  • content/zh/docs/concepts/configuration

1 file changed

+64
-46
lines changed

content/zh/docs/concepts/configuration/secret.md

Lines changed: 64 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -22,47 +22,58 @@ weight: 30
2222

2323
<!-- overview -->
2424

25-
<!--
26-
Kubernetes `secret` objects let you store and manage sensitive information, such
27-
as passwords, OAuth tokens, and ssh keys. Putting this information in a `secret`
28-
is safer and more flexible than putting it verbatim in a
29-
{{< glossary_tooltip term_id="pod" >}} definition or in a
30-
{{< glossary_tooltip text="container image" term_id="image" >}}.
31-
See [Secrets design document](https://git.k8s.io/community/contributors/design-proposals/auth/secrets.md) for more information.
32-
-->
33-
34-
`Secret` 对象类型用来保存敏感信息,例如密码、OAuth 令牌和 SSH 密钥。
35-
将这些信息放在 `secret` 中比放在 {{< glossary_tooltip term_id="pod" >}} 的定义或者 {{< glossary_tooltip text="容器镜像" term_id="image" >}} 中来说更加安全和灵活。
36-
参阅 [Secret 设计文档](https://git.k8s.io/community/contributors/design-proposals/auth/secrets.md) 获取更多详细信息。
37-
3825
<!--
3926
A Secret is an object that contains a small amount of sensitive data such as
4027
a password, a token, or a key. Such information might otherwise be put in a
41-
Pod specification or in an image. Users can create Secrets and the system
42-
also creates some Secrets.
28+
{{< glossary_tooltip term_id="pod" >}} specification or in a
29+
{{< glossary_tooltip text="container image" term_id="image" >}}. Using a
30+
Secret means that you don't need to include confidential data in your
31+
application code.
4332
-->
4433
Secret 是一种包含少量敏感信息例如密码、令牌或密钥的对象。
45-
这样的信息可能会被放在 Pod 规约中或者镜像中。
46-
用户可以创建 Secret,同时系统也创建了一些 Secret。
34+
这样的信息可能会被放在 {{< glossary_tooltip term_id="pod" >}} 规约中或者镜像中。
35+
使用 Secret 意味着你不需要在应用程序代码中包含机密数据。
36+
37+
<!--
38+
Because Secrets can be created independently of the Pods that use them, there
39+
is less risk of the Secret (and its data) being exposed during the workflow of
40+
creating, viewing, and editing Pods. Kubernetes, and applications that run in
41+
your cluster, can also take additional precautions with Secrets, such as
42+
avoiding writing confidential data to nonvolatile storage.
43+
44+
Secrets are similar to {{< glossary_tooltip text="ConfigMaps" term_id="configmap" >}}
45+
but are specifically intended to hold confidential data.
46+
-->
47+
由于创建 Secret 可以独立于使用它们的 Pod,
48+
因此在创建、查看和编辑 Pod 的工作流程中暴露 Secret(及其数据)的风险较小。
49+
Kubernetes 和在集群中运行的应用程序也可以对 Secret 采取额外的预防措施,
50+
例如避免将机密数据写入非易失性存储。
51+
52+
Secret 类似于 {{<glossary_tooltip text="ConfigMap" term_id="configmap" >}}
53+
但专门用于保存机密数据。
4754

4855
{{< caution >}}
4956
<!--
50-
Kubernetes Secrets are, by default, stored as unencrypted base64-encoded
51-
strings. By default they can be retrieved - as plain text - by anyone with API
52-
access, or anyone with access to Kubernetes' underlying data store, etcd. In
53-
order to safely use Secrets, it is recommended you (at a minimum):
57+
Kubernetes Secrets are, by default, stored unencrypted in the API server's underlying data store (etcd). Anyone with API access can retrieve or modify a Secret, and so can anyone with access to etcd.
58+
Additionally, anyone who is authorized to create a Pod in a namespace can use that access to read any Secret in that namespace; this includes indirect access such as the ability to create a Deployment.
59+
60+
In order to safely use Secrets, take at least the following steps:
5461
55-
1. [Enable Encryption at Rest](/zh/docs/tasks/administer-cluster/encrypt-data/) for Secrets.
56-
2. [Enable or configure RBAC rules](/docs/reference/access-authn-authz/authorization/) that restrict reading and writing the Secret. Be aware that secrets can be obtained implicitly by anyone with the permission to create a Pod.
62+
1. [Enable Encryption at Rest](/docs/tasks/administer-cluster/encrypt-data/) for Secrets.
63+
2. Enable or configure [RBAC rules](/docs/reference/access-authn-authz/authorization/) that
64+
restrict reading data in Secrets (including via indirect means).
65+
3. Where appropriate, also use mechanisms such as RBAC to limit which principals are allowed to create new Secrets or replace existing ones.
5766
-->
58-
Kubernetes Secret 默认情况下存储为 base64-编码的、非加密的字符串。
59-
默认情况下,能够访问 API 的任何人,或者能够访问 Kubernetes 下层数据存储(etcd)
60-
的任何人都可以以明文形式读取这些数据。
61-
为了能够安全地使用 Secret,我们建议你(至少):
67+
默认情况下,Kubernetes Secret 未加密地存储在 API 服务器的底层数据存储(etcd)中。
68+
任何拥有 API 访问权限的人都可以检索或修改 Secret,任何有权访问 etcd 的人也可以。
69+
此外,任何有权限在命名空间中创建 Pod 的人都可以使用该访问权限读取该命名空间中的任何 Secret;
70+
这包括间接访问,例如创建 Deployment 的能力。
71+
72+
为了安全地使用 Secret,请至少执行以下步骤:
6273

6374
1. 为 Secret [启用静态加密](/zh/docs/tasks/administer-cluster/encrypt-data/)
64-
2. [启用 或配置 RBAC 规则](/zh/docs/reference/access-authn-authz/authorization/)来限制对 Secret 的读写操作
65-
要注意,任何被允许创建 Pod 的人都默认地具有读取 Secret 的权限
75+
2. 启用或配置 [RBAC 规则](/zh/docs/reference/access-authn-authz/authorization/)来限制读取 Secret 的数据(包括通过间接方式)
76+
3. 在适当的情况下,还可以使用 RBAC 等机制来限制允许哪些主体创建新 Secret 或替换现有 Secret
6677
{{< /caution >}}
6778

6879
<!-- body -->
@@ -89,6 +100,15 @@ Pod 可以用三种方式之一来使用 Secret:
89100
- 作为[容器的环境变量](#using-secrets-as-environment-variables)
90101
-[kubelet 在为 Pod 拉取镜像时使用](#using-imagepullsecrets)
91102

103+
<!--
104+
The Kubernetes control plane also uses Secrets; for example,
105+
[bootstrap token Secrets](#bootstrap-token-secrets) are a mechanism to
106+
help automate node registration.
107+
-->
108+
Kubernetes 控制平面也使用 Secret;
109+
例如,[引导令牌 Secret](#bootstrap-token-secrets)
110+
是一种帮助自动化节点注册的机制。
111+
92112
<!--
93113
The name of a Secret object must be a valid
94114
[DNS subdomain name](/docs/concepts/overview/working-with-objects/names#dns-subdomain-names).
@@ -108,20 +128,19 @@ Secret 对象的名称必须是合法的 [DNS 子域名](/zh/docs/concepts/overv
108128
## Types of Secret {#secret-types}
109129
110130
When creating a Secret, you can specify its type using the `type` field of
111-
the [`Secret`](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#secret-v1-core)
112-
resource, or certain equivalent `kubectl` command line flags (if available).
113-
The Secret type is used to facilitate programmatic handling of the Secret data.
131+
a Secret resource, or certain equivalent `kubectl` command line flags (if available).
132+
The `type` of a Secret is used to facilitate programmatic handling of different
133+
kinds of confidential data.
114134
115135
Kubernetes provides several builtin types for some common usage scenarios.
116136
These types vary in terms of the validations performed and the constraints
117137
Kubernetes imposes on them.
118138
-->
119139
## Secret 的类型 {#secret-types}
120140

121-
在创建 Secret 对象时,你可以使用
122-
[`Secret`](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#secret-v1-core)
123-
资源的 `type` 字段,或者与其等价的 `kubectl` 命令行参数(如果有的话)为其设置类型。
124-
Secret 的类型用来帮助编写程序处理 Secret 数据。
141+
创建 Secret 时,你可以使用 Secret 资源的 `type` 字段,
142+
或者与其等价的 `kubectl` 命令行参数(如果有的话)为其设置类型。
143+
Secret 的 `type` 有助于对不同类型机密数据的编程处理。
125144

126145
Kubernetes 提供若干种内置的类型,用于一些常见的使用场景。
127146
针对这些类型,Kubernetes 所执行的合法性检查操作以及对其所实施的限制各不相同。
@@ -553,13 +572,13 @@ kubectl create secret tls my-tls-secret \
553572
```
554573

555574
<!--
556-
The public/private key pair must exist before hand. The public key certificate
575+
The public/private key pair must exist beforehand. The public key certificate
557576
for `--cert` must be .PEM encoded (Base64-encoded DER format), and match the
558577
given private key for `--key`.
559578
The private key must be in what is commonly called PEM private key format,
560579
unencrypted. In both cases, the initial and the last lines from PEM (for
561580
example, `--------BEGIN CERTIFICATE-----` and `-------END CERTIFICATE----` for
562-
a cetificate) are *not* included.
581+
a certificate) are *not* included.
563582
-->
564583
这里的公钥/私钥对都必须事先已存在。用于 `--cert` 的公钥证书必须是 .PEM 编码的
565584
(Base64 编码的 DER 格式),且与 `--key` 所给定的私钥匹配。
@@ -1334,6 +1353,8 @@ This includes any pods created using kubectl, or indirectly via a replication
13341353
controller. It does not include pods created via the kubelets
13351354
`--manifest-url` flag, its `--config` flag, or its REST API (these are
13361355
not common ways to create pods.)
1356+
The `spec` of a {{< glossary_tooltip text="static Pod" term_id="static-pod" >}} cannot refer to a Secret
1357+
or any other API objects.
13371358
-->
13381359
每个 Secret 的大小限制为 1MB。这是为了防止创建非常大的 Secret 导致 API 服务器
13391360
和 kubelet 的内存耗尽。然而,创建过多较小的 Secret 也可能耗尽内存。
@@ -1343,6 +1364,8 @@ kubelet 仅支持从 API 服务器获得的 Pod 使用 Secret。
13431364
这包括使用 `kubectl` 创建的所有 Pod,以及间接通过副本控制器创建的 Pod。
13441365
它不包括通过 kubelet `--manifest-url` 标志,`--config` 标志或其 REST API
13451366
创建的 Pod(这些不是创建 Pod 的常用方法)。
1367+
{{<glossary_tooltip text="静态 Pod" term_id="static-pod" >}}
1368+
的 `spec` 不能引用 Secret 或任何其他 API 对象。
13461369

13471370
<!--
13481371
Secrets must be created before they are consumed in pods as environment
@@ -1829,7 +1852,7 @@ limited using [authorization policies](
18291852
Secrets often hold values that span a spectrum of importance, many of which can
18301853
cause escalations within Kubernetes (e.g. service account tokens) and to
18311854
external systems. Even if an individual app can reason about the power of the
1832-
secrets it expects to interact with, other apps within the same namespace can
1855+
Secrets it expects to interact with, other apps within the same namespace can
18331856
render those assumptions invalid.
18341857

18351858
For these reasons `watch` and `list` requests for secrets within a namespace are
@@ -1953,10 +1976,6 @@ for secret data, so that the secrets are not stored in the clear into {{< glossa
19531976
- A user who can create a pod that uses a secret can also see the value of that secret. Even
19541977
if apiserver policy does not allow that user to read the secret object, the user could
19551978
run a pod which exposes the secret.
1956-
- Currently, anyone with root on any node can read _any_ secret from the apiserver,
1957-
by impersonating the kubelet. It is a planned feature to only send secrets to
1958-
nodes that actually require them, to restrict the impact of a root exploit on a
1959-
single node.
19601979
-->
19611980
### 风险
19621981

@@ -1968,18 +1987,17 @@ for secret data, so that the secrets are not stored in the clear into {{< glossa
19681987
- 如果您将 Secret 数据编码为 base64 的清单(JSON 或 YAML)文件,共享该文件或将其检入代码库,该密码将会被泄露。 Base64 编码不是一种加密方式,应该视同纯文本。
19691988
- 应用程序在从卷中读取 Secret 后仍然需要保护 Secret 的值,例如不会意外将其写入日志或发送给不信任方。
19701989
- 可以创建使用 Secret 的 Pod 的用户也可以看到该 Secret 的值。即使 API 服务器策略不允许用户读取 Secret 对象,用户也可以运行 Pod 导致 Secret 暴露。
1971-
- 目前,任何节点的 root 用户都可以通过模拟 kubelet 来读取 API 服务器中的任何 Secret。
1972-
仅向实际需要 Secret 的节点发送 Secret 数据才能限制节点的 root 账号漏洞的影响,
1973-
该功能还在计划中。
19741990

19751991
## {{% heading "whatsnext" %}}
19761992

19771993
<!--
19781994
- Learn how to [manage Secret using `kubectl`](/docs/tasks/configmap-secret/managing-secret-using-kubectl/)
19791995
- Learn how to [manage Secret using config file](/docs/tasks/configmap-secret/managing-secret-using-config-file/)
19801996
- Learn how to [manage Secret using kustomize](/docs/tasks/configmap-secret/managing-secret-using-kustomize/)
1997+
- Read the [API reference](/docs/reference/kubernetes-api/config-and-storage-resources/secret-v1/) for `Secret`
19811998
-->
19821999
- 学习如何[使用 `kubectl` 管理 Secret](/zh/docs/tasks/configmap-secret/managing-secret-using-kubectl/)
19832000
- 学习如何[使用配置文件管理 Secret](/zh/docs/tasks/configmap-secret/managing-secret-using-config-file/)
19842001
- 学习如何[使用 kustomize 管理 Secret](/zh/docs/tasks/configmap-secret/managing-secret-using-kustomize/)
2002+
- 阅读 [API 参考](/zh/docs/reference/kubernetes-api/config-and-storage-resources/secret-v1/)了解 `Secret`
19852003

0 commit comments

Comments
 (0)