繁体   English   中英

我应该为安全灵活的应用引擎设置哪些服务帐户权限 -> 云功能通信

[英]What service account permissions should I set for secure flexible app engine -> cloud function communication

我在确定需要将某些角色分配给哪个服务帐户时遇到问题。

我有一个 NodeJS 应用程序在我灵活的应用程序引擎环境中运行。 我有一个 hello-world python3.7 HTTP 云函数。

我想从我的应用引擎向我的云函数发出 GET 请求。

当 allUser 成员被授予 hello-world 云函数的云函数调用者角色时,一切正常。

但现在我想保护我的云功能端点,以便只有我灵活的应用引擎可以访问它。

我删除了 allUser 成员,正如预期的那样,当应用程序引擎尝试调用时,我得到了 403。

现在,我将 @appspot.gserviceaccount.com 和 @gae-api-prod.google.com.iam.gserviceaccount.com 成员添加到 hello-world 云函数,并为它们提供云函数调用者角色。

我希望灵活的应用程序引擎现在能够调用 hello-world 云函数,因为我给了它云函数调用者角色。

但我不断收到 403 错误。

应用引擎灵活使用什么服务帐户来对云函数 API 进行这些调用?

为了将云功能与服务帐户连接,需要进行一些设置:

  • 启用所需的 API
  • 启用服务帐户
  • 充当用户服务帐户

默认服务帐户创建了一个云功能,有时并不具有所有权限。

您可以在此处找到更多信息:

https://cloud.google.com/functions/docs/securing/

约翰汉利是对的,

当使用 GCP 库执行操作(例如 google-cloud-firestore)时,执行函数将使用底层服务帐户权限来执行这些操作。

对云函数 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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM