@@ -20,9 +20,7 @@ weight: 80
20
20
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.
21
21
-->
22
22
基于属性的访问控制(Attribute-based access control - ABAC)定义了访问控制范例,
23
- 其中通过使用将属性组合在一起的策略来向用户授予访问权限。
24
-
25
-
23
+ ABAC 通过使用将属性组合在一起的策略来向用户授予访问权限。
26
24
27
25
<!-- body -->
28
26
@@ -36,68 +34,76 @@ should be no enclosing list or map, only one map per line.
36
34
37
35
Each line is a "policy object", where each such object is a map with the following
38
36
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.
64
37
-->
65
38
## 策略文件格式 {#policy-file-format}
66
39
67
- 基于 ` ABAC ` 模式,可以这样指定策略文件 ` --authorization-policy-file=SOME_FILENAME ` 。
40
+ 要启用 ` ABAC ` 模式,可以在启动时指定 ` --authorization-policy-file=SOME_FILENAME ` 和 ` --authorization-mode=ABAC ` 。
68
41
69
- 此文件格式是 [ JSON Lines ] ( https://jsonlines.org/ ) ,不应存在外层的列表或映射,每行应只有一个映射。
42
+ 此文件格式是[ 每行一个 JSON 对象 ] ( https://jsonlines.org/ ) ,不应存在外层的列表或映射,每行应只有一个映射。
70
43
71
- 每一行都是一个策略对象 ,策略对象是具有以下属性的映射:
44
+ 每一行都是一个“策略对象” ,策略对象是具有以下属性的映射:
72
45
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
+ -->
81
78
- 资源匹配属性:
82
79
- ` apiGroup ` ,字符串类型;一个 API 组。
83
- - 例如:` apps ` , ` networking.k8s.io `
80
+ - 例如:` apps ` 、 ` networking.k8s.io `
84
81
- 通配符:` * ` 匹配所有 API 组。
85
82
- ` namespace ` ,字符串类型;一个命名空间。
86
83
- 例如:` kube-system `
87
84
- 通配符:` * ` 匹配所有资源请求。
88
85
- ` resource ` ,字符串类型;资源类型。
89
- - 例如:` pods ` , ` deployments `
86
+ - 例如:` pods ` 、 ` deployments `
90
87
- 通配符:` * ` 匹配所有资源请求。
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
+ -->
91
97
- 非资源匹配属性:
92
98
- ` nonResourcePath ` ,字符串类型;非资源请求路径。
93
99
- 例如:` /version ` 或 ` /apis `
94
100
- 通配符:
95
101
- ` * ` 匹配所有非资源请求。
96
102
- ` /foo/* ` 匹配 ` /foo/ ` 的所有子路径。
97
- - ` readonly ` ,键入布尔值,如果为 true,则表示该策略仅适用于 get、list 和 watch 操作。
103
+ - ` readonly ` ,布尔值类型。如果为 true,则表示该策略仅适用于 get、list 和 watch 操作。
104
+ 非资源匹配属性仅适用于 get 操作。
98
105
99
106
{{< note >}}
100
-
101
107
<!--
102
108
An unset property is the same as a property set to the zero value for its type
103
109
(e.g. empty string, 0, false). However, unset should be preferred for
@@ -106,10 +112,10 @@ readability.
106
112
In the future, policies may be expressed in a JSON format, and managed via a
107
113
REST interface.
108
114
-->
109
- 属性未设置等效于属性被设置为对应类型的零值( 例如空字符串、0、false),然而,出于可读性考虑,应尽量选择不设置这类属性。
115
+ 属性未设置等效于属性被设置为对应类型的零值(例如空字符串、0、false)。
116
+ 然而,出于可读性考虑,应尽量选择不设置这类属性。
110
117
111
118
在将来,策略可能以 JSON 格式表示,并通过 REST 界面进行管理。
112
-
113
119
{{< /note >}}
114
120
115
121
<!--
@@ -121,7 +127,16 @@ When a request is received, the attributes are determined. Unknown attributes
121
127
are set to the zero value of its type (e.g. empty string, 0, false).
122
128
123
129
A property set to `"*"` will match any value of the corresponding attribute.
130
+ -->
131
+ ## 鉴权算法 {#authorization-algorithm}
132
+
133
+ 请求具有与策略对象的属性对应的属性。
134
+
135
+ 当接收到请求时,属性是确定的。未知属性设置为其类型的零值(例如:空字符串、0、false)。
136
+
137
+ 设置为 ` "*" ` 的属性将匹配相应属性的任何值。
124
138
139
+ <!--
125
140
The tuple of attributes is checked for a match against every policy in the
126
141
policy file. If at least one line matches the request attributes, then the
127
142
request is authorized (but may fail later validation).
@@ -135,22 +150,15 @@ group property set to `"system:unauthenticated"`.
135
150
To permit a user to do anything, write a policy with the apiGroup, namespace,
136
151
resource, and nonResourcePath properties set to `"*"`.
137
152
-->
138
-
139
- ## 鉴权算法 {#authorization-algorithm}
140
-
141
- 请求具有与策略对象的属性对应的属性。
142
-
143
- 当接收到请求时,确定属性。未知属性设置为其类型的零值(例如:空字符串,0,false)。
144
-
145
- 设置为 ` "*" ` 的属性将匹配相应属性的任何值。
146
-
147
- 检查属性的元组,以匹配策略文件中的每个策略。如果至少有一行匹配请求属性,则请求被鉴权(但仍可能无法通过稍后的合法性检查)。
153
+ 检查属性的元组,以匹配策略文件中的每个策略。如果至少有一行匹配请求属性,
154
+ 则请求被鉴权(但仍可能无法通过稍后的合法性检查)。
148
155
149
156
要允许任何经过身份验证的用户执行某些操作,请将策略组属性设置为 ` "system:authenticated" ` 。
150
157
151
158
要允许任何未经身份验证的用户执行某些操作,请将策略组属性设置为 ` "system:unauthenticated" ` 。
152
159
153
- 要允许用户执行任何操作,请使用设置为 ` "*" ` 的 apiGroup,namespace,resource 和 nonResourcePath 属性编写策略。
160
+ 要允许用户执行任何操作,请使用设置为 ` "*" ` 的 apiGroup、namespace、resource 和
161
+ nonResourcePath 属性编写策略。
154
162
155
163
<!--
156
164
## Kubectl
@@ -161,7 +169,16 @@ operations using schema information located at `/openapi/v2`.
161
169
162
170
When using ABAC authorization, those special resources have to be explicitly
163
171
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 的对象。
164
177
178
+ 当使用 ABAC 鉴权时,这些特殊资源必须显式地通过策略中的 ` nonResourcePath ` 属性暴露出来
179
+ (参见下面的 [ 示例] ( #examples ) ):
180
+
181
+ <!--
165
182
* `/api`, `/api/*`, `/apis`, and `/apis/*` for API version negotiation.
166
183
* `/version` for retrieving the server version via `kubectl version`.
167
184
* `/swaggerapi/*` for create/update operations.
@@ -171,132 +188,104 @@ up the verbosity:
171
188
172
189
kubectl --v=8 version
173
190
-->
174
-
175
- ## kubectl
176
-
177
- kubectl 使用 apiserver 的 ` /api ` 和 ` /apis ` 端点来发现服务资源类型,
178
- 并使用位于 ` /openapi/v2 ` 的模式信息来验证通过创建/更新操作发送到 API 的对象。
179
-
180
- 当使用 ABAC 鉴权时,这些特殊资源必须显式地通过策略中的 ` nonResourcePath ` 属性暴露出来(参见下面的 [ 示例] ( #examples ) ):
181
-
182
191
* ` /api ` ,` /api/* ` ,` /apis ` 和 ` /apis/* ` 用于 API 版本协商。
183
192
* ` /version ` 通过 ` kubectl version ` 检索服务器版本。
184
193
* ` /swaggerapi/* ` 用于创建 / 更新操作。
185
194
186
195
要检查涉及到特定 kubectl 操作的 HTTP 调用,你可以调整详细程度:
187
- kubectl --v=8 version
196
+
197
+ ``` shell
198
+ kubectl --v=8 version
199
+ ```
188
200
189
201
<!--
190
202
## Examples
191
203
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
+ -->
208
206
## 例子 {#examples}
209
207
210
208
1 . Alice 可以对所有资源做任何事情:
211
209
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
+ ```
216
213
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 :
221
218
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
+ ```
225
222
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 可以读写事件:
228
227
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
+ ```
233
231
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":
238
234
-->
239
- 4 . Bob 可以在命名空间 `projectCaribou` 中读取 pod :
235
+ 4 . Bob 可以在命名空间 ` projectCaribou ` 中读取 Pod :
240
236
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
+ -->
244
244
5 . 任何人都可以对所有非资源路径进行只读请求:
245
245
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
+ ```
250
250
251
251
<!--
252
252
[Complete file example](https://releases.k8s.io/v{{< skew currentPatchVersion >}}/pkg/auth/authorizer/abac/example_policy_file.jsonl)
253
253
254
254
## A quick note on service accounts
255
255
256
256
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
-
262
257
-->
263
258
[ 完整文件示例] (https://releases.k8s.io/v{{ < skew currentPatchVersion >}}/pkg/auth/authorizer/abac/example_policy_file.jsonl)
264
259
265
- ## 服务帐户的快速说明 {#a-quick-note-on-service-accounts}
260
+ ## 服务账号的快速说明 {#a-quick-note-on-service-accounts}
266
261
267
- 服务帐户自动生成用户。用户名是根据命名约定生成的 :
262
+ 每个服务账号都有对应的 ABAC 用户名,服务账号的用户名是根据命名约定生成的 :
268
263
269
264
``` shell
270
265
system:serviceaccount:< namespace> :< serviceaccountname>
271
266
```
272
267
273
268
<!--
274
269
Creating a new namespace leads to the creation of a new service account in the following format:
270
+ -->
271
+ 创建新的命名空间也会导致创建一个新的服务账号:
275
272
276
273
``` shell
277
274
system:serviceaccount:< namespace> :default
278
275
```
279
276
277
+ <!--
280
278
For example, if you wanted to grant the default service account (in the `kube-system` namespace) full
281
279
privilege to the API using ABAC, you would add this line to your policy file:
280
+ -->
281
+ 例如,如果你要使用 ABAC 将(` kube-system ` 命名空间中)的默认服务账号完整权限授予 API,
282
+ 则可以将此行添加到策略文件中:
282
283
283
284
``` json
284
285
{"apiVersion" :" abac.authorization.kubernetes.io/v1beta1" ,"kind" :" Policy" ,"spec" :{"user" :" system:serviceaccount:kube-system:default" ,"namespace" :" *" ,"resource" :" *" ,"apiGroup" :" *" }}
285
286
```
286
287
288
+ <!--
287
289
The apiserver will need to be restarted to pick up the new policy lines.
288
290
-->
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