当前位置:网站首页>RBAC of kubernetes authority management (1)
RBAC of kubernetes authority management (1)
2020-11-09 16:56:00 【Ruijiang cloud computing】
k8s In enabling role-based access control RBAC(Role-based-Access-Control) Authorization mode of . Equivalent to property based access control ABAC(Attribute-based Access Control),RBAC Mainly introduced role (Role Set of authorities ) Bind to the role (RoleBinding) Abstract concept of . stay ABAC in ,k8s Access policies in a cluster can only be directly associated with users ; and RBAC in , Access policies can be associated with a role , Specific users are associated with a role or multiple roles .
RBAC There are four new k8s Top level resource object : role (Role)、 The cluster character (ClusterRole)、 Character binding (RoleBinding)、 Cluster role binding (ClusterRoleBinding). Same as others API Resource objects are the same , Users can use kubectl perhaps API Call mode and so on to operate these resource objects .
RBAC It has the following advantages .
1、 Complete coverage of resource and non resource permissions in the cluster .
2、 Whole RBAC It's all about a few API Object complete , Same as others API object , It can be used kubectl or API To operate .
3、 It can be adjusted at runtime , No need to restart API Server.
4、 To use RBAC Authorization mode , be Need to be in API Server Start of Parameters in add --authorization-mode=RBAC.
1) role ( Role)
A role is a set of permissions , The permissions here are in the form of permission , There is no rule of rejection . In a namespace , Roles can be used to define a role , If it's cluster level , You need to use ClusterRole 了 . Roles can only authorize resources within a namespace , The role defined in the following example has read Pod Authority :
kind: Role
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
namespace: default // This means default The role under the namespace
name: pod-reader
rules:
- apiGroups: [""] # "" An empty string , It means the core API Group
resources: ["pods"] // The resource to operate
verbs: ["get", "watch", "list"] // Operation resources correspond to specific permissions
rules The parameters in are described as follows :
apiGroups: Supported by API Group list , for example ”apiVersion: batch/v1”、”apiVersion: extensions”、”apiVersion: apps”
resources: List of supported resource objects , for example pods、deployments、secrets、jobs、configmaps、endpoints、persistentvolumeclaims、replicationcontrollers、statefulsets、namespaces etc. .
verbs: For resource objects List of operation methods for , for example get、 watch、 list、 delete、 replace、 patch 、create etc.
2) The cluster character (ClusterRole)
In addition to the ability to manage resources in the same namespace as the role , Because of its cluster level effective range , It can also be used for authorization management of the following special elements :
Cluster wide resources , Such as Node.
Non resource based path , Such as ”/healthz”.
Resources that contain all the namespace , for example pods( be used for kubectl get pods –all-namespaces Such operations are authorized )
The following cluster role can give users access to any or all of the namespace's secrets( Depending on how it's bound ):
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: my-cluster-role
# ClusterRole It's not limited to the namespace , So it omits namespace The definition of
rules:
- apiGroups: [""]
resources: ["secrets"]
verbs: ["get", "watch", "list"]
3) Character binding (RoleBinding) and Cluster role binding (ClusterRoleBinding)
First, role binding or cluster role binding is used to bind a role to a target , The binding target can be User( user )、Group( Group ) perhaps Service Account. Use RoleBinding You can authorize a namespace , Use ClusterRoleBinding Cluster wide authorization is possible .
RoleBinding You can reference Role To authorize . In the following example RoleBinding Will be in default Put... In the namespace pod-reader The role grants the user jane, This operation makes jane Can read default In namespace Pod:
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: read-pods
namespace: default // The namespace specified by the role binding
subjects:
- kind: User // The type of operation is user
name: jane //user The name of
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: Role // The type of permission binding is role
name: pod-reader // For the above role name
apiGroup: rbac.authorization.k8s.io
RoleBinding You can also quote ClusterRole To authorize .
RoleBinding You can reference ClusterRole, To belong to the same namespace ClusterRole Define the resource subject to authorize . A very common practice is , The Cluster Administrator predefines a set of roles for the cluster scope (ClusterRole), And then reuse these in multiple namespace ClusterRole. This can greatly improve the efficiency of authorization management , It also makes the basic authorization rules under each namespace consistent with the user experience .
For example, the following , although secret-reader It's a cluster role , But because of the use of RoleBinding``, therefore dave Can only read development Namespace `` Medium secret.
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: read-secrets
namespace: development # In the cluster role , Only in development Only permissions in the namespace can be granted dave
subjects:
- kind: User
name: dave
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: ClusterRole
name: secret-reader
apiGroup: rbac.authorization.k8s.io
ClusterRoleBinding, Roles in cluster role binding can only be cluster roles . For authorization at the cluster level or for all namespace .
The following example allows manager The user of the group reads any namespace Medium secret:
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: read-secrets-global
subjects:
- kind: Group
name: manager
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: ClusterRole
name: secret-reader
apiGroup: rbac.authorization.k8s.io
The figure below shows the above pair of Pod Of get/watch/list Operations are authorized Role and RoleBinding logical relationship .
4) How resources are referenced
Most resources can be expressed as strings of their names , That is to say Endpoint Medium URL Relative paths , for example pods. However , some k8s API Include subordinate resources , Such as pod Log (logs).pod The log Endpoint yes GET/api/v1/namespaces/{namespace}/pods/{pod_name}/log.
In this case ,Pod Is a resource in a namespace ,log It's a subordinate resource . To be in RBAC In the role , You need to use a slash ‘/‘ To distinguish between resources and subordinate resources .
If you want to authorize a subject to read at the same time Pod and Pod log, You can configure resources Is an array :
kind: Role
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
namespace: default
name: pod-and-pod-logs-reader
rules:
- apiGroups: [""]
resources: ["pods", "pods/log"]
verbs: ["get", "list"]
Resources can also be named (ResourceName) reference ( This refers to the name of the resource instance ). In the specified ResourceName after , Use get、delete、update、patch The request for action , Will be limited to the scope of this resource instance .
Such as A statement allows a subject to only one configmap Conduct get and update operation
kind: Role
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
namespace: default
name: configmap-updater
rules:
- apiGroups: [""]
resources: ["configmap"]
resourceNames: ["my-configmap"]
verbs: ["update", "get"]
resourceName This usage is correct for list、watch、create、deletecollection The operation is invalid , It's because you have to pass URL For authentication , And the resource name is in list、watch、create and deletecollection You can only ask for Body Part of the data .
Because there is so much , That's all for this issue , Next time we'll talk about common role examples 、 Common role binding examples . See you next time ~
版权声明
本文为[Ruijiang cloud computing]所创,转载请带上原文链接,感谢
边栏推荐
- 校准服务的六个轴心
- 分享用MathType编辑字母与数学公式的技巧
- 布客·ApacheCN 编程/后端/大数据/人工智能学习资源 2020.11
- The worst hacker in history: stealing $1 billion of bitcoin without spending it for seven years, and finally being seized by the Department of justice
- 设置背景图片的两种方式,并解决手机端背景图片高度自适应问题
- Building Hadoop environment based on pseudo distributed under centos7
- 用微信表情翻译表白,程序员的小浪漫,赶紧Get起来!
- 浅谈API网关(API Gateway)如何承载API经济生态链
- Help enterprises to get rid of difficulties, famous enterprises return home Engineers: success depends on it!
- 全栈技术实践经历告诉你:开发一个商城小程序要多少钱?
猜你喜欢
In depth analysis of the multi-user shopping mall system from search to create a profit point
浅谈API网关(API Gateway)如何承载API经济生态链
How to use Camtasia to make dynamic animation scene?
Chrome浏览器 js 关闭窗口失效解决方法
5分钟GET我使用Github 5 年总结的这些骚操作!
Rookie gospel, 28 books step by step to make you a big bull! (a copy of learning syllabus attached)
Six axes of calibration service
CentOS view the number of CPU cores and cpuinfo analysis
MIT6.824分布式系统课程 翻译&学习笔记(三)GFS
Toolkit Pro helps interface development: shorten the project development cycle and quickly realize GUI with modern functional area style
随机推荐
Mit6.824 distributed system course translation & learning notes (3) GFS
It's so easy to replace the video background with the sound and shadow
[share] interface tests how to transfer files in post request
High quality defect analysis: let yourself write fewer bugs
深入分析商淘多用户商城系统如何从搜索着手打造盈利点
echart 设置柱子之间的间距
【运维思考】如何做好云上运维服务?
5分钟GET我使用Github 5 年总结的这些骚操作!
QML Repeater
超简单集成华为系统完整性检测,搞定设备安全防护
Toolkit Pro助力界面开发:缩短项目开发周期,快速实现具有现代功能区样式的GUI
Gesture switch background, let live with goods more immersive
H264Nalu头部解析
自定义室内地图在线工具
拉线式位移传感器在边坡裂缝中的作用
How to choose the development of Biao fan interactive interpretation program?
会展云技术解读 | 面对突发事故,APP 如何做好崩溃分析与性能监控?
QML Repeater
iOS下带小数点的数字键盘
Using GaN based oversampling technique to improve the accuracy of model for mortality prediction of unbalanced covid-19