Skip to content

Commit b1e9fbe

Browse files
committed
[zh] cleanup page abac
1 parent 5cbcac4 commit b1e9fbe

File tree

1 file changed

+65
-54
lines changed
  • content/en/docs/reference/access-authn-authz

1 file changed

+65
-54
lines changed

content/en/docs/reference/access-authn-authz/abac.md

Lines changed: 65 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -10,43 +10,50 @@ weight: 80
1010
---
1111

1212
<!-- overview -->
13-
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.
13+
Attribute-based access control (ABAC) defines an access control paradigm whereby access rights are granted
14+
to users through the use of policies which combine attributes together.
1415

1516
<!-- body -->
1617
## Policy File Format
1718

18-
To enable `ABAC` mode, specify `--authorization-policy-file=SOME_FILENAME` and `--authorization-mode=ABAC` on startup.
19+
To enable `ABAC` mode, specify `--authorization-policy-file=SOME_FILENAME` and `--authorization-mode=ABAC`
20+
on startup.
1921

20-
The file format is [one JSON object per line](https://jsonlines.org/). There
22+
The file format is [one JSON object per line](https://jsonlines.org/). There
2123
should be no enclosing list or map, only one map per line.
2224

2325
Each line is a "policy object", where each such object is a map with the following
2426
properties:
2527

26-
- Versioning properties:
27-
- `apiVersion`, type string; valid values are "abac.authorization.kubernetes.io/v1beta1". Allows versioning and conversion of the policy format.
28-
- `kind`, type string: valid values are "Policy". Allows versioning and conversion of the policy format.
29-
- `spec` property set to a map with the following properties:
30-
- Subject-matching properties:
31-
- `user`, type string; the user-string from `--token-auth-file`. If you specify `user`, it must match the username of the authenticated user.
32-
- `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.
33-
- Resource-matching properties:
34-
- `apiGroup`, type string; an API group.
35-
- Ex: `apps`, `networking.k8s.io`
36-
- Wildcard: `*` matches all API groups.
37-
- `namespace`, type string; a namespace.
38-
- Ex: `kube-system`
39-
- Wildcard: `*` matches all resource requests.
40-
- `resource`, type string; a resource type
41-
- Ex: `pods`, `deployments`
42-
- Wildcard: `*` matches all resource requests.
43-
- Non-resource-matching properties:
44-
- `nonResourcePath`, type string; non-resource request paths.
45-
- Ex: `/version` or `/apis`
46-
- Wildcard:
47-
- `*` matches all non-resource requests.
48-
- `/foo/*` matches all subpaths of `/foo/`.
49-
- `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.
28+
- Versioning properties:
29+
- `apiVersion`, type string; valid values are "abac.authorization.kubernetes.io/v1beta1". Allows versioning
30+
and conversion of the policy format.
31+
- `kind`, type string: valid values are "Policy". Allows versioning and conversion of the policy format.
32+
- `spec` property set to a map with the following properties:
33+
- Subject-matching properties:
34+
- `user`, type string; the user-string from `--token-auth-file`. If you specify `user`, it must match the
35+
username of the authenticated user.
36+
- `group`, type string; if you specify `group`, it must match one of the groups of the authenticated user.
37+
`system:authenticated` matches all authenticated requests. `system:unauthenticated` matches all
38+
unauthenticated requests.
39+
- Resource-matching properties:
40+
- `apiGroup`, type string; an API group.
41+
- Ex: `apps`, `networking.k8s.io`
42+
- Wildcard: `*` matches all API groups.
43+
- `namespace`, type string; a namespace.
44+
- Ex: `kube-system`
45+
- Wildcard: `*` matches all resource requests.
46+
- `resource`, type string; a resource type
47+
- Ex: `pods`, `deployments`
48+
- Wildcard: `*` matches all resource requests.
49+
- Non-resource-matching properties:
50+
- `nonResourcePath`, type string; non-resource request paths.
51+
- Ex: `/version` or `/apis`
52+
- Wildcard:
53+
- `*` matches all non-resource requests.
54+
- `/foo/*` matches all subpaths of `/foo/`.
55+
- `readonly`, type boolean, when true, means that the Resource-matching policy only applies to get, list,
56+
and watch operations, Non-resource-matching policy only applies to get operation.
5057

5158
{{< note >}}
5259
An unset property is the same as a property set to the zero value for its type
@@ -61,7 +68,7 @@ REST interface.
6168

6269
A request has attributes which correspond to the properties of a policy object.
6370

64-
When a request is received, the attributes are determined. Unknown attributes
71+
When a request is received, the attributes are determined. Unknown attributes
6572
are set to the zero value of its type (e.g. empty string, 0, false).
6673

6774
A property set to `"*"` will match any value of the corresponding attribute.
@@ -95,42 +102,49 @@ exposed via the `nonResourcePath` property in a policy (see [examples](#examples
95102
To inspect the HTTP calls involved in a specific kubectl operation you can turn
96103
up the verbosity:
97104

98-
kubectl --v=8 version
105+
```shell
106+
kubectl --v=8 version
107+
```
99108

100109
## Examples
101110

102-
1. Alice can do anything to all resources:
111+
1. Alice can do anything to all resources:
112+
113+
```json
114+
{"apiVersion": "abac.authorization.kubernetes.io/v1beta1", "kind": "Policy", "spec": {"user": "alice", "namespace": "*", "resource": "*", "apiGroup": "*"}}
115+
```
116+
117+
1. The kubelet can read any pods:
118+
119+
```json
120+
{"apiVersion": "abac.authorization.kubernetes.io/v1beta1", "kind": "Policy", "spec": {"user": "kubelet", "namespace": "*", "resource": "pods", "readonly": true}}
121+
```
103122

104-
```json
105-
{"apiVersion": "abac.authorization.kubernetes.io/v1beta1", "kind": "Policy", "spec": {"user": "alice", "namespace": "*", "resource": "*", "apiGroup": "*"}}
106-
```
107-
2. The Kubelet can read any pods:
123+
1. The kubelet can read and write events:
108124

109-
```json
110-
{"apiVersion": "abac.authorization.kubernetes.io/v1beta1", "kind": "Policy", "spec": {"user": "kubelet", "namespace": "*", "resource": "pods", "readonly": true}}
111-
```
112-
3. The Kubelet can read and write events:
125+
```json
126+
{"apiVersion": "abac.authorization.kubernetes.io/v1beta1", "kind": "Policy", "spec": {"user": "kubelet", "namespace": "*", "resource": "events"}}
127+
```
113128

114-
```json
115-
{"apiVersion": "abac.authorization.kubernetes.io/v1beta1", "kind": "Policy", "spec": {"user": "kubelet", "namespace": "*", "resource": "events"}}
116-
```
117-
4. Bob can just read pods in namespace "projectCaribou":
129+
1. Bob can just read pods in namespace "projectCaribou":
118130

119-
```json
120-
{"apiVersion": "abac.authorization.kubernetes.io/v1beta1", "kind": "Policy", "spec": {"user": "bob", "namespace": "projectCaribou", "resource": "pods", "readonly": true}}
121-
```
122-
5. Anyone can make read-only requests to all non-resource paths:
131+
```json
132+
{"apiVersion": "abac.authorization.kubernetes.io/v1beta1", "kind": "Policy", "spec": {"user": "bob", "namespace": "projectCaribou", "resource": "pods", "readonly": true}}
133+
```
123134

124-
```json
125-
{"apiVersion": "abac.authorization.kubernetes.io/v1beta1", "kind": "Policy", "spec": {"group": "system:authenticated", "readonly": true, "nonResourcePath": "*"}}
135+
1. Anyone can make read-only requests to all non-resource paths:
136+
137+
```json
138+
{"apiVersion": "abac.authorization.kubernetes.io/v1beta1", "kind": "Policy", "spec": {"group": "system:authenticated", "readonly": true, "nonResourcePath": "*"}}
126139
{"apiVersion": "abac.authorization.kubernetes.io/v1beta1", "kind": "Policy", "spec": {"group": "system:unauthenticated", "readonly": true, "nonResourcePath": "*"}}
127-
```
140+
```
128141

129142
[Complete file example](https://releases.k8s.io/v{{< skew currentPatchVersion >}}/pkg/auth/authorizer/abac/example_policy_file.jsonl)
130143

131144
## A quick note on service accounts
132145

133-
Every service account has a corresponding ABAC username, and that service account's username is generated according to the naming convention:
146+
Every service account has a corresponding ABAC username, and that service account's username is generated
147+
according to the naming convention:
134148

135149
```shell
136150
system:serviceaccount:<namespace>:<serviceaccountname>
@@ -142,14 +156,11 @@ Creating a new namespace leads to the creation of a new service account in the f
142156
system:serviceaccount:<namespace>:default
143157
```
144158

145-
For example, if you wanted to grant the default service account (in the `kube-system` namespace) full
159+
For example, if you wanted to grant the default service account (in the `kube-system` namespace) full
146160
privilege to the API using ABAC, you would add this line to your policy file:
147161

148162
```json
149163
{"apiVersion":"abac.authorization.kubernetes.io/v1beta1","kind":"Policy","spec":{"user":"system:serviceaccount:kube-system:default","namespace":"*","resource":"*","apiGroup":"*"}}
150164
```
151165

152166
The apiserver will need to be restarted to pick up the new policy lines.
153-
154-
155-

0 commit comments

Comments
 (0)