1. 程式人生 > 其它 >|NO.Z.00223|——————————|CloudNative|——|KuberNetes&細粒度許可權控制.V07|------------------------------------------------|RBAC.v03|實驗例項|

|NO.Z.00223|——————————|CloudNative|——|KuberNetes&細粒度許可權控制.V07|------------------------------------------------|RBAC.v03|實驗例項|



[CloudNative:KuberNetes&細粒度許可權控制.V07]                                                    [Applications.KuberNetes] [|DevOps|k8s|細粒度許可權控制|RBAC|許可權管理應用|]








一、RBAC實驗例項
### --- RoleBinding下subjects示例
~~~     # subjects繫結到使用者
~~~     對於名為的使用者[email protected]:
~~~     以下示例是RoleBinding僅顯示本subjects節的摘錄。

subjects:
- kind: User                        // 繫結到一個使用者,
  name: "[email protected]"         // 這個使用者名稱是[email protected]
  apiGroup: rbac.authorization.k8s.io   
### --- subjects繫結到組

subjects:
- kind: Group                       // 繫結到前端的管理員的組
  name: "frontend-admins"           // 組的名稱
  apiGroup: rbac.authorization.k8s.io
### --- 繫結到kube-system名稱空間下的預設服務賬戶

subjects:
- kind: ServiceAccount              // 繫結到ServiceAccount
  name: default             
  namespace: kube-system            // ServiceAccount是需要指定namespace的;若是不指,就是當前的namespace
### --- 繫結所有的ServiceAccount到qa這個namespace下
~~~     注:就是一個namespace下,有很多個ServiceAccount,
~~~     這個namespace下的ServiceAccount就可以按組來分
~~~     可以把qa下的這個qa下的namespace下的所有的role的這個許可權都賦予給qa下的這個
~~~     namespace的ServiceAccount有多少個ServiceAccount,就有多少個許可權

subjects:
- kind: Group
  name: system:serviceaccounts:qa
  apiGroup: rbac.authorization.k8s.io
### --- 對於“開發”名稱空間中“開發”組中的所有服務帳戶:

subjects:
- kind: Group
  name: system:serviceaccounts:dev
  apiGroup: rbac.authorization.k8s.io
  namespace: development
### --- 沒有指定qa,就是對namespace下的所有的ServiceAccount都生效

subjects:
- kind: Group
  name: system:serviceaccounts:dev
  apiGroup: rbac.authorization.k8s.io
  namespace: development
### --- 對通過身份認證的使用者生效

subjects:
- kind: Group
  name: system:authenticated
  apiGroup: rbac.authorization.k8s.io
### --- 對於沒有經過身份認證的使用者生效,這個一般是不給它任何許可權的

subjects:
- kind: Group
  name: system:unauthenticated
  apiGroup: rbac.authorization.k8s.io
### --- 既包含已認證的又包含沒有經過認證的所有使用者生效

subjects:
- kind: Group
  name: system:authenticated
  apiGroup: rbac.authorization.k8s.io
- kind: Group
  name: system:unauthenticated
  apiGroup: rbac.authorization.k8s.io
二、對於RoleBinding的建立和授權的限制:就是RoleBinding誰去操作,一般都是管理員去操作
### --- 例如,這ClusterRole和RoleBinding將允許user-1授予其他使用者admin,
~~~     edit和view角色的名稱空間user-1-namespace
~~~     注:這個是管理員來操作,若是管理員很多的話,就會建立配置

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: role-grantor            // 使用者role-grantor
rules:
- apiGroups: ["rbac.authorization.k8s.io"]      
  resources: ["rolebindings"]
  verbs: ["create"]
- apiGroups: ["rbac.authorization.k8s.io"]
  resources: ["clusterroles"]
  verbs: ["bind"]               // 對這個RoleBinding有bind的許可權
  # omit resourceNames to allow binding any ClusterRole
  resourceNames: ["admin","edit","view"]                
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: role-grantor-binding
  namespace: user-1-namespace
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: role-grantor
subjects:
- apiGroup: rbac.authorization.k8s.io
  kind: User
  name: user-1








===============================END===============================


Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart                                                                                                                                                    ——W.S.Landor



來自為知筆記(Wiz)