我需要使用 RBAC 授予对一个部署和该部署的所有 pod 的访问权限。我已经成功地为Role
和配置RoleBinding
了deploymet
,它工作正常:
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
namespace: <my-namespace>
name: <deployment>-manager-role
rules:
- apiGroups: ["", "extensions", "apps"]
resources: ["deployments"]
resourceNames: ["<deployment>"]
verbs: ["get", "list", "watch", "update", "patch"]
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: <deployment>-manager-binding
namespace: <my-namespace>
subjects:
- kind: User
name: <username>
apiGroup: ""
roleRef:
kind: Role
name: <deployment>-manager-role
apiGroup: ""
使用此角色,用户可以访问、更新和修补部署。此部署创建具有动态名称(如<deployment>-5594cbfcf4-v4xx8
)的 pod。我尝试允许此用户使用部署名称和使用部署名称 + 通配符 char 访问这些 pod(获取、列出、监视、读取日志、执行、删除)*
:
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
namespace: <my-namespace>
name: <deployment>-pods-manager-role
rules:
- apiGroups: ["", "extensions", "apps"]
resources: ["pods"]
resourceNames: ["<deployment>*"]
verbs: ["get", "list", "watch", "update", "patch", "exec", "delete"]
我还更新了角色绑定。但是当我尝试获取吊舱时:
kubectl --context=<username>-ctx -n <namespace> get pods <deployment>-5594cbfcf4-v4xx8
我收到错误:
服务器错误(禁止):pod“<deployment>-5594cbfcf4-v4xx8”被禁止:用户“<username>”无法在命名空间“<namespace>”中的 API 组“”中获取资源“pods”
如果我添加<deployment>-5594cbfcf4-v4xx8
到列表中resourceNames
,用户可以访问此 pod。
是否可以根据部署名称授予对特定 pod 的访问权限?