|NO.Z.00218|——————————|CloudNative|——|KuberNetes&细粒度权限控制.V02|——|RBAC.v02|role&ClusterRole|

一、rbac在安装k8s的时候就已经启用了
### --- rbac在安装的时候就已经启用它了
~~~     RBAC是可以接入第三方的。   

[root@k8s-master01 ~]# more /usr/lib/systemd/system/kube-apiserver.service 
[Service]
ExecStart=/usr/local/bin/kube-apiserver \
      --authorization-mode=Node,RBAC  \  // 基于RBAC认证已经启用了   
二、role只作用于namespace之下
### --- 查看Ingress-nginx的role

[root@k8s-master01 ~]# kubectl get role --all-namespaces
ingress-nginx          ingress-nginx                                    2021-04-21T16:09:29Z
[root@k8s-master01 ~]# kubectl get role -n ingress-nginx
[root@k8s-master01 ~]# kubectl get role -n ingress-nginx -oyaml
- apiVersion: rbac.authorization.k8s.io/v1
  kind: Role    
### --- 指定的role的类型是role

[root@k8s-master01 ~]# kubectl get role -n ingress-nginx ingress-nginx -oyaml 
kind: Role          
~~~     注:kind:是role
rules:
- apiGroups:                        // 这个角色是切片形式的,每个APIGroups是一个切片的集合。
  - ""
  resources:                        // 是对那些资源配置权限
  - namespaces          
  verbs:                            // verbs是权限的类型,作用于什么,get是只能查看
  - get
~~~     注:这是一个定义权限
- apiGroups:
  - ""
  resourceNames:                    // 这个resourceNames是只能对这一个configmaps进行更新和查看
  - ingress-controller-leader-nginx
  resources:                        // 也是对configmaps进行授权
  - configmaps
  verbs:                            // 操作类型是:get和update
  - get
  - update
~~~     注:这是一个更细维度的权限控制
- apiGroups:
  - ""
  resources:
  - configmaps
  verbs:
  - create
~~~     注:定义了对configmap的创建权限
- apiGroups:
  - ""
  resources:
  - endpoints
  verbs:
  - create
  - get
  - update
~~~     注:对endpoints进行授权的
三、ClusterRole:作用与所有的namespace
### --- 查看当前的ClusterRole
~~~     注:k8s内置的权限,可以查看整个集群的权限,就是可以查看整个namespace的所有资源

[root@k8s-master01 ~]# kubectl get clusterrole
view                                                                   2021-04-09T13:52:18Z 
### --- 导出view.的权限

[root@k8s-master01 ~]# kubectl get clusterrole view -oyaml > /tmp/view.yaml
 [root@k8s-master01 ~]# vim /tmp/view.yaml  
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole                   // 可以看到kind是ClusterRole权限 
#权限的规则的写法是一致的,就是类型不一样。 
rules:
- apiGroups:
  - ""
  resources:
  - configmaps
  - endpoints
  - persistentvolumeclaims
  - persistentvolumeclaims/status   // 这个status相当于PVC的下级资源
  - pods
  - replicationcontrollers
  - replicationcontrollers/scale        
  - serviceaccounts
  - services
  - services/status
  verbs:
  - get
  - list
  - watch
- apiGroups:
  - ""
  resources:
  - bindings
  - events
  - limitranges
  - namespaces/status
  - pods/log                        // 经常用到的是pods/log,
  - pods/status
  - replicationcontrollers/status
  - resourcequotas
  - resourcequotas/status
  verbs:
  - get                             // 查看
  - list                            // 列出所有资源
  - watch                           // 查看相当于w的权限

 
 
 
 
 
 
 
 
 

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

 

 

posted on 2022-03-31 12:55  yanqi_vip  阅读(39)  评论(0)    收藏  举报

导航