问题描述
我的目标
我想使用 GCP 模拟来获取我的 GKE 集群凭据。然后我想运行 kubectl
命令。
初始上下文
- 我有一个名为
rakib-example-project
的 GCP 项目 - 我在名为的项目中有 2 个 ServiceAccounts:
-
[email protected]
- 它具有项目范围的
roles/owner
角色 - 因此它可以在 GCP 项目中执行任何操作
- 它具有项目范围的
-
[email protected]
- 它仅具有项目范围的
roles/iam.serviceAccountTokenCreator
角色 - 因此它可以模拟 GCP 项目中的所有者 ServiceAccount
- 它仅具有项目范围的
-
[email protected]
- 我在名为
my-gke-cluster
的项目中有 1 个 GKE 集群
问题
✅ 我已经认证为执行者 ServiceAccount:
$ gcloud auth activate-service-account --key-file=my_executor_sa_key.json
Activated service account credentials for: [[email protected]]
✅ 我通过冒充所有者获取了 GKE 集群凭据:
$ gcloud container clusters get-credentials my-gke-cluster \
--zone asia-southeast1-a \
--project rakib-example-project \
--impersonate-service-account=owner@rakib-example-project.iam.gserviceaccount.com
WARNING: This command is using service account impersonation. All API calls will be executed as [[email protected]].
WARNING: This command is using service account impersonation. All API calls will be executed as [[email protected]].
Fetching cluster endpoint and auth data.
kubeconfig entry generated for my-gke-cluster.
❌ 由于缺少 container.nodes.list
权限,我无法列出集群节点:
$ kubectl get nodes
Error from server (Forbidden): nodes is forbidden: User "[email protected]" cannot list resource "nodes" in API group "" at the cluster scope: requires one of ["container.nodes.list"] permission(s).
但我已经模拟了所有者 ServiceAccount。为什么它仍然缺少权限? ???
我的局限
如果我授予我的执行者 ServiceAccount roles/container.admin
角色,效果会很好。但是,由于合规性要求,我不允许将此类角色授予我的执行者 ServiceAccount。我只能冒充所有者 ServiceAccount,然后通过它做我想做的任何事情 - 而不是直接。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)