【发布时间】:2022-01-28 03:31:29
【问题描述】:
是否可以使用 Google Workload Identity Federation 的 OIDC 方法对我的 Python 应用程序的 Google Cloud Storage 包进行身份验证。
我想做这样的事情:
import os
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = str(os.path.dirname(os.path.dirname(__file__))) + "/keys/credentials.json"
from google.cloud import storage
import google.oauth2.id_token
import google.auth.transport.requests
request = google.auth.transport.requests.Request()
target_audience = "https://pubsub.googleapis.com"
obtained_id_token = google.oauth2.id_token.fetch_id_token(request, target_audience)
storage_client = storage.Client(credentials=obtained_id_token)
这会产生以下错误:
ValueError: This library only supports credentials from google-auth-library-python. See https://google-auth.readthedocs.io/en/latest/ for help on authentication with this library.
【问题讨论】:
-
1) 云存储需要 OAuth 访问令牌而不是身份令牌。 2) 您的代码尝试使用一个库创建凭据类,然后在不兼容的库方法中使用该变量。 3)您的问题提到了 Workload Identity Federation,但我在您的代码中没有看到。
-
@JohnHanley 感谢您的澄清评论。我想使用 Workload Identity Federation 来避免使用和传递敏感的 json 文件。我可以使用 WIF 对这些 Google SDK 进行身份验证吗?
标签: python google-cloud-platform google-cloud-storage openid-connect