【问题标题】:Insufficient Permission with Appengine Flex service account to access Drive folderAppengine Flex 服务帐户的权限不足,无法访问云端硬盘文件夹
【发布时间】:2016-05-10 16:27:53
【问题描述】:

我已经编写了一个应用程序,它使用官方记录的所有客户端/sdk。

credentials = GoogleCredentials \
    .get_application_default() \
    .create_scoped('https://www.googleapis.com/auth/drive')
drive = discovery.build(
    'drive',
    'v3',
    http=self.credentials.authorize(Http())
)
drive.files() \
    .get(fileId=file_id) \
    .execute()

它在本地使用面板生成的服务帐户完美运行,但是当我部署应用程序时,AppEngine 柔性环境中的服务帐户遇到问题。

17:15:04.000 /env/lib/python3.4/site-packages/oauth2client/contrib/gce.py:99: UserWarning: You have requested explicit scopes to be used with a GCE service account. 17:15:04.000 Using this argument will have no effect on the actual scopes for tokens 17:15:04.000 requested. These scopes are set at VM instance creation time and 17:15:04.000 can't be overridden in the request. 17:15:04.000 17:15:04.000 warnings.warn(_SCOPES_WARNING) 17:15:04.000 INFO:googleapiclient.discovery:URL being requested: GET https://www.googleapis.com/discovery/v1/apis/drive/v3/rest 17:15:04.000 INFO:oauth2client.client:Attempting refresh to obtain initial access_token 17:15:04.000 INFO:googleapiclient.discovery:URL being requested: GET https://www.googleapis.com/drive/v3/files/0B0Kn....M1pBNFE?alt=json 17:15:04.000 ERROR:root:Failed to retrieve file 0B0K....M1pBNFE. Is it shared with me? project-id@appspot.gserviceaccount.com 17:15:04.000 Traceback (most recent call last): 17:15:04.000 File "/home/vmagent/app/script.py", line 45, in get 17:15:04.000 .execute() 17:15:04.000 File "/env/lib/python3.4/site-packages/oauth2client/util.py", line 135, in positional_wrapper 17:15:04.000 return wrapped(*args, **kwargs) 17:15:04.000 File "/env/lib/python3.4/site-packages/googleapiclient/http.py", line 760, in execute 17:15:04.000 raise HttpError(resp, content, uri=self.uri) 17:15:04.000 googleapiclient.errors.HttpError: <HttpError 403 when requesting https://www.googleapis.com/drive/v3/files/0B0Kn....M1pBNFE?alt=json returned "Insufficient Permission">

我已经检查了权限并且它们都已设置。问题可能是由于尝试创建范围凭据时出现的“使用此参数将无效...”消息。

【问题讨论】:

  • 您遵循哪些文章/指南来实现这一目标?可以提供链接吗?
  • 使用您在上面提供的代码,我无法重现此问题。您的 Drive API 是否在 API 下的开发者控制台中启用?错误消息说明要与 GCE 实例(不是 GAE 应用程序)一起使用的范围。这段代码在哪里运行?
  • 啊,是的。这确实是一个已知问题。很抱歉没有从发布的日志中识别它。我的复制是使用标准环境而不是灵活的环境。为了完整起见,我会将其发布为社区更完整的答案。
  • 虽然这是一个已知问题,但提交的答案是该问题的适当答案。

标签: google-app-engine google-drive-api google-cloud-platform google-managed-vm


【解决方案1】:

正如您在之前的评论中提到的,这是known issue。正如araf...@google.com 所述,柔性环境中的 App Engine 实例似乎将底层 GCE VM 的凭据假定为应用程序默认凭据。

同时,作为一种解决方法,您可以使用手动创建的服务帐户导出为存储在您的应用中的 JSON 密钥,按照 Using OAuth 2.0 for Server to Server Applications

对于受此问题影响或解决方法无效的任何人,请在said issue 上发布任何相关信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-11
    • 2022-11-15
    • 2016-06-01
    • 1970-01-01
    相关资源
    最近更新 更多