为 GKE 身份验证生成的令牌缺少权限

问题描述 投票:0回答:1

看来这个问题应该被编辑

python kubernetes google-cloud-platform kubernetes-python-client
1个回答
3
投票

因此,如果您查看print-access-token的代码

here
,您会发现访问令牌通常是在没有范围的情况下打印的。你看:

try:
  creds = client.GoogleCredentials.get_application_default()
except client.ApplicationDefaultCredentialsError as e:
  log.debug(e, exc_info=True)
  raise c_exc.ToolException(str(e))

if creds.create_scoped_required():
   ...

然后在这个文件上你会看到:

def create_scoped_required(self):
    """Whether this Credentials object is scopeless.
    create_scoped(scopes) method needs to be called in order to create
    a Credentials object for API calls.
    """
    return False

显然,在您的代码中,您正在获取具有

https://www.googleapis.com/auth/cloud-platform
范围的令牌。您可以尝试删除它或尝试使用 USER_EMAIL_SCOPE,因为您指定的是:
"iss": self._service_account_key["client_email"]

您可以随时查看

gcloud auth activate-service-account --key-file=credentials.json
~/.config
下存储的内容。所以你知道
gcloud auth print-access-token
的用途。请注意,根据 thisthis,商店看起来像是 sqlite 格式。

© www.soinside.com 2019 - 2024. All rights reserved.