![](/img/trans.png)
[英]Using a Google service account keyfile in a Kubernetes serviceaccount as a testing environment replacement for GKE workload identity
[英]ServiceAccount in GKE fails authentication
我需要创建可以访问GKE集群的ServiceAccounts。 在内部我使用以下命令执行此操作:
kubectl create serviceaccount onboarding --namespace kube-system
kubectl apply -f onboarding.clusterrole.yaml
kubectl create clusterrolebinding onboarding --clusterrole=onboarding --serviceaccount=kube-system:onboarding
文件onboarding.clusterrole.yaml
的内容是这样的:
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRole
metadata:
name: onboarding
rules:
- apiGroups:
- '*'
resources:
- 'namespace,role,rolebinding,resourcequota'
verbs:
- '*'
ServiceAccount资源按预期创建,ClusterRole和ClusterRoleBinding也看起来正确,但当我尝试使用此新角色访问API时,我收到身份验证失败。
curl -k -X GET -H "Authorization: Bearer [REDACTED]" https://36.195.83.167/api/v1/namespaces
{
"kind": "Status",
"apiVersion": "v1",
"metadata": {
},
"status": "Failure",
"message": "namespaces is forbidden: User \"system:serviceaccount:kube-system:onboarding\" cannot list namespaces at the cluster scope: Unknown user \"system:serviceaccount:kube-system:onboarding\"",
"reason": "Forbidden",
"details": {
"kind": "namespaces"
},
"code": 403
响应表明未知用户,但我确认ServiceAccount存在并且位于ClusterRoleBinding的主题中。 是否可以通过这种方式为GKE定义ServiceAccount?
我正在我们在数据中心运行的kubernetes集群上成功使用确切的过程。
GKE应该有相同的过程。 您的kubectl
版本是否与GKE集群的版本匹配? 不确定这是否是问题,但ClusterRole
需要复数资源,资源表示为列表:
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRole
metadata:
name: onboarding
rules:
- apiGroups:
- '*'
resources:
- namespaces
- roles
- rolebindings
- resourcequotas
verbs:
- '*'
在K8s 1.11.x上为我工作:
curl -k -X GET -H "Authorization: Bearer [REDACTED]" https://127.0.0.1:6443/api/v1/namespaces
{
"kind": "NamespaceList",
"apiVersion": "v1",
"metadata": {
"selfLink": "/api/v1/namespaces",
"resourceVersion": "12345678"
},
...
我看到你正在创建服务帐户,角色和角色绑定以获得对kubernetes集群的API访问权限,唯一的“hic”是资源配置不当。 查看本文档 ,了解如何配置rbac角色,资源动词以及它们的定义和示例。
你能否展示kubectl get clusterrolebinding onboarding -o yaml
的输出kubectl get clusterrolebinding onboarding -o yaml
?
这可能是版本不匹配,因为您创建了rbac.authorization.k8s.io/v1beta1 ClusterRole
和kubectl create clusterrole
将创建rbac.authorization.k8s.io/v1 ClusterRoleBinding
。
您应该将ClusterRole
升级到版本rbac.authorization.k8s.io/v1
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.