授权: 授予用户不同的访问权限,决定一个api调用是否合法, api server目前支持以下几种授权策略(通过api server启动参数--authorization-mode): ABAC,RBAC, Webhook
1)1.5 版本开始引入, 1.6升级为beta版本, 1.8为GA版本 2)4种资源对象: Role, ClusterRole, RoleBinding , ClusterRoleBinding
1)Role角色: 一个角色就是一组权限的集合, 这里的权限都是许可形式, 不存在拒绝规则, 一个Role角色属于一个命名空间,作用范围是一个命名空间, 角色只能对命名空间内的资源进行授权
kind: Role apiVersion: rbac.authorization.k8s.io/v1 metadata: namespace: default name: pod-reader rules: - apiGroups: [""] resources: ["pods"] verbs: ["get", "watch", "list"] #apiGroups: 支持的API组列表 #resources: 支持的资源对象列表, 例如pods, deployments,job #verbs: 对资源列表的操作方法列表, 例如get, watch, list, delete等2)ClusterRole集群角色: 权限等同于Role, 与Role区别在于作用范围是所有的命名空间, 同时还可以对特殊元素的授权, 例如Node,
kind: ClusterRole apiVersion: rbac.authorization.k8s.io/v1 metadata: rules: - apiGroups: [""] resources: ["secrets"] verbs: ["get", "watch", "list"]3)角色绑定(RoleBinding)和集群角色绑定(ClusterRoleBinding)
功能: 角色绑定(RoleBinding)和集群角色绑定(ClusterRoleBinding)用来把一个Role或ClusterRole绑定到一个目标上, 目标可以是User用户丶Group组丶ServiceAccount, RoleBinding作用于一个命名空间, ClusterRoleBinding作用于所有命名空间 kind: RoleBinding apiVersion: rbac.authorization.k8s.io/v1 metadata: name: read-pods namespace: default subjects: - kind: User name: jane apiGroup: rbac.authorization.k8s.io roleRef: kind: Role name: pod-reader apiGroup: rbac.authorization.k8s.io kind: ClusterRoleBinding apiVersion: rbac.authorization.k8s.io/v1 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 kind: RoleBinding apiVersion: rbac.authorization.k8s.io/v1 metadata: name: read-secrets namespace: development subjects: - kind: User name: dave apiGroup: rbac.authorization.k8s.io roleRef: kind: ClusterRole name: secret-reader apiGroup: rbac.authorization.k8s.io #注意: secret-reader是一个集群角色, 但是因为使用了RoleBinding,所以dave只能读取deployment命名空间中的secret转载于:https://www.cnblogs.com/lovelinux199075/p/11265086.html