【问题标题】:Google Cloud function - how to authenticate while calling Google App EngineGoogle Cloud 功能 - 如何在调用 Google App Engine 时进行身份验证
【发布时间】:2021-01-15 03:18:42
【问题描述】:

我们在 App Engine 标准 Python 2.7 中有一个应用程序。我们在这个项目中还有一个 Cloud Function。

我们想向 App Engine 应用程序中的资源之一发出 HTTP POST 请求。目前我们在 Cloud Functions 中有以下代码

url = "https://project-name.appspot.com/urlidentifier"

data_obj = {
    'sample' : 'data'
}

data_json = json.dumps(data_obj)
data_encode = urllib.parse.urlencode(data_json).encode("utf-8")

req =  request.Request(url, data=data_encode) # this will make the method "POST"
resp = request.urlopen(req)

Python 2.7 中的应用程序使用 Firebase 用户身份验证进行身份验证。详情请见here。

我们的问题 - 当 HTTP POST 由 Cloud Function(而不是用户)发起时,我们如何强制对应用程序的资源进行身份验证。应用程序资源 (https://project-name.appspot.com/urlidentifier) 是项目中的一个函数。我们可以使用服务帐户吗?如果是,我们该怎么做?

Cloud Function 和应用程序属于同一个项目。

【问题讨论】:

    标签: google-cloud-platform google-cloud-functions google-authentication google-app-engine-python


    【解决方案1】:

    您可以通过函数现有的service identity 进行身份验证,请参阅:

    https://cloud.google.com/run/docs/authenticating/service-to-service

    (此文档适用于 Cloud Run,但模式与 Cloud Functions 相同。您需要将 App Engine 调用者角色授予该函数的服务帐号)。

    【讨论】:

    • 对于 IAP,我认为您在生成 JWT 令牌时必须使用这种受众模式:<PROJECT_NUMBER>-<HASH>.apps.googleusercontent.com。试试看,让我们知道!
    • 我们如何保护 Project 1 应用程序?目前,身份验证基于 Firebase 用户身份验证。该应用程序不受 IAP 保护。我们是否可以只为一种资源提供 IAP - project-name.appspot.com/urlidentifier?我们的理解/方法有错吗?
    • 项目 1 应用程序使用 Firebase 使用此 firebase.google.com/docs/auth/admin/… 进行身份验证。现在我们有一个资源 project-name.appspot.com/urlidentifier 需要由服务帐户(而不是用户帐户)访问。我们如何保护 project-name.appspot.com/urlidentifier?
    猜你喜欢
    • 2011-12-25
    • 1970-01-01
    • 2015-01-02
    • 1970-01-01
    • 1970-01-01
    • 2014-08-14
    • 2014-04-30
    • 1970-01-01
    • 2014-06-22
    相关资源
    最近更新 更多