在 Cloud 函数中生成 google 个没有密钥的服务帐户凭据
Generate google service account credentials without key in Cloud function
如何在没有服务帐户密钥文件的情况下创建凭据?
我目前的设置。
我正在使用
从应用程序调用云函数
curl -X POST CF_URL -H "Authorization: Bearer $TOKEN" -d@Key.json
在云函数中
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']))
如何在没有服务帐户密钥文件的情况下创建凭据?
我目前的设置。
我正在使用
从应用程序调用云函数curl -X POST CF_URL -H "Authorization: Bearer $TOKEN" -d@Key.json
在云函数中
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']))