天天看點

帶你讀《雲原生應用開發 Operator原理與實踐》第二章 Operator 原理2.3 Kube-APIServer 介紹(五)

(1)      RoleBinding和 ClusterRoleBinding

RoleBinding向使用者或一組使用者授予在角色中定義的權限。它包含主題清單(使用者、組或服務賬戶),以及對所授予角色的引用。RoleBinding授予特定Namespace内的權限,而 ClusterRoleBinding授予在叢集範圍内通路的權限。

RoleBinding可以引用同一 Namespace中的任何 Role。 或者,RoleBinding可以引 用 ClusterRole并 将 該 ClusterRole綁 定 到 RoleBinding的 Namespace。 如 果 要 将ClusterRole綁定到叢集中的所有 Namespace,要使用 ClusterRoleBinding。

代碼清單2-71是一個 RoleBinding的示例。

apiVersion:rbac.authorization.k8s.io/v1kind:RoleBinding

metadata:

name:ns-admin-rolebindingnamespace:myspace

roleRef:

apiGroup:rbac.authorization.k8s.iokind:Role

name:ns-adminsubjects:

-  apiGroup:rbac.authorization.k8s.iokind:User

name:kcp

要在叢集範圍内完成通路權限的鑒權,可以使用一個ClusterRoleBinding(見代碼清單2-72)。

apiVersion:rbac.authorization.k8s.io/v1kind:ClusterRoleBinding

name:system:corednsroleRef:

apiGroup:rbac.authorization.k8s.iokind:ClusterRole

name:system:corednssubjects:

-  kind:ServiceAccountname:corednsnamespace:kube-system

1. Node鑒權

Node鑒權是一種專用授權模式,專門對 Kubelet發出的 API 請求進行鑒權。Node鑒權允許 Kubelet對多種資源有操作權限,例如,Services、Endpoints、Nodes、Pods等資源。使用 system:node組對Kubelet元件進行權限控制,要使用 Node鑒權,需要在APIServer啟動參數中添加--authorization-mode=Node,RBAC。

2. WebHook模式

WebHook鑒權基于 HTTP的回調機制,這個子產品在做決策時,APIServer會向遠端鑒權伺服器發送一個 POST請求,請求體是一個SubjectAccessReview對象,這個對象中包含了描述使用者請求的資源,同時也包含了被通路資源或請求的具體資訊。要啟用WebHook鑒權,需要添加如下參數。

(1)--authorization-webhook-config-file=:這是一個 kubeconfig格式的配置檔案,user字段引用的是 apiserverwebhook,clusters字段引用的是遠端服務。

(2)--authorization-mode=Node,RBAC:啟用 WebHook鑒權。

繼續閱讀