如何将角色与服务帐户绑定-Kubernetes

问题描述 投票:0回答:1

我知道有很多类似的问题,但就我所浏览的而言,没有一个解决方案。谈到这个问题,我创建了一个服务帐户(使用命令),角色(使用.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>

kubernetes dashboard rbac
1个回答
0
投票

我发现您提供的.yamls需要一些调整。

Rolerules部分后面的格式有误。

[RoleBindingnamespace:之后缺少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有非常有用的指南,您可以在其中找到有关此特定主题的更多详细信息。

请让我知道是否有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.