【发布时间】:2021-12-06 07:31:33
【问题描述】:
我正在尝试从 Cloud Function 向部署在默认 GAE 服务上的多个 App Engine 端点发送请求。我的代码很简单:
云功能
main.py
import logging
import requests
def main(event, context):
bucketname = event['bucket']
filename = event['name']
endpoint = # Some logic extracting the endpoint to be used
url = 'https://myproject.ew.r.appspot.com/{}'.format(endpoint)
data = {
'bucketname': bucketname,
'filename': filename
}
r = requests.post(url, json=data)
logging.info(r)
return str(r)
云函数的部署方式:
gcloud functions deploy storage_to_gae --runtime python37 --trigger-resource $BUCKETNAME --trigger-event google.storage.object.finalize --region $REGION --source gcf/ --entry-point main --service-account cf-sa@myproject.iam.gserviceaccount.com
Fuction 使用的服务帐户已授予服务帐户用户 (roles/iam.serviceAccountUser) 角色。
应用引擎
app.yml
runtime: python37
service: default
但是,请求不会到达 App Engine,因为 GAE 服务上没有显示任何日志。请求返回 <Response [401]> 错误代码,因此 CF 似乎无法访问 App Engine 服务。
我还需要哪些额外的角色来提供我的cf-sa@myproject.iam.gserviceaccount.com 服务帐户?我在客户端环境中进行部署,因此我的权限有限,我必须询问所需的确切角色。
【问题讨论】:
-
您是否在 App Engine 之上使用 IAP?
-
你是对的,我问了客户 GCP 团队,他们正在使用 IAP 来管理访问。我将结束这个问题,因为它与公司相关,而不是通用问题。 @guillaumeblaquiere
-
您可以对受 IAP 保护的 App Engine 服务执行 Cloud Functions 调用。没有问题。为什么要结束这个问题?
-
你能检查一下客户ID是否正确吗?客户端 ID 应该是目标应用引擎的项目 ID。
-
与我的客户端 GCP 团队的通信很慢,所以我不知道客户端启用了 IAP。当他们告诉我时,我要求项目的正确权限和 IAP 客户端 ID,我能够成功调用 GAE 端点。如果需要,您可以发布一个答案,解释如何调用 IAP 安全 GAE 服务执行请求,我会将其标记为正确。否则,我可以发布用于我的用例的解决方案。 @guillaumeblaquiere
标签: python google-app-engine google-cloud-platform google-cloud-functions google-cloud-iam