我知道有很多类似的问题,但就我所浏览的而言,没有一个解决方案。谈到这个问题,我创建了一个服务帐户(使用命令),角色(使用.yaml文件),角色绑定(使用.yaml文件)。该角色仅授予对Pod的访问权限。但是,当我使用角色附加到的SA登录到仪表板(令牌方法)时,我可以不受限制地查看所有资源。这是我使用的文件和命令。
Role.yaml:
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
namespace: assembly-prod
name: testreadrole
rules:
- apiGroups: [""]
resources: ["pods"]
verbs: ["get", "watch", "list"]
RoleBinding.yaml
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: testrolebinding
namespace: assembly-prod
subjects:
- kind: ServiceAccount
name: testsa
apiGroup: ""
roleRef:
kind: Role
name: testreadrole
apiGroup: rbac.authorization.k8s.io
用于创建服务帐户的命令:kubectl create serviceaccount <saname> --namespace <namespacename>
我发现您提供的.yamls
需要一些调整。
Role
的rules
部分后面的格式有误。
[RoleBinding
在namespace:
之后缺少subjects:
,并且格式错误。
尝试这样的事情:
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
namespace: assembly-prod
name: testreadrole
rules:
- apiGroups: [""]
resources: ["pods"]
verbs: ["get", "watch", "list"]
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: testrolebinding
namespace: assembly-prod
subjects:
- kind: ServiceAccount
name: testsa
namespace: assembly-prod
roleRef:
kind: Role
name: testreadrole
apiGroup: rbac.authorization.k8s.io
关于Non-Privileged RBAC User Administration in Kubernetes有非常有用的指南,您可以在其中找到有关此特定主题的更多详细信息。
请让我知道是否有帮助。