我们希望从计算引擎向appengine标准发出安全的HTTP请求,使用Appengine Users API进行身份验证
用户API:https://cloud.google.com/appengine/docs/standard/go/users/
GAE标准处理程序(使用用户Api保护 - 登录:必需):
handlers:
- url: /securehandler/.*
script: _go_app
login: required
secure: always
我们尝试使用此库从我们的计算引擎Go应用程序向上面的GAE处理程序发出经过身份验证的HTTPS请求:
https://godoc.org/golang.org/x/oauth2/google#ComputeTokenSource
client := &http.Client{
Transport: &oauth2.Transport{
// Fetch from Google Compute Engine's metadata server to retrieve
// an access token for the provided account.
// If no account is specified, "default" is used.
Source: google.ComputeTokenSource(""),
},
}
client.Get("https://myapp.appspot.com/securehandler/search")
我们收到403 Forbidden HTTP错误。
我们的默认计算引擎服务帐户包含App Engine Admin &安培; IAM中的编辑者权限。
Google支持人员告诉我们,我们应该可以使用默认的计算引擎服务帐户向GAE标准处理程序发出请求。
由于
答案 0 :(得分:1)
当从Compute Engine向App Engine应用程序发出安全的HTTP请求时,您必须使用用户授权流程[1],因为您希望GAE应用程序中的用户授予对来自GCE的请求的访问权限。 App Engine用户API仅适用于在App Engine平台上运行的应用程序。我假设你的是在GCE实例上运行。
在这种情况下,来自其他GCP服务(如GCE)的HTTP请求需要直接路由,其中URL包含资源的名称或ID [2]。
e.g
http://[VERSION_ID].[SERVICE_ID].[MY_PROJECT_ID].appspot.com
https://[VERSION_ID]-dot-[SERVICE_ID]-dot-[MY_PROJECT_ID].appspot.com)
请查看此文档,了解如何在您的请求中为您的应用所需的用户信息提供访问范围[3]。
希望这有助于指出正确的方向。
[1] https://cloud.google.com/compute/docs/api/how-tos/authorization
[2] https://cloud.google.com/appengine/docs/standard/go/communicating-between-services
[3] https://cloud.google.com/compute/docs/api/how-tos/authorization#user_auth_flow