role 分为clsterrole和role

我们从普通的role 开始理解起

  1. [root@master ~]# kubectl create role pod-read --verb=get,list,watch --resource=pods --dry-run -o yaml
  2. apiVersion: rbac.authorization.k8s.io/v1
  3. kind: Role
  4. metadata:
  5. creationTimestamp: null
  6. name: pod-read
  7. rules:
  8. - apiGroups:
  9. - ""
  10. resources:
  11. - pods
  12. verbs:
  13. - get
  14. - list
  15. - watch
  16. [root@master ~]# kubectl create rolebinding song-pod-read --role=pod-read --user=song --dry-run -o yaml
  17. apiVersion: rbac.authorization.k8s.io/v1
  18. kind: RoleBinding
  19. metadata:
  20. creationTimestamp: null
  21. name: song-pod-read
  22. roleRef:
  23. apiGroup: rbac.authorization.k8s.io
  24. kind: Role
  25. name: pod-read
  26. subjects:
  27. - apiGroup: rbac.authorization.k8s.io
  28. kind: User
  29. name: song
  30. [root@master ~]# kubectl create role pod-read --verb=get,list,watch --resource=pods
  31. role.rbac.authorization.k8s.io/pod-read created
  32. [root@master ~]# kubectl create rolebinding song-pod-read --role=pod-read --user=song
  33. rolebinding.rbac.authorization.k8s.io/song-pod-read created
    再次切换我们的song用户,发现他可以再default 命名空间中来查看pod
  34. [root@master ~]# kubectl config use-context song@kubernetes
  35. Switched to context "song@kubernetes".
  36. [root@master ~]# kubectl get pods
  37. NAME READY STATUS RESTARTS AGE
  38. debian-869994669d-226qq / Running 21d
  39. filebeat-ds-msmst / Running 23d
  40. filebeat-ds-qkpd9 / Running 23d
  41. haproxy-598b6697db-d7h6w / Running 22d
  42. myapp-deploy-7769f49474-c7w49 / Running 21d
  43. myapp-deploy-7769f49474-r6xjr / Running 21d
  44. myapp-deploy-7769f49474-rwhfc / Running 24d
  45. myapp-deploy-7769f49474-vgshx / Running 24d
  46. myapp-deploy-7769f49474-xcf9m / Running 24d
  47. mysqlxx-784fdd7b55-x9czr-69b97d59d4-slspx / Running 21d
  48. pod-demo / Running 19d
  49. pod-sa / Running 37h
  50. redis-85b846ff9c-h7j72 / Running 23d
  51. redis-state- / CrashLoopBackOff 11d
  52. redis-state- / CrashLoopBackOff 10d
  53. tomcat-test-76789745c5-42c5d / Running 30d
  54. tomcat-test-76789745c5-5wzl7 / Running

在全局还是没有权限。
  [root@master ~]# kubectl get pod --all-namespaces
  Error from server (Forbidden): pods is forbidden: User "song" cannot list resource "pods" in API group "" at the cluster scope

使用clusterrole给用户授予跨命名空间的大权限

  1. [root@master ~]# kubectl config use-context kubernetes-admin@kubernetes
  2. Switched to context "kubernetes-admin@kubernetes".
  3. [root@master ~]# kubectl delete rolebindings.rbac.authorization.k8s.io song-pod-read
  4. rolebinding.rbac.authorization.k8s.io "song-pod-read" deleted
  5. [root@master ~]# kubectl create clusterrole all-pod-read --verb=get,list,watch --resource=pods
  6. clusterrole.rbac.authorization.k8s.io/all-pod-read created
  7. [root@master ~]# kubectl create clusterrolebinding song-all-pod-read --clusterrole=all-pod-read --user=song
  8. clusterrolebinding.rbac.authorization.k8s.io/song-all-pod-read created
  9. [root@master ~]# kubectl config use-context song@kubernetes
  10. Switched to context "song@kubernetes".
  11. [root@master ~]# kubectl get pod --all-namespaces
  12. NAMESPACE NAME READY STATUS RESTARTS AGE
  13. default debian-869994669d-226qq / Running 21d
  14. default filebeat-ds-msmst / Running 23d
  15. default filebeat-ds-qkpd9 / Running 23d
  16. default haproxy-598b6697db-d7h6w / Running 22d
  17. default myapp-deploy-7769f49474-c7w49 / Running 21d
  18. default myapp-deploy-7769f49474-r6xjr / Running 21d
  19. default myapp-deploy-7769f49474-rwhfc / Running 24d
  20. default myapp-deploy-7769f49474-vgshx / Running 24d
  21. default myapp-deploy-7769f49474-xcf9m / Running 24d
  22. default mysqlxx-784fdd7b55-x9czr-69b97d59d4-slspx / Running 21d
  23. default pod-demo / Running 19d
  24. default pod-sa / Running 37h
  25. default redis-85b846ff9c-h7j72 / Running 23d
  26. default redis-state- / CrashLoopBackOff 11d
  27. default redis-state- / CrashLoopBackOff 10d
  28. default tomcat-test-76789745c5-42c5d / Running 30d
  29. default tomcat-test-76789745c5-5wzl7 / Running 21d
  30. ingress-nginx nginx-ingress-controller-797b884cbc-zcqsv / Running 20d
  31. kube-system coredns-86c58d9df4-gs9x7 / Running 32d
  32. kube-system coredns-86c58d9df4-srzb9 / Running 32d
  33. kube-system etcd-master / Running 32d
  34. kube-system kube-apiserver-master / Running 32d
  35. kube-system kube-controller-manager-master / Running 32d
  36. kube-system kube-flannel-ds-amd64-2fkc8 / Running 31d
  37. kube-system kube-flannel-ds-amd64-cmjjg / Running 31d
  38. kube-system kube-flannel-ds-amd64-t4b42 / Running 32d
  39. kube-system kube-proxy-mdmp5 / Running 31d
  40. kube-system kube-proxy-qjvhv / Running 31d
  41. kube-system kube-proxy-rkh97 / Running 32d
  42. kube-system kube-scheduler-master / Running 32d
  43. kube-system kubernetes-dashboard-57df4db6b-fw58v / ImagePullBackOff 18d

一般 clusterRoleBinding 用来绑定clsterRole   roleBinding 用来绑定  role

但是 roleBinding可以绑定  clusterRole  但是会造成 权限缩小到此命名空间

  1. [root@master ~]# kubectl delete clusterrolebindings.rbac.authorization.k8s.io song-all-pod-read
  2. clusterrolebinding.rbac.authorization.k8s.io "song-all-pod-read" deleted
  3. [root@master ~]# kubectl create rolebinding song-all-pod-read --clusterrole=all-pod-read --user=song
  4. rolebinding.rbac.authorization.k8s.io/song-all-pod-read created
  5. [root@master ~]# kubectl config use-context song@kubernetes
  6. Switched to context "song@kubernetes".
  7. [root@master ~]# kubectl get pod --all-namespaces
  8. Error from server (Forbidden): pods is forbidden: User "song" cannot list resource "pods" in API group "" at the cluster scope

集群最高权限查看

  1. [root@master ~]# kubectl describe clusterrole admin
  2. Name: admin
  3. Labels: kubernetes.io/bootstrapping=rbac-defaults
  4. Annotations: rbac.authorization.kubernetes.io/autoupdate: true
  5. PolicyRule:
  6. Resources Non-Resource URLs Resource Names Verbs
  7. --------- ----------------- -------------- -----
  8. rolebindings.rbac.authorization.k8s.io [] [] [create delete deletecollection get list patch update watch]
  9. roles.rbac.authorization.k8s.io [] [] [create delete deletecollection get list patch update watch]
  10. configmaps [] [] [create delete deletecollection patch update get list watch]
  11. endpoints [] [] [create delete deletecollection patch update get list watch]
  12. persistentvolumeclaims [] [] [create delete deletecollection patch update get list watch]
  13. pods [] [] [create delete deletecollection patch update get list watch]
  14. replicationcontrollers/scale [] [] [create delete deletecollection patch update get list watch]
  15. replicationcontrollers [] [] [create delete deletecollection patch update get list watch]
  16. services [] [] [create delete deletecollection patch update get list watch]
  17. daemonsets.apps [] [] [create delete deletecollection patch update get list watch]
  18. deployments.apps/scale [] [] [create delete deletecollection patch update get list watch]
  19. deployments.apps [] [] [create delete deletecollection patch update get list watch]
  20. replicasets.apps/scale [] [] [create delete deletecollection patch update get list watch]
  21. replicasets.apps [] [] [create delete deletecollection patch update get list watch]
  22. statefulsets.apps/scale [] [] [create delete deletecollection patch update get list watch]
  23. statefulsets.apps [] [] [create delete deletecollection patch update get list watch]
  24. horizontalpodautoscalers.autoscaling [] [] [create delete deletecollection patch update get list watch]
  25. cronjobs.batch [] [] [create delete deletecollection patch update get list watch]
  26. jobs.batch [] [] [create delete deletecollection patch update get list watch]
  27. daemonsets.extensions [] [] [create delete deletecollection patch update get list watch]
  28. deployments.extensions/scale [] [] [create delete deletecollection patch update get list watch]
  29. deployments.extensions [] [] [create delete deletecollection patch update get list watch]
  30. ingresses.extensions [] [] [create delete deletecollection patch update get list watch]
  31. networkpolicies.extensions [] [] [create delete deletecollection patch update get list watch]
  32. replicasets.extensions/scale [] [] [create delete deletecollection patch update get list watch]
  33. replicasets.extensions [] [] [create delete deletecollection patch update get list watch]
  34. replicationcontrollers.extensions/scale [] [] [create delete deletecollection patch update get list watch]
  35. networkpolicies.networking.k8s.io [] [] [create delete deletecollection patch update get list watch]
  36. poddisruptionbudgets.policy [] [] [create delete deletecollection patch update get list watch]
  37. deployments.apps/rollback [] [] [create delete deletecollection patch update]
  38. deployments.extensions/rollback [] [] [create delete deletecollection patch update]
  39. localsubjectaccessreviews.authorization.k8s.io [] [] [create]
  40. pods/attach [] [] [get list watch create delete deletecollection patch update]
  41. pods/exec [] [] [get list watch create delete deletecollection patch update]
  42. pods/portforward [] [] [get list watch create delete deletecollection patch update]
  43. pods/proxy [] [] [get list watch create delete deletecollection patch update]
  44. secrets [] [] [get list watch create delete deletecollection patch update]
  45. services/proxy [] [] [get list watch create delete deletecollection patch update]
  46. bindings [] [] [get list watch]
  47. events [] [] [get list watch]
  48. limitranges [] [] [get list watch]
  49. namespaces/status [] [] [get list watch]
  50. namespaces [] [] [get list watch]
  51. pods/log [] [] [get list watch]
  52. pods/status [] [] [get list watch]
  53. replicationcontrollers/status [] [] [get list watch]
  54. resourcequotas/status [] [] [get list watch]
  55. resourcequotas [] [] [get list watch]
  56. controllerrevisions.apps [] [] [get list watch]
  57. serviceaccounts [] [] [impersonate create delete deletecollection patch update get list watch]

[root@master ~]# kubectl describe clusterrole cluster-admin
Name: cluster-admin
Labels: kubernetes.io/bootstrapping=rbac-defaults
Annotations: rbac.authorization.kubernetes.io/autoupdate: true
PolicyRule:
Resources Non-Resource URLs Resource Names Verbs
--------- ----------------- -------------- -----
*.* [] [] [*]
[*] [] [*]

16.kubernetes的RBAC的更多相关文章

  1. 16. kubernetes RBAC

    16. kubernetes RBAC授权插件: Node,ABAC,RBAC,webhock RBAC: role based access contrl 基于角色的授权. 角色:(role)许可( ...

  2. Kubernetes之RBAC

    API Server的授权管理 API Server 内部通过用户认证后,然后进入授权流程.对合法用户进行授权并且随后在用户访问时进行鉴权,是权限管理的重要环节.API Server 目前支持一下几种 ...

  3. Kubernetes的RBAC是啥

    RBAC: Role-Based Access Control,基于角色的权限控制,有以下三种角色 Role:角色,它其实是一组规则,定义了一组API对象的操作权限 Subject:被作用者,可以是人 ...

  4. Kubernetes 基于 RBAC 的授权(十六)

    目录 一.RBAC介绍 1.1.角色和集群角色 1.2.RoleBinding 和 ClusterRoleBinding 1.3.资源 1.4.主体 二.命令行工具 2.1.kubectl creat ...

  5. K8S从入门到放弃系列-(16)Kubernetes集群Prometheus-operator监控部署

    Prometheus Operator不同于Prometheus,Prometheus Operator是 CoreOS 开源的一套用于管理在 Kubernetes 集群上的 Prometheus 控 ...

  6. 10、kubernetes之RBAC认证

    一.kubectl proxy # kubectl proxy --port=8080 # curl http://localhost:8080/api/v1/ # curl http://local ...

  7. kubernetes 1.6 RBAC访问控制

    一.简介 之前,Kubernetes中的授权策略主要是ABAC(Attribute-Based Access Control).对于ABAC,Kubernetes在实现上是比较难用的,而且需要Mast ...

  8. 二进制安装部署kubernetes集群---超详细教程

    本文收录在容器技术学习系列文章总目录 前言:本篇博客是博主踩过无数坑,反复查阅资料,一步步搭建完成后整理的个人心得,分享给大家~~~ 本文所需的安装包,都上传在我的网盘中,需要的可以打赏博主一杯咖啡钱 ...

  9. 手动部署 kubernetes HA 集群

    前言 关于kubernetes HA集群部署的方式有很多种(这里的HA指的是master apiserver的高可用),比如通过keepalived vip漂移的方式.haproxy/nginx负载均 ...

随机推荐

  1. Arcgis瓦片--数据获取

    Arcgis的二维地图瓦片有两种获取方式 1.在Arcmap中对配置好的地图进行切图,生成对应瓦片 2.使用第三方的地图下载器,直接下载,导出成arcgis瓦片格式即可使用. 备注:这里主要介绍第二种 ...

  2. c或c++利用scanf无限输入并进行简单操作如比大小等

    #include <iostream> using namespace std; int main() { ; ) //scanf返回值为int类型表示成功输入的数据数量个数 { if(n ...

  3. 对国内IoT的展望

    这个世界上让任何人最安心的,莫过于自己能够完全控制,反之什么都无法控制的,万念俱灰之下,最后只有自我了结.芸芸众生都是在这个之间徘徊,尽可能的去掌控,尽可能的去拥有,觉得能够安心,其实只是自由的内心被 ...

  4. 章节十、1-用ID和XPath、name定位元素

    一.在定位元素时需要HTML标签,HTML是超文本标记语言,我们打开web网页是看到的内容就是通过html语言来实现的,按键盘“F12”调用开发者选项后,“Elements”栏中显示的就是网页的HTM ...

  5. 01-vue学习之前的准备

    一.具备的基础知识 1.扎实的HTML/CSS/Javascript基本功,这是前置条件. 2.不要用任何的构建项目工具,只用最简单的<script>,把教程里的例子模仿一遍,理解用法.不 ...

  6. MySQL自增列(AUTO_INCREMENT)相关知识点总结

      MySQL的自增列(AUTO_INCREMENT)和其它数据库的自增列对比,有很多特性和不同点(甚至不同存储引擎.不同版本也有一些不同的特性),让人感觉有点稍微复杂.下面我们从一些测试开始,来认识 ...

  7. 修改vue element Transfer 穿梭框里内容区的宽度

    <template> <el-transfer v-model="value1" :data="data"></el-transf ...

  8. Asp.net Core应用程序部署为服务

    安装前使用dotnet命令运行下看网站能不能正常运行 1.下载nssm,下载后解压文件 下载地址:https://nssm.cc/usage 2.使用命令行工具进入到nssm的目录: 3.执行服务安装 ...

  9. mysql 的远程链接字符

    默认情况下,mysql只允许本地登录,如果要开启远程连接,则需要修改/etc/mysql/my.conf文件. 一.修改/etc/mysql/my.conf找到bind-address = 127.0 ...

  10. spark-2.4.0-hadoop2.7-高可用(HA)安装部署

    1. 主机规划 主机名称 IP地址 操作系统 部署软件 运行进程 备注 mini01 172.16.1.11[内网] 10.0.0.11  [外网] CentOS 7.5 Jdk-8.zookeepe ...