【发布时间】:2020-01-03 17:12:27
【问题描述】:
尝试编写我的第一组 RBAC 角色。因此,试图找出为多个命名空间组件设置 2 个角色的最佳方式。
管理员角色(3 个命名空间的 RW 表示默认,ns1 和 ns2) 用户角色(只读 3 个命名空间,默认为 ns1 和 ns2)
正在考虑需要一个具有 2 个 clusterRoles 的服务帐户用于管理员/用户
apiVersion: rbac.authorization.k8s.io/v1
kind: ServiceAccount
metadata:
name: sa
namespace: default
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: admin-master
rules:
- apiGroups:
- batch
resources:
- pods
verbs:
- create
- delete
- deletecollection
- get
- list
- patch
- update
- watch
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: user-master
rules:
- apiGroups:
- batch
resources:
- pods
verbs:
- get
- list
- watch
然后利用roleBindings:
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: admin-rw
namespace: ns1
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: admin-master
subjects:
- kind: ServiceAccount
name: sa
namespace: default
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: user-readonly
namespace: ns1
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: user-master
subjects:
- kind: ServiceAccount
name: sa
namespace: default
但不确定如何将角色 admin-rw/user-readonly 与命名空间 2 (ns2) 绑定的最佳方式?
【问题讨论】:
标签: kubernetes ansible yaml rbac