如何在没有服务帐户密钥文件的情况下创建凭据?
我当前的设置。
我正在使用curl -X POST CF_URL -H“授权:承载$ TOKEN” [email protected]
在CF中
credentials = service_account.Credentials.from_service_account_info(request_json),
scopes=['https://www.googleapis.com/auth/cloud-platform'])
service = googleapiclient.discovery.build(
'cloudresourcemanager', 'v1', credentials=credentials,cache_discovery=False)
policy = (
service.projects()
.getIamPolicy(
resource=credentials.project_id,
body={},
)
.execute()
)
我正在将服务帐户密钥作为有效内容传递给安全性。如何避免将密钥文件作为有效载荷传递。
在Cloud Functions(以及所有GCP产品中)中,您具有功能名称function identity。这意味着您可以在运行时选择要附加到Cloud Function的服务帐户。如果未定义,则默认使用该选项。
因此,默认身份自动存在于您的云功能中。您可以简单地执行此操作,例如described in this library
import google.auth
credentials, project_id = google.auth.default(scopes='https://www.googleapis.com/auth/cloud-platform']))