我在确定我需要给哪个服务帐户指定某些角色时遇到了问题。
我有一个NodeJS应用程序运行在我灵活的应用程序引擎环境中。我有一个hello-world python3.7 HTTP云函数。
我想做一个从我的应用引擎到我的云功能的GET请求。
当allUser成员在hello-world云函数上被赋予云函数调用者角色时,一切都很好。
但是现在我想保护我的云功能端点,这样只有我灵活的应用程序引擎才能到达它。
我删除了allUser成员,就像预期的那样,当应用引擎试图调用时,我得到了一个403。
现在,我将@gae-api-prod.google.com.iam.gserviceaccount.com和@appspot.gserviceaccount.com成员添加到hello-world云函数中,并赋予它们云函数调用者角色。
我希望灵活的应用程序引擎现在能够调用hello-world云功能,因为我赋予它云函数调用者的角色。
但我一直有403个错误。
应用程序引擎可以灵活地使用哪个服务帐户来执行对云函数API的调用?
发布于 2020-04-06 11:32:34
约翰·汉利是对的
当使用GCP库执行操作时(例如,),执行函数将使用底层服务帐户权限来执行这些操作。
当对云函数URL执行手动HTTP请求时,必须从元数据服务器获取令牌,以正确验证请求。
def generate_token() -> str:
"""Generate a Google-signed OAuth ID token"""
token_request_url: str = f'http://metadata/computeMetadata/v1/instance/service-
accounts/default/identity?audience={TARGET_URL}'
token_request_headers: dict = {'Metadata-Flavor': 'Google'}
token_response = requests.get(token_request_url, headers=token_request_headers)
return token_response.content.decode("utf-8")
def do_request():
token: str = generate_token()
headers: dict = {
'Content-type': 'application/json',
'Accept': 'application/json',
'Authorization': f'Bearer {token}'
}
requests.post(url=TARGET_URL, json=data, headers=headers)
发布于 2019-07-24 00:04:45
这些设置是为了通过服务帐户连接云功能而设置的:
默认的服务帐户创建一个云函数,有时并不拥有所有的特权。
您可以在这里找到更多信息:
https://stackoverflow.com/questions/57145654
复制相似问题