gpt4 book ai didi

kubernetes - 如何制作一个允许对命名空间中的角色和角色绑定(bind)进行所有操作的 k8s 角色?

转载 作者:行者123 更新时间:2023-12-02 12:12:32 25 4
gpt4 key购买 nike

我想创建一个角色,允许在命名空间级别上对“Roles”和“RoleBindings”(但不是 ClusterRoles 或 ClusterRoleBindings)执行任何操作。

这是我放在一起的角色 YAML,但是当它绑定(bind)到服务帐户时,它现在被应用了。我做错什么了?

apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: role-binder
namespace: foo-namespace
rules:
- apiGroups:
- rbac.authorization.k8s.io
resources:
- Role
- RoleBinding
verbs:
- '*'

最佳答案

您可以通过以下规则实现:

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: role-grantor
rules:
- apiGroups: ["rbac.authorization.k8s.io"]
resources: ["rolebindings"]
verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
- apiGroups: ["rbac.authorization.k8s.io"]
resources: ["roles"]
verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]

---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: role-grantor-binding
namespace: office
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: role-grantor
subjects:
- apiGroup: rbac.authorization.k8s.io
kind: User
name: employee

我在我的实验室对其进行了测试,它可以按您的意愿工作:
$ kubectl --context=employee-context get role 
NAME AGE
deployment-manager 15m
role-binder 12m

$ kubectl --context=employee-context get rolebindings
NAME AGE
deployment-manager-binding 15m
role-grantor-binding 3m37s

$ kubectl --context=employee-context get clusterrolebindings
Error from server (Forbidden): clusterrolebindings.rbac.authorization.k8s.io is forbidden: User "employee" cannot list resource "clusterrolebindings" in API group "rbac.authorization.k8s.io" at the cluster scope

您可以在 documentation 中详细了解此内容。 .

关于kubernetes - 如何制作一个允许对命名空间中的角色和角色绑定(bind)进行所有操作的 k8s 角色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61066707/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com