Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google app engine 使用IAP的应用程序引擎上的服务到服务请求_Google App Engine_Google Cloud Platform_Next.js_Google Iap_Identity Aware Proxy - Fatal编程技术网

Google app engine 使用IAP的应用程序引擎上的服务到服务请求

Google app engine 使用IAP的应用程序引擎上的服务到服务请求,google-app-engine,google-cloud-platform,next.js,google-iap,identity-aware-proxy,Google App Engine,Google Cloud Platform,Next.js,Google Iap,Identity Aware Proxy,我正在使用GoogleAppEngine托管一些服务(一个SSR服务和一个构建在Express上的后端API)。我已将我的dispatch.yaml文件设置为将/api/*请求路由到我的api服务,所有其他请求都路由到默认的(NextJS)服务 调度: -url:'*/api/*' 服务:api 问题是:我还为appengine启用了身份感知代理。当我尝试从我的NextJS服务向我的API发出GET请求时(服务器端,通过getServerSideProps),它会再次触发IAP登录页面,而不是

我正在使用GoogleAppEngine托管一些服务(一个SSR服务和一个构建在Express上的后端API)。我已将我的
dispatch.yaml
文件设置为将
/api/*
请求路由到我的api服务,所有其他请求都路由到
默认的
(NextJS)服务

调度:
-url:'*/api/*'
服务:api
问题是:我还为appengine启用了身份感知代理。当我尝试从我的NextJS服务向我的API发出
GET
请求时(服务器端,通过
getServerSideProps
),它会再次触发IAP登录页面,而不是点击我的API。我尝试了一些方法来解决这个问题:

  • 转发API请求中的所有cookie
  • 如前所述,使用
  • 标题设置
    X-request-With
    
  • 向我的应用程序引擎默认服务帐户授予IAP安全的Web应用程序用户权限

  • 但似乎什么都不管用。我已经确认,关闭应用程序引擎的IAP可以让一切按预期运行。前端对API的任何请求也能正常工作。是否有我缺少的解决方案或解决方法?

    您需要执行服务对服务呼叫。这并不简单,你也没有真正的例子。不管怎么说,我(在围棋中)测试了一下,它成功了

    首先,基于文档页面的开发

    您将在NodeJS中拥有这段代码抱歉,我不是NodeJS开发人员,至少是NexJS开发人员,您必须进行调整

    此示例不起作用,因为您需要正确的受众。这里的变量是
    receivingServiceURL
    。它适用于云运行(和云功能),但不适用于IAP背后的应用程序引擎。您需要使用名为
    IAP App Engine App

    好吧,很难理解我在说什么。因此,转到控制台,API&Services->Creentials。从那里,您有一个OAuth2客户机ID部分。复制行
    IAP-App-Engine-App
    的Client-ID列,如下所示

    最后一点,请确保您的应用程序引擎默认服务帐户具有访问IAP的权限。并将其添加为
    IAP安全Web应用程序用户
    。服务帐户的格式为
    @appspot.gserviceaccount.com

    也不是很清楚。因此,转到IAP页面(安全->身份识别代理),单击App Engine前面的复选框并转到页面右侧的权限面板中


    同时,我可以解释如何停用特定服务上的IAP(由NoCommandLine提出)。只是一句话:当你遇到麻烦时,停用安全性从来都不是一个好主意


    从技术上讲,您不能在服务上停用IAP。但您可以在特定服务上授予
    alluser
    作为
    IAP-secured Web-App用户
    (而不是单击App-Engine的复选框,而是单击特定服务的复选框)。这样,即使使用IAP,您也授权所有用户访问您的服务。实际上,这是一个没有检查的激活。

    您如何在代码中执行您的请求?您是否在授权标头中添加了承载id令牌?@guillaumeblaquiere否,我使用Axios发出
    GET
    请求,并在
    cookie
    headerOk中从前端传递cookie。您在IAP后面有一个前端服务,它调用IAP后面的后端服务?或者是调用另一个后端服务的后端服务?关闭后端服务上的IAP,而添加承载令牌验证如何?您在内部拨打电话时包含该令牌。公共用户将没有该令牌,这意味着他们对后端服务的调用将失败。注意:根据文档--您应该能够单独打开/关闭后端服务的IAP,而不是其他web服务services@guillaumeblaquiere它是一个调用另一个后端服务的后端服务。两者都是通过IAP背后的App Engine部署的建议是关闭IAP并替换为
    承载令牌验证
    ,这意味着仍然存在某种安全性。这可能不是最好的安全方法,但我们同意关闭安全性肯定不是最好的解决方案
    // Make sure to `npm install --save request-promise` or add the dependency to your package.json
    const request = require('request-promise');
    
    const receivingServiceURL = ...
    
    // Set up metadata server request
    // See https://cloud.google.com/compute/docs/instances/verifying-instance-identity#request_signature
    const metadataServerTokenURL = 'http://metadata/computeMetadata/v1/instance/service-accounts/default/identity?audience=';
    const tokenRequestOptions = {
        uri: metadataServerTokenURL + receivingServiceURL,
        headers: {
            'Metadata-Flavor': 'Google'
        }
    };
    
    // Fetch the token, then provide the token in the request to the receiving service
    request(tokenRequestOptions)
      .then((token) => {
        return request(receivingServiceURL).auth(null, null, true, token)
      })
      .then((response) => {
        res.status(200).send(response);
      })
      .catch((error) => {
        res.status(400).send(error);
      });