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