Rak*_*kib 3 impersonation google-cloud-platform kubernetes google-kubernetes-engine kubectl
我想使用 GCP 模拟来获取我的 GKE 集群凭据。然后我想运行kubectl命令。
rakib-example-projectroles/owner角色 - 因此它可以在 GCP 项目内执行任何操作roles/iam.serviceAccountTokenCreator角色 - 因此它可以模拟GCP 项目中的所有者ServiceAccountmy-gke-cluster\xe2\x9c\x85 我已验证为执行者ServiceAccount:
\n$ gcloud auth activate-service-account --key-file=my_executor_sa_key.json\n\nActivated service account credentials for: [executor@rakib-example-project.iam.gserviceaccount.com]\nRun Code Online (Sandbox Code Playgroud)\n\xe2\x9c\x85 我已通过模拟所有者获取了 GKE 集群凭据:
\n$ gcloud container clusters get-credentials my-gke-cluster \\\n --zone asia-southeast1-a \\\n --project rakib-example-project \\\n --impersonate-service-account=owner@rakib-example-project.iam.gserviceaccount.com\n\nWARNING: This command is using service account impersonation. All API calls will be executed as [owner@rakib-example-project.iam.gserviceaccount.com].\nWARNING: This command is using service account impersonation. All API calls will be executed as [owner@rakib-example-project.iam.gserviceaccount.com].\nFetching cluster endpoint and auth data.\nkubeconfig entry generated for my-gke-cluster.\nRun Code Online (Sandbox Code Playgroud)\n\xe2\x9d\x8c 由于缺少container.nodes.list权限,我无法列出集群节点:
$ kubectl get nodes\n\nError from server (Forbidden): nodes is forbidden: User "executor@rakib-example-project.iam.gserviceaccount.com" cannot list resource "nodes" in API group "" at the cluster scope: requires one of ["container.nodes.list"] permission(s).\nRun Code Online (Sandbox Code Playgroud)\n但我已经模拟了Owner ServiceAccount。为什么它仍然缺少权限?
\n如果我授予我的执行者ServiceAccount 该角色,效果会很好roles/container.admin。但是,由于合规性要求,我不允许将此类角色授予我的执行者ServiceAccount。我只能冒充所有者ServiceAccount,然后通过它做任何我想做的事 - 而不是直接做。
如果您查看此位置的 kubeconfig 文件~/.kube/config,您可以看到授权和机密列表,例如
- name: gke_gdglyon-cloudrun_us-central1-c_knative
user:
auth-provider:
config:
access-token: ya29.<secret>-9XQmaTQodj4kS39w
cmd-args: config config-helper --format=json
cmd-path: /usr/lib/google-cloud-sdk/bin/gcloud
expiry: "2020-08-25T17:48:39Z"
expiry-key: '{.credential.token_expiry}'
token-key: '{.credential.access_token}'
name: gcp
Run Code Online (Sandbox Code Playgroud)
您会看到外部引用 (expiry-key和token-key) 和cmd-path. 命令路径很有趣,因为当需要生成新令牌时,它将被调用。
但是,您会看到任何提及冒充的内容。您必须将其添加到命令路径中,默认情况下才会使用。为此,请将其添加到您的配置中,如下所示:
gcloud config set auth/impersonate_service_account owner@rakib-example-project.iam.gserviceaccount.com
Run Code Online (Sandbox Code Playgroud)
现在,每次使用 gcloud CLI 都将使用模拟服务帐户,这就是您想要生成有效的 access_token 来访问您的 GKE 集群的原因
| 归档时间: |
|
| 查看次数: |
1935 次 |
| 最近记录: |