首页 文章

我应该如何创建仅在我的项目中可见的Google App Engine服务?

提问于
浏览
0

我想创建一个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服务,我会使用网络 . 我不认为GAE实例可以分配给网络 .

1 回答

  • 0

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

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

    Appengine identity api doc包含使用 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)
    

相关问题