![](/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.