【发布时间】:2019-05-12 15:23:14
【问题描述】:
我一直在尝试一种场景,即用户应该能够对命名空间中的服务执行所有操作,但在一个服务上他应该只能执行读取操作。
以下是我用来授予集群级别所有用户访问服务的集群角色。
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: test-clusterRole
rules:
- apiGroups:
- ""
resources:
- pods
verbs:
- get
- list
- watch
- apiGroups:
- ""
resources:
- pods/exec
verbs:
- create
- apiGroups:
- ""
resources:
- replicationcontrollers
- services
verbs:
- get
- list
- watch
- create
- delete
- update
- apiGroups:
- ""
resources:
- persistentvolumeclaims
- serviceaccounts
- namespaces/status
- pods/log
- pods/status
- replicationcontrollers/status
- resourcequotas
- resourcequotas/status
- namespaces
- persistentvolumes
verbs:
- get
- list
- watch
- apiGroups:
- ""
resources:
- configmaps
- secrets
verbs:
- get
- list
- watch
- create
- update
- delete
- apiGroups:
- apps
resources:
- deployments
- replicasets
- statefulsets
verbs:
- get
- list
- watch
- create
- update
- delete
- apiGroups:
- extensions
resources:
- ingresses
verbs:
- get
- list
- watch
- apiGroups:
- extensions
resources:
- replicasets
- deployments
verbs:
- get
- list
- watch
- create
- update
- delete
并且我已经为上述 ClusterRole 创建了关联的 RoleBinding。
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: test-roleBinding
namespace: test-namespace
subjects:
- apiGroup: rbac.authorization.k8s.io
kind: User
name: pradeep
- kind: ServiceAccount
name: default
namespace: test-namespace
roleRef:
kind: ClusterRole
name: test-clusterRole
apiGroup: rbac.authorization.k8s.io
现在,我正在尝试为命名空间“test-namespace”创建角色和 RoleBinding,以限制用户“pradeep”对特定服务“test-service”的只读访问,如下所示
角色:
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: test-role
namespace: test-namespace
rules:
- apiGroups: [""]
resources: ["services"]
resourceNames : ["test-service"]
verbs: ["get","list","watch"]
角色绑定:
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: test-roleBinding1
namespace: test-namespace
subjects:
- apiGroup: rbac.authorization.k8s.io
kind: User
name: pradeep
- kind: ServiceAccount
name: default
namespace: test-namespace
roleRef:
kind: Role
name: test-role
apiGroup: rbac.authorization.k8s.io
但是,用户“pradeep”仍然能够出于某种原因删除指定的服务“test-service”。 test-clusterRole 权限是否覆盖了 test-role 权限?如果是这样,如何解决这个问题。
如果没有,请提出一种实现此场景的方法。
【问题讨论】:
标签: service kubernetes roles rbac