【问题标题】:How should I create a Google App Engine service visible only within my project?我应该如何创建仅在我的项目中可见的 Google App Engine 服务?
【发布时间】:2017-01-15 08:49:41
【问题描述】:

我想创建一个 Google App Engine 服务以用作微服务。我希望它的 API 只能被我项目网络中的调用者访问(即,来自我项目中的 Google Compute Engine 和 GAE 实例)。像这样限制访问的最简单方法是什么?

我从How do I run private modules on Google App Engine? 看到,对X-AppEngine-Inbound-AppId 的检查适用于来自 GAE 的请求,但这对来自 GCE 的请求没有帮助。

为了限制 GCE 服务,我会使用 Networking。我不认为 GAE 实例可以分配给网络。

【问题讨论】:

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


    【解决方案1】:

    检查 X-AppEngine-Inbound-AppId 是否与您的应用 ID 匹配。

    https://cloud.google.com/appengine/docs/python/appidentity/

    Appengine 身份 API 文档包含使用 X-AppEngine-Inbound-AppId 来声明身份。

    import webapp2
    
    
    class MainPage(webapp2.RequestHandler):
         allowed_app_ids = [
            'other-app-id',
            'other-app-id-2'
        ]
    
        def get(self):
            incoming_app_id = self.request.headers.get(
                'X-Appengine-Inbound-Appid', None)
    
            if incoming_app_id not in self.allowed_app_ids:
                self.abort(403)
    
            self.response.write('This is a protected page.')
    
    app = webapp2.WSGIApplication([
        ('/', MainPage)
    ], debug=True)
    

    【讨论】:

    • 这仅适用于来自 Google Compute Engine 的请求设置了 X-AppEngine-Inbound-AppId 标头。我的印象是他们没有。是吗?
    • 哦,对不起。我无法理解我读过的内容。您可以使用 jwt (json web token) 进行服务器到服务器的身份验证。请参阅该文档中的Asserting identity to third-party services 部分。
    • 该部分下该文档中描述的方法似乎需要google.appengine.api 才能签署消息,如果没有remote_api,则无法在GCE中访问,我无法在某些相关的脚本。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-18
    • 2017-09-09
    • 1970-01-01
    • 2019-12-14
    • 1970-01-01
    相关资源
    最近更新 更多