目录
RBAC基本概念
授权插件:
Node,ABAC(Attribute-based access control),RBAC(Role-based access control)和Webhook等
角色(Role),可以拥有多种许可(permission);
- Verb / Action / Operation
- Objects / Workload / Resources
许可(Permission),对一系列对象的操作权限;【Operation+Object】
用于限制对资源的授权访问的三种方式:
- Resources [Type],,还有一种是Non-resource URLs
- Resource Names 【具体的某个或某几个】
- Verbs(可以执行的操作)
用于RBAC的三种资源对象:user、group、serviceaccount等;
Users&Roles&Permissions之间的逻辑关系
users-roles-operations-objects关联关系:
Role&Clusterrole&Rolebinding&Clusterrolebinding
Rolebinding:user account OR group account OR service account
以及Clusterrole和Clusterrolebinding
资源是有边界或范围的;或Cluster,或namespace;这里的Role和Rolebinding属于namespace级别;clusterrole和clusterrolebinding属于cluster级别;
特殊情况(rolebinding绑定clusterrole)
(1)rolebinding可以绑定role或者clusterrole,,clusterrolebinding只能绑定clusterrole;
(2)如果是rolebinding绑定clusterrole,那么clusterrole所定义的权限,只在rolebinding所在的namespace中有效;
特殊情况举例,假设某一个Kubernetes集群有10个namespace,如果每个namespace都需要新建1个user,1个role和1个rolebinding,那么就需要建10个user、10个role和10个rolebinding,,现在假设这10个user的权限都是一样的,那比较推荐的一个做法是新建1个Clusterrole和10个rolebinding,然后使用rolebinding去为10个user绑定用那一个Clusterrole即可,注意这里的权限都是namespace级别的,不是Cluster级别的,且10个user的权限是一样的才行,,如每个namespace都需要一个管理员(admin)的场景,如下图所示:
创建role和rolebinding的操作命令
创建role的命令:kubectl create role ROLE_NAME –verb=verb –resource=resource.group / subresource [–dry-run] [options]
创建rolebinding的命令:kubectl create rolebinding ROLEBINDING_NAME –role=ROLE_NAME or –clusterrole=CLUSTERROLE_NAME [–user=username] [–group=groupname] [–serviceaccount=namespace.serviceaccountname] [–dry-run] [options]