【问题标题】:Permission denied during gcloud app deploy using Google Cloud SDK使用 Google Cloud SDK 部署 gcloud 应用程序期间权限被拒绝
【发布时间】:2018-06-25 14:25:22
【问题描述】:

使用 Google Cloud SDK 将应用部署到 Google App Engine 非常困难。

我已经尝试了以下 2 个命令

C:\Users\yccheok\Desktop\jstock-android-appengine>gcloud config set project jstock-android
Updated property [core/project].

C:\Users\yccheok\Desktop\jstock-android-appengine>gcloud app deploy app.yaml --log-http --verbosity=debug
DEBUG: Running [gcloud.app.deploy] with arguments: [--log-http: "true", --verbosity: "debug", DEPLOYABLES:1: "['app.yaml']"]
DEBUG: No staging command found for runtime [python27] and environment [STANDARD].
DEBUG: API endpoint: [https://appengine.googleapis.com/], API version: [v1]
=======================
==== request start ====
uri: https://appengine.googleapis.com/v1/apps/jstock-android?alt=json
method: GET
== headers start ==
Authorization: Bearer ya29.GlxEBb1XVP1JK93-ARiaN_ZgiMbvZmw5KWfvJVfibDJ4FK_ZaMRoU1jVDTiWzsY606GSduJKJd9Nm8zA-_Iql5mGn4AMk4QVl8mPRycfekeZnOOHtbUvpkBMgOLOQA
accept: application/json
accept-encoding: gzip, deflate
content-length: 0
user-agent: google-cloud-sdk x_Tw5K8nnjoRAqULM9PFAC2b gcloud/184.0.0 command/gcloud.app.deploy invocation-id/c9ae232d33b346d787b95a36e28c38c0 environment/None environment-version/None interactive/True python/2.7.13 (Windows NT 10.0.16299)
== headers end ==
== body start ==

== body end ==
==== request end ====
---- response start ----
-- headers start --
-content-encoding: gzip
alt-svc: hq=":443"; ma=2592000; quic=51303431; quic=51303339; quic=51303338; quic=51303337; quic=51303335,quic=":443"; ma=2592000; v="41,39,38,37,35"
cache-control: private
content-length: 335
content-type: application/json; charset=UTF-8
date: Tue, 16 Jan 2018 19:16:21 GMT
server: ESF
status: 403
transfer-encoding: chunked
vary: Origin, X-Origin, Referer
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
-- headers end --
-- body start --
{
  "error": {
    "code": 403,
    "message": "Operation not allowed",
    "status": "PERMISSION_DENIED",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.ResourceInfo",
        "resourceType": "gae.api",
        "description": "The \"appengine.applications.get\" permission is required."
      }
    ]
  }
}

-- body end --
total round trip time (request+response): 1.796 secs
---- response end ----
----------------------
DEBUG: (gcloud.app.deploy) Permissions error fetching application [apps/jstock-android]. Please make sure you are using the correct project ID and that you have permission to view applications on the project.
Traceback (most recent call last):
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\lib\googlecloudsdk\calliope\cli.py", line 797, in Execute
    resources = calliope_command.Run(cli=self, args=args)
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\lib\googlecloudsdk\calliope\backend.py", line 757, in Run
    resources = command_instance.Run(args)
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\lib\surface\app\deploy.py", line 65, in Run
    parallel_build=False)
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\lib\googlecloudsdk\command_lib\app\deploy_util.py", line 543, in RunDeploy
    app = _PossiblyCreateApp(api_client, project)
  File "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\lib\googlecloudsdk\command_lib\app\deploy_util.py", line 703, in _PossiblyCreateApp
    api_client._FormatApp())))  # pylint: disable=protected-access
HttpException: Permissions error fetching application [apps/jstock-android]. Please make sure you are using the correct project ID and that you have permission to view applications on the project.
ERROR: (gcloud.app.deploy) Permissions error fetching application [apps/jstock-android]. Please make sure you are using the correct project ID and that you have permission to view applications on the project.

C:\Users\yccheok\Desktop\jstock-android-appengine>

然后,我通过https://cloud.google.com/appengine/docs/admin-api/accessing-the-api,它提到我需要使用Admin API。所以,我一步一步小心翼翼地做。

步骤 1

第二步

它提到 Admin API 已启用。现在我需要凭据。

第三步

第四步

好的。现在他们提到我不需要创建新的凭证。我可以使用 应用程序默认凭据 ?!

第 5 步

所以,我去了https://developers.google.com/identity/protocols/application-default-credentials?hl=en_GB。我知道我需要跑步

C:\Users\yccheok\Desktop\jstock-android-appengine>gcloud auth application-default login
Your browser has been opened to visit:

    https://accounts.google.com/o/oauth2/auth?redirect_uri=http%3A%2F%2Flocalhost%3A8085%2F&prompt=select_account&response_type=code&client_id=764086051850-6qr4p6gpi6hn506pt8ejuq83di341hur.apps.googleusercontent.com&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform&access_type=offline



Credentials saved to file: [C:\Users\yccheok\AppData\Roaming\gcloud\application_default_credentials.json]

These credentials will be used by any library that requests
Application Default Credentials.

第 6 步

第 7 步


不过,在完成上述 7 个步骤后,我在尝试运行时仍然收到完全相同的错误消息

gcloud app deploy app.yaml --log-http --verbosity=debug

谁能告诉我,为了使用 Google Cloud SDK 将我的 Python 应用程序部署到 Google App Engine,我还需要什么步骤?

【问题讨论】:

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


    【解决方案1】:

    Admin API 用于以编程方式部署应用程序,而不是使用 gcloud app deploy 进行部署,您甚至不需要为您的应用程序启用 Admin API。

    来自Deploying a Python App

    要以编程方式部署您的应用,请使用the Admin API

    开始之前

    在部署应用之前:

    (但我可以看到上述内容可能会被误解为使用 Admin API 的邀请)

    gcloud app deploy 实际使用的帐户很可能丢失或没有所需的权限。

    您可以检查与gcloud auth list 一起使用的帐户。在我的情况下,该帐户是我的电子邮件地址,而不是服务帐户(我不确定是否可以使用服务帐户)。

    如果您需要其他帐户,请使用 gcloud auth login(也可能是 gcloud auth revoke)。

    您可以在the IAM Page 上查看该帐户在项目/应用上的权限(如果有)。

    【讨论】:

    • 撤销访问权限是删除另一个项目的身份验证的关键。
    【解决方案2】:

    对此的补充说明, 当您启用 App Engine API 和 cloud builder api 时,请确保 Cloud Build Service Account 也有权访问该项目。

    我在启用正确的 api 后遇到了这个问题。

    这是使用构建触发器。我可以从命令行进行本地部署,因为我已通过自己的身份验证。但是,如果您使用的是构建触发器,它将使用需要访问权限的构建服务帐户。

    希望这会有所帮助。

    【讨论】:

    • 您的回答帮助我解决了我的问题:我的default Cloud Build Service Account was missing the "App Engine Deployer" role。谢谢!
    • 这就是问题所在!如果您希望云构建能够将服务升级到最新版本或参与流量拆分,您可能还希望将“App Engine 服务管理员”角色授予云构建服务帐户。
    • @GovindRai 但gcloud app deploy 应该还能用吗?还是您的意思是只有gcloud app deploy --no-promote 可以工作?
    • 这是个好问题。我不完全确定,但可能 - no-promote 应该可以工作,因为它只是部署而不是拆分流量。试试看?
    【解决方案3】:

    我遇到了这个问题。在我的情况下,它是通过使用项目 ID 而不是项目名称设置项目来解决的。看到这个答案

    gcloud app deploy ERROR: Permissions error fetching application [apps/<PROJECT_NAME>]

    【讨论】:

    • 用项目ID替换项目名称对我有用,谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-18
    • 2016-06-02
    • 2014-01-03
    • 1970-01-01
    • 1970-01-01
    • 2019-10-25
    相关资源
    最近更新 更多