Skip to content

Commit 52ac6f8

Browse files
authored
Merge pull request #41451 from windsonsea/rbacy
[zh] sync /access-authn-authz/abac.md
2 parents 70577cc + ec1b0a3 commit 52ac6f8

File tree

1 file changed

+120
-131
lines changed
  • content/zh-cn/docs/reference/access-authn-authz

1 file changed

+120
-131
lines changed

content/zh-cn/docs/reference/access-authn-authz/abac.md

Lines changed: 120 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ weight: 80
2020
Attribute-based access control (ABAC) defines an access control paradigm whereby access rights are granted to users through the use of policies which combine attributes together.
2121
-->
2222
基于属性的访问控制(Attribute-based access control - ABAC)定义了访问控制范例,
23-
其中通过使用将属性组合在一起的策略来向用户授予访问权限。
24-
25-
23+
ABAC 通过使用将属性组合在一起的策略来向用户授予访问权限。
2624

2725
<!-- body -->
2826

@@ -36,68 +34,76 @@ should be no enclosing list or map, only one map per line.
3634
3735
Each line is a "policy object", where each such object is a map with the following
3836
properties:
39-
40-
- Versioning properties:
41-
- `apiVersion`, type string; valid values are "abac.authorization.kubernetes.io/v1beta1". Allows versioning and conversion of the policy format.
42-
- `kind`, type string: valid values are "Policy". Allows versioning and conversion of the policy format.
43-
- `spec` property set to a map with the following properties:
44-
- Subject-matching properties:
45-
- `user`, type string; the user-string from `--token-auth-file`. If you specify `user`, it must match the username of the authenticated user.
46-
- `group`, type string; if you specify `group`, it must match one of the groups of the authenticated user. `system:authenticated` matches all authenticated requests. `system:unauthenticated` matches all unauthenticated requests.
47-
- Resource-matching properties:
48-
- `apiGroup`, type string; an API group.
49-
- Ex: `apps`, `networking.k8s.io`
50-
- Wildcard: `*` matches all API groups.
51-
- `namespace`, type string; a namespace.
52-
- Ex: `kube-system`
53-
- Wildcard: `*` matches all resource requests.
54-
- `resource`, type string; a resource type
55-
- Ex: `pods`, `deployments`
56-
- Wildcard: `*` matches all resource requests.
57-
- Non-resource-matching properties:
58-
- `nonResourcePath`, type string; non-resource request paths.
59-
- Ex: `/version` or `/apis`
60-
- Wildcard:
61-
- `*` matches all non-resource requests.
62-
- `/foo/*` matches all subpaths of `/foo/`.
63-
- `readonly`, type boolean, when true, means that the Resource-matching policy only applies to get, list, and watch operations, Non-resource-matching policy only applies to get operation.
6437
-->
6538
## 策略文件格式 {#policy-file-format}
6639

67-
基于 `ABAC` 模式,可以这样指定策略文件 `--authorization-policy-file=SOME_FILENAME`
40+
要启用 `ABAC` 模式,可以在启动时指定 `--authorization-policy-file=SOME_FILENAME``--authorization-mode=ABAC`
6841

69-
此文件格式是 [JSON Lines](https://jsonlines.org/),不应存在外层的列表或映射,每行应只有一个映射。
42+
此文件格式是[每行一个 JSON 对象](https://jsonlines.org/),不应存在外层的列表或映射,每行应只有一个映射。
7043

71-
每一行都是一个策略对象,策略对象是具有以下属性的映射:
44+
每一行都是一个“策略对象”,策略对象是具有以下属性的映射:
7245

73-
- 版本控制属性:
74-
- `apiVersion`,字符串类型:有效值为 `abac.authorization.kubernetes.io/v1beta1`,允许对策略格式进行版本控制和转换。
75-
- `kind`,字符串类型:有效值为 `Policy`,允许对策略格式进行版本控制和转换。
76-
- `spec` 配置为具有以下映射的属性:
77-
- 主体匹配属性:
78-
- `user`,字符串类型;来自 `--token-auth-file` 的用户字符串,如果你指定 `user`,它必须与验证用户的用户名匹配。
79-
- `group`,字符串类型;如果指定 `group`,它必须与经过身份验证的用户的一个组匹配,`system:authenticated` 匹配所有经过身份验证的请求。
80-
`system:unauthenticated` 匹配所有未经过身份验证的请求。
46+
<!--
47+
- Versioning properties:
48+
- `apiVersion`, type string; valid values are "abac.authorization.kubernetes.io/v1beta1". Allows versioning and conversion of the policy format.
49+
- `kind`, type string: valid values are "Policy". Allows versioning and conversion of the policy format.
50+
-->
51+
- 版本控制属性:
52+
- `apiVersion`,字符串类型:有效值为 `abac.authorization.kubernetes.io/v1beta1`,允许对策略格式进行版本控制和转换。
53+
- `kind`,字符串类型:有效值为 `Policy`,允许对策略格式进行版本控制和转换。
54+
<!--
55+
- `spec` property set to a map with the following properties:
56+
- Subject-matching properties:
57+
- `user`, type string; the user-string from `--token-auth-file`. If you specify `user`, it must match the username of the authenticated user.
58+
- `group`, type string; if you specify `group`, it must match one of the groups of the authenticated user. `system:authenticated` matches all authenticated requests. `system:unauthenticated` matches all unauthenticated requests.
59+
-->
60+
- `spec` 配置为具有以下映射的属性:
61+
- 主体匹配属性:
62+
- `user`,字符串类型;来自 `--token-auth-file` 的用户字符串,如果你指定 `user`,它必须与验证用户的用户名匹配。
63+
- `group`,字符串类型;如果指定 `group`,它必须与经过身份验证的用户的一个组匹配,
64+
`system:authenticated` 匹配所有经过身份验证的请求。
65+
`system:unauthenticated` 匹配所有未经过身份验证的请求。
66+
<!--
67+
- Resource-matching properties:
68+
- `apiGroup`, type string; an API group.
69+
- Ex: `apps`, `networking.k8s.io`
70+
- Wildcard: `*` matches all API groups.
71+
- `namespace`, type string; a namespace.
72+
- Ex: `kube-system`
73+
- Wildcard: `*` matches all resource requests.
74+
- `resource`, type string; a resource type
75+
- Ex: `pods`, `deployments`
76+
- Wildcard: `*` matches all resource requests.
77+
-->
8178
- 资源匹配属性:
8279
- `apiGroup`,字符串类型;一个 API 组。
83-
- 例如:`apps``networking.k8s.io`
80+
- 例如:`apps``networking.k8s.io`
8481
- 通配符:`*`匹配所有 API 组。
8582
- `namespace`,字符串类型;一个命名空间。
8683
- 例如:`kube-system`
8784
- 通配符:`*`匹配所有资源请求。
8885
- `resource`,字符串类型;资源类型。
89-
- 例如:`pods``deployments`
86+
- 例如:`pods``deployments`
9087
- 通配符:`*`匹配所有资源请求。
88+
<!--
89+
- Non-resource-matching properties:
90+
- `nonResourcePath`, type string; non-resource request paths.
91+
- Ex: `/version` or `/apis`
92+
- Wildcard:
93+
- `*` matches all non-resource requests.
94+
- `/foo/*` matches all subpaths of `/foo/`.
95+
- `readonly`, type boolean, when true, means that the Resource-matching policy only applies to get, list, and watch operations, Non-resource-matching policy only applies to get operation.
96+
-->
9197
- 非资源匹配属性:
9298
- `nonResourcePath`,字符串类型;非资源请求路径。
9399
- 例如:`/version``/apis`
94100
- 通配符:
95101
- `*` 匹配所有非资源请求。
96102
- `/foo/*` 匹配 `/foo/` 的所有子路径。
97-
- `readonly`,键入布尔值,如果为 true,则表示该策略仅适用于 get、list 和 watch 操作。
103+
- `readonly`,布尔值类型。如果为 true,则表示该策略仅适用于 get、list 和 watch 操作。
104+
非资源匹配属性仅适用于 get 操作。
98105

99106
{{< note >}}
100-
101107
<!--
102108
An unset property is the same as a property set to the zero value for its type
103109
(e.g. empty string, 0, false). However, unset should be preferred for
@@ -106,10 +112,10 @@ readability.
106112
In the future, policies may be expressed in a JSON format, and managed via a
107113
REST interface.
108114
-->
109-
属性未设置等效于属性被设置为对应类型的零值( 例如空字符串、0、false),然而,出于可读性考虑,应尽量选择不设置这类属性。
115+
属性未设置等效于属性被设置为对应类型的零值(例如空字符串、0、false)。
116+
然而,出于可读性考虑,应尽量选择不设置这类属性。
110117

111118
在将来,策略可能以 JSON 格式表示,并通过 REST 界面进行管理。
112-
113119
{{< /note >}}
114120

115121
<!--
@@ -121,7 +127,16 @@ When a request is received, the attributes are determined. Unknown attributes
121127
are set to the zero value of its type (e.g. empty string, 0, false).
122128
123129
A property set to `"*"` will match any value of the corresponding attribute.
130+
-->
131+
## 鉴权算法 {#authorization-algorithm}
132+
133+
请求具有与策略对象的属性对应的属性。
134+
135+
当接收到请求时,属性是确定的。未知属性设置为其类型的零值(例如:空字符串、0、false)。
136+
137+
设置为 `"*"` 的属性将匹配相应属性的任何值。
124138

139+
<!--
125140
The tuple of attributes is checked for a match against every policy in the
126141
policy file. If at least one line matches the request attributes, then the
127142
request is authorized (but may fail later validation).
@@ -135,22 +150,15 @@ group property set to `"system:unauthenticated"`.
135150
To permit a user to do anything, write a policy with the apiGroup, namespace,
136151
resource, and nonResourcePath properties set to `"*"`.
137152
-->
138-
139-
## 鉴权算法 {#authorization-algorithm}
140-
141-
请求具有与策略对象的属性对应的属性。
142-
143-
当接收到请求时,确定属性。未知属性设置为其类型的零值(例如:空字符串,0,false)。
144-
145-
设置为 `"*"` 的属性将匹配相应属性的任何值。
146-
147-
检查属性的元组,以匹配策略文件中的每个策略。如果至少有一行匹配请求属性,则请求被鉴权(但仍可能无法通过稍后的合法性检查)。
153+
检查属性的元组,以匹配策略文件中的每个策略。如果至少有一行匹配请求属性,
154+
则请求被鉴权(但仍可能无法通过稍后的合法性检查)。
148155

149156
要允许任何经过身份验证的用户执行某些操作,请将策略组属性设置为 `"system:authenticated"`
150157

151158
要允许任何未经身份验证的用户执行某些操作,请将策略组属性设置为 `"system:unauthenticated"`
152159

153-
要允许用户执行任何操作,请使用设置为 `"*"` 的 apiGroup,namespace,resource 和 nonResourcePath 属性编写策略。
160+
要允许用户执行任何操作,请使用设置为 `"*"` 的 apiGroup、namespace、resource 和
161+
nonResourcePath 属性编写策略。
154162

155163
<!--
156164
## Kubectl
@@ -161,7 +169,16 @@ operations using schema information located at `/openapi/v2`.
161169
162170
When using ABAC authorization, those special resources have to be explicitly
163171
exposed via the `nonResourcePath` property in a policy (see [examples](#examples) below):
172+
-->
173+
## kubectl
174+
175+
kubectl 使用 apiserver 的 `/api``/apis` 端点来发现服务资源类型,
176+
并使用位于 `/openapi/v2` 的模式信息来验证通过创建/更新操作发送到 API 的对象。
164177

178+
当使用 ABAC 鉴权时,这些特殊资源必须显式地通过策略中的 `nonResourcePath` 属性暴露出来
179+
(参见下面的 [示例](#examples)):
180+
181+
<!--
165182
* `/api`, `/api/*`, `/apis`, and `/apis/*` for API version negotiation.
166183
* `/version` for retrieving the server version via `kubectl version`.
167184
* `/swaggerapi/*` for create/update operations.
@@ -171,132 +188,104 @@ up the verbosity:
171188
172189
kubectl --v=8 version
173190
-->
174-
175-
## kubectl
176-
177-
kubectl 使用 apiserver 的 `/api``/apis` 端点来发现服务资源类型,
178-
并使用位于 `/openapi/v2` 的模式信息来验证通过创建/更新操作发送到 API 的对象。
179-
180-
当使用 ABAC 鉴权时,这些特殊资源必须显式地通过策略中的 `nonResourcePath` 属性暴露出来(参见下面的 [示例](#examples)):
181-
182191
* `/api``/api/*``/apis``/apis/*` 用于 API 版本协商。
183192
* `/version` 通过 `kubectl version` 检索服务器版本。
184193
* `/swaggerapi/*` 用于创建 / 更新操作。
185194

186195
要检查涉及到特定 kubectl 操作的 HTTP 调用,你可以调整详细程度:
187-
kubectl --v=8 version
196+
197+
```shell
198+
kubectl --v=8 version
199+
```
188200

189201
<!--
190202
## Examples
191203
192-
1. Alice can do anything to all resources:
193-
194-
```json
195-
{"apiVersion": "abac.authorization.kubernetes.io/v1beta1", "kind": "Policy", "spec": {"user": "alice", "namespace": "*", "resource": "*", "apiGroup": "*"}}
196-
```
197-
2. The Kubelet can read any pods:
198-
199-
```json
200-
{"apiVersion": "abac.authorization.kubernetes.io/v1beta1", "kind": "Policy", "spec": {"user": "kubelet", "namespace": "*", "resource": "pods", "readonly": true}}
201-
```
202-
3. The Kubelet can read and write events:
203-
204-
```json
205-
{"apiVersion": "abac.authorization.kubernetes.io/v1beta1", "kind": "Policy", "spec": {"user": "kubelet", "namespace": "*", "resource": "events"}}
206-
```
207-
-->
204+
1. Alice can do anything to all resources:
205+
-->
208206
## 例子 {#examples}
209207

210208
1. Alice 可以对所有资源做任何事情:
211209

212-
```json
213-
{"apiVersion": "abac.authorization.kubernetes.io/v1beta1", "kind": "Policy", "spec": {"user": "alice", "namespace": "*", "resource": "*", "apiGroup": "*"}}
214-
```
215-
2. kubelet 可以读取任何 pod:
210+
```json
211+
{"apiVersion": "abac.authorization.kubernetes.io/v1beta1", "kind": "Policy", "spec": {"user": "alice", "namespace": "*", "resource": "*", "apiGroup": "*"}}
212+
```
216213

217-
```json
218-
{"apiVersion": "abac.authorization.kubernetes.io/v1beta1", "kind": "Policy", "spec": {"user": "kubelet", "namespace": "*", "resource": "pods", "readonly": true}}
219-
```
220-
3. kubelet 可以读写事件
214+
<!--
215+
2. The Kubelet can read any pods:
216+
-->
217+
2. kubelet 可以读取所有 Pod
221218

222-
```json
223-
{"apiVersion": "abac.authorization.kubernetes.io/v1beta1", "kind": "Policy", "spec": {"user": "kubelet", "namespace": "*", "resource": "events"}}
224-
```
219+
```json
220+
{"apiVersion": "abac.authorization.kubernetes.io/v1beta1", "kind": "Policy", "spec": {"user": "kubelet", "namespace": "*", "resource": "pods", "readonly": true}}
221+
```
225222

226-
<!--
227-
4. Bob can just read pods in namespace "projectCaribou":
223+
<!--
224+
3. The Kubelet can read and write events:
225+
-->
226+
3. kubelet 可以读写事件:
228227

229-
```json
230-
{"apiVersion": "abac.authorization.kubernetes.io/v1beta1", "kind": "Policy", "spec": {"user": "bob", "namespace": "projectCaribou", "resource": "pods", "readonly": true}}
231-
```
232-
5. Anyone can make read-only requests to all non-resource paths:
228+
```json
229+
{"apiVersion": "abac.authorization.kubernetes.io/v1beta1", "kind": "Policy", "spec": {"user": "kubelet", "namespace": "*", "resource": "events"}}
230+
```
233231

234-
```json
235-
{"apiVersion": "abac.authorization.kubernetes.io/v1beta1", "kind": "Policy", "spec": {"group": "system:authenticated", "readonly": true, "nonResourcePath": "*"}}
236-
{"apiVersion": "abac.authorization.kubernetes.io/v1beta1", "kind": "Policy", "spec": {"group": "system:unauthenticated", "readonly": true, "nonResourcePath": "*"}}
237-
```
232+
<!--
233+
4. Bob can just read pods in namespace "projectCaribou":
238234
-->
239-
4. Bob 可以在命名空间 `projectCaribou` 中读取 pod
235+
4. Bob 可以在命名空间 `projectCaribou` 中读取 Pod
240236

241-
```json
242-
{"apiVersion": "abac.authorization.kubernetes.io/v1beta1", "kind": "Policy", "spec": {"user": "bob", "namespace": "projectCaribou", "resource": "pods", "readonly": true}}
243-
```
237+
```json
238+
{"apiVersion": "abac.authorization.kubernetes.io/v1beta1", "kind": "Policy", "spec": {"user": "bob", "namespace": "projectCaribou", "resource": "pods", "readonly": true}}
239+
```
240+
241+
<!--
242+
5. Anyone can make read-only requests to all non-resource paths:
243+
-->
244244
5. 任何人都可以对所有非资源路径进行只读请求:
245245

246-
```json
247-
{"apiVersion": "abac.authorization.kubernetes.io/v1beta1", "kind": "Policy", "spec": {"group": "system:authenticated", "readonly": true, "nonResourcePath": "*"}}
248-
{"apiVersion": "abac.authorization.kubernetes.io/v1beta1", "kind": "Policy", "spec": {"group": "system:unauthenticated", "readonly": true, "nonResourcePath": "*"}}
249-
```
246+
```json
247+
{"apiVersion": "abac.authorization.kubernetes.io/v1beta1", "kind": "Policy", "spec": {"group": "system:authenticated", "readonly": true, "nonResourcePath": "*"}}
248+
{"apiVersion": "abac.authorization.kubernetes.io/v1beta1", "kind": "Policy", "spec": {"group": "system:unauthenticated", "readonly": true, "nonResourcePath": "*"}}
249+
```
250250

251251
<!--
252252
[Complete file example](https://releases.k8s.io/v{{< skew currentPatchVersion >}}/pkg/auth/authorizer/abac/example_policy_file.jsonl)
253253
254254
## A quick note on service accounts
255255
256256
Every service account has a corresponding ABAC username, and that service account's username is generated according to the naming convention:
257-
258-
```shell
259-
system:serviceaccount:<namespace>:<serviceaccountname>
260-
```
261-
262257
-->
263258
[完整文件示例](https://releases.k8s.io/v{{< skew currentPatchVersion >}}/pkg/auth/authorizer/abac/example_policy_file.jsonl)
264259

265-
## 服务帐户的快速说明 {#a-quick-note-on-service-accounts}
260+
## 服务账号的快速说明 {#a-quick-note-on-service-accounts}
266261

267-
服务帐户自动生成用户。用户名是根据命名约定生成的
262+
每个服务账号都有对应的 ABAC 用户名,服务账号的用户名是根据命名约定生成的
268263

269264
```shell
270265
system:serviceaccount:<namespace>:<serviceaccountname>
271266
```
272267

273268
<!--
274269
Creating a new namespace leads to the creation of a new service account in the following format:
270+
-->
271+
创建新的命名空间也会导致创建一个新的服务账号:
275272

276273
```shell
277274
system:serviceaccount:<namespace>:default
278275
```
279276

277+
<!--
280278
For example, if you wanted to grant the default service account (in the `kube-system` namespace) full
281279
privilege to the API using ABAC, you would add this line to your policy file:
280+
-->
281+
例如,如果你要使用 ABAC 将(`kube-system` 命名空间中)的默认服务账号完整权限授予 API,
282+
则可以将此行添加到策略文件中:
282283

283284
```json
284285
{"apiVersion":"abac.authorization.kubernetes.io/v1beta1","kind":"Policy","spec":{"user":"system:serviceaccount:kube-system:default","namespace":"*","resource":"*","apiGroup":"*"}}
285286
```
286287

288+
<!--
287289
The apiserver will need to be restarted to pick up the new policy lines.
288290
-->
289-
290-
创建新的命名空间也会导致创建一个新的服务帐户:
291-
292-
```shell
293-
system:serviceaccount:<namespace>:default
294-
```
295-
296-
例如,如果要将 API 的 kube-system 完整权限中的默认服务帐户授予,则可以将此行添加到策略文件中:
297-
298-
```json
299-
{"apiVersion":"abac.authorization.kubernetes.io/v1beta1","kind":"Policy","spec":{"user":"system:serviceaccount:kube-system:default","namespace":"*","resource":"*","apiGroup":"*"}}
300-
```
301-
302-
需要重新启动 apiserver 以获取新的策略行。
291+
API 服务器将需要被重新启动以获取新的策略行。

0 commit comments

Comments
 (0)