Google app engine 如何在GCP App Engine Flex中使特定端点私有或至少受限?

Google app engine 如何在GCP App Engine Flex中使特定端点私有或至少受限?,google-app-engine,.net-core,google-cloud-platform,Google App Engine,.net Core,Google Cloud Platform,我有一个循环Cron调度程序,它调用Google云平台应用程序引擎Flex服务(.net core web API say APP1)中的一个方法,该服务反过来调用另一个Google云平台应用程序引擎Flex服务(另一个.net core web API say APP2)端点(例如:/v1/API/test) 我的问题是如何将对这个特定APP2端点的访问限制为仅对APP1的访问?我是否必须使用云端点来实现这一点?请记住,APP2还有其他对公众开放的端点。调用私有端点时,可以使用X-Appeng

我有一个循环Cron调度程序,它调用Google云平台应用程序引擎Flex服务(.net core web API say APP1)中的一个方法,该服务反过来调用另一个Google云平台应用程序引擎Flex服务(另一个.net core web API say APP2)端点(例如:/v1/API/test)


我的问题是如何将对这个特定APP2端点的访问限制为仅对APP1的访问?我是否必须使用云端点来实现这一点?请记住,APP2还有其他对公众开放的端点。

调用私有端点时,可以使用X-Appengine-Inbound-AppId检查源应用程序


请参阅

要限制从服务app2到服务app1的访问,而不是对普通公众的访问,您必须使用云端点。要执行此操作,请执行以下步骤:

1) 您必须创建一个指向云端点的openapi-appengine.yaml文件。配置如下:

  swagger: '2.0'
  info:
    title: Cloud Endpoints
    description: Sample API on Cloud Endpoints with a Cloud Run backend
    version: 1.0.0
  host: endpoint-service.appspot.com   ---> you've to put your service URL
  x-google-allow: all
  schemes:
    - https
  produces:
    - application/json
  paths:
    /resdticted-endpoint-1:             --> Here you've to put all the endpoints you want to restrict
      get:
        summary: Greet a user
        operationId: hello
        responses:
          '200':
            description: A successful response
            schema:
              type: string
        security:
          - DEFINITION_NAME: []

    /resdticted-endpoint-2:
      get:
        summary: Greet a user
        operationId: hello
        responses:
          '200':
            description: A successful response
            schema:
              type: string
        security:
          - DEFINITION_NAME: []

securityDefinitions:                      
  DEFINITION_NAME:
    authorizationUrl: ""
    flow: "implicit"
    type: "oauth2"
    x-google-issuer: "SA_EMAIL_ADDRESS"   --> Here you've to add a Service Account, in case you don't have any, create a new one
    x-google-jwks_uri: "https://www.googleapis.com/robot/v1/metadata/x509/SA_EMAIL_ADDRESS"  --> put your service account name at the end
2) 然后,转到App2服务: -将您的服务名称添加到app.yaml文件:

   endpoints_api_service:
   # The following values are to be replaced by information from the output of
   # 'gcloud endpoints services deploy openapi-appengine.yaml' command.
   name: ENDPOINTS-SERVICE-NAME
   rollout_strategy: managed
  • 将ENDPOINTS-SERVICE-NAME替换为端点服务的名称。这与您在OpenAPI文档的主机字段中配置的名称相同。例如:

    端点\u api\u服务: 名称:example-project-12345.appspot.com 战略:管理


3) 最后,继续此操作,以便在服务之间进行身份验证。

云端点可能是您的最佳选择,因为它们本机支持此功能,或者您可以实现您的身份验证机制,可能使用服务帐户凭据。看起来这只通过URL获取服务提供。不要认为它在.net core中受支持。您可以创建自己的url_fetch服务,并使用AuthorizedSession()从APP1调用APP2,然后调用APP2。在APP2中,您可以检查私有端点的请求令牌。这是否允许我仅限制特定端点,而让其他端点可供一般公众访问?是的。这正是我最终要做的。现在我被困在JWT部分。如果你想看的话,就把它作为另一个问题贴出来。谢谢