Skip to content

Commit edc6c4f

Browse files
committed
Add access-control-zh.md
1 parent 2c0cfed commit edc6c4f

5 files changed

Lines changed: 132 additions & 0 deletions

File tree

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
## 权限控制
2+
3+
### RBAC
4+
5+
https://kubernetes.io/docs/reference/access-authn-authz/rbac/
6+
7+
![](../images/rbac-example.png)
8+
9+
10+
### KS中的租户与资源层级
11+
12+
![](../images/resource-hierarchy.png)
13+
14+
15+
Platform: users、workspaces、clusters
16+
Cluster: nodes、workloads、namespaces
17+
Workspace: namespaces、apps
18+
Namesapce: workloads
19+
20+
### API Pattern
21+
22+
https://kubernetes.io/docs/reference/using-api/api-concepts/
23+
24+
```
25+
# KS API
26+
/kapis/{apiGroup}/{apiVersion}/{resourcePlural}/{resourceName}/{subResource}
27+
28+
# K8s 原生 API
29+
/apis/{apiGroup}/{apiVersion}/{resourcePlural}/{resourceName}/{subResource}
30+
/api/{apiGroup}/{apiVersion}/{resourcePlural}/{resourceName}/{subResource}
31+
32+
# 多集群分发
33+
/apis/clusters/{cluster}/{apiGroup}/{apiVersion}/{resourcePlural}/{resourceName}/{subResource}
34+
/kapis/clusters/{cluster}/{apiGroup}/{apiVersion}/{resourcePlural}/{resourceName}/{subResource}
35+
```
36+
37+
**API 示例**
38+
39+
Platform Scope
40+
41+
特殊的 CRD,这类资源被 host 集群管理,受到 GlobalRole 的限制
42+
43+
```
44+
/kapis/iam.kubesphere.io/users
45+
/kapis/resources.kubesphere.io/v1alpha3/clusters
46+
/kapis/tenant.kubesphere.io/workspaces
47+
```
48+
49+
Workspace Scope
50+
51+
KS 中的资源层级,受到 WorkspaceRole 的限制
52+
53+
```
54+
/kapis/openpitrix.kubesphere.io/workspaces/{workspace}/apps
55+
/kapis/tenant.kubesphere.io/workspaces/{workspace}/namespaces
56+
```
57+
58+
Cluster Scope
59+
60+
K8s 中的资源层级,收到 ClusterRole 的限制
61+
62+
```
63+
/api/v1/nodes
64+
/apis/apps/v1/deployments
65+
```
66+
67+
Namespace Scope
68+
69+
```
70+
/apis/apps/v1/namespaces/{namespace}/deployments
71+
```
72+
73+
### 插件的权限控制
74+
75+
KubeSphere 2.x
76+
77+
![](../images/rbac-2.x.png)
78+
79+
80+
KubeSphere 3.x
81+
82+
![](./../images/rbac-3.x.png)
83+
84+
KubeSphere 4.x
85+
86+
在 3.x 的基础之上进一步细化,授权粒度分为 创建(create)、查看(list、get、watch)、编辑(update、patch)、删除(delete)、管理(\*) 五个部分
87+
88+
授权项、功能模块可以动态拓展
89+
90+
** RoleTemplate **
91+
92+
```yaml
93+
apiVersion: iam.kubesphere.io/v1
94+
kind: RoleTemplate
95+
metadata:
96+
annotations:
97+
iam.kubesphere.io/scope: Platform
98+
iam.kubesphere.io/module: Access Control
99+
iam.kubesphere.io/rules: '{"users": "view"}'
100+
name: role-template-view-users
101+
102+
rules:
103+
- apiGroups:
104+
- '*'
105+
resources:
106+
- users
107+
verbs:
108+
- get
109+
- list
110+
- watch
111+
```
112+
113+
```yaml
114+
apiVersion: iam.kubesphere.io/v1
115+
kind: RoleTemplate
116+
metadata:
117+
annotations:
118+
iam.kubesphere.io/scope: Namespaced
119+
iam.kubesphere.io/module: Pipelines
120+
iam.kubesphere.io/rules: '{"pipelines": "view"}'
121+
name: role-template-view-pipelines
122+
123+
rules:
124+
- apiGroups:
125+
- 'devops.kubesphere.io'
126+
resources:
127+
- 'pipelines'
128+
verbs:
129+
- get
130+
- list
131+
- watch
132+
```
117 KB
Loading
77.5 KB
Loading
75.3 KB
Loading
131 KB
Loading

0 commit comments

Comments
 (0)