authentication - 无法从 Google Container VM 镜像访问服务帐户的元数据 token

标签 authentication metadata google-cloud-platform

我从 VM 镜像登录到 Google Compute Engine 实例,详细信息 here .

我想按照访问私有(private)容器注册表的说明进行操作,但在请求 token 时收到 403 错误。

试试这个:

$ METADATA=http://metadata.google.internal/computeMetadata/v1
$ SVC_ACCT=$METADATA/instance/service-accounts/default
$ ACCESS_TOKEN=$(curl -H 'Metadata-Flavor: Google' $SVC_ACCT/token \
    | cut -d'"' -f 4)
$ docker login -e 1234@5678.com -u _token -p $ACCESS_TOKEN https://gcr.io
$ docker run --rm gcr.io/<your-project>/<your-image> <command>

..我没有找到访问 token 并且失败了。

尝试调用元数据我可以看到:
> curl "http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/" -H "Metadata-Flavor: Google"

aliases
email
scopes
token

...但是当我尝试获取 token 时,出现 403 错误:
> curl "http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token" -H "Metadata-Flavor: Google"

<!DOCTYPE html>
<html lang=en>
  <meta charset=utf-8>
  <meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
  <title>Error 403 (Forbidden)!!1</title>
  <style>
    *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}
  </style>
  <a href=//www.google.com/><span id=logo aria-label=Google></span></a>
  <p><b>403.</b> <ins>That’s an error.</ins>
  <p>Your client does not have permission to get URL <code>/computeMetadata/v1/instance/service-accounts/default/token</code> from this server.  <ins>That’s all we know.</ins>

我已经设置了 default compute engine service account to be an owner项目(它在编辑器上)并再次尝试,没有运气。

我已经尝试了如下详述的 SO 解决方案,但它们不起作用:
  • How to upload file from google cloud instance to cloud storage with IAM?
  • Access google container registry without the gcloud client
  • gcloud docker push 403 Forbidden

  • 并在此处查阅了 Google 文档:
  • https://cloud.google.com/compute/docs/storing-retrieving-metadata#querying

  • 关于如何获得成功的身份验证,我是否遗漏了什么?如果您有任何建议,非常感谢!

    最佳答案

    赞美上帝,我创建的实例没有正确的范围。

    您可以在编辑实例屏幕中查看 GCE UI,由于通过 {"https://www.googleapis.com/auth/cloud-platform"} 我没有 Google API Cloud 访问权限而不是 ["https://www.googleapis.com/auth/cloud-platform"]在 API 请求中。

    此命令现在可以正确返回身份验证 token :

    > curl "http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token" -H "Metadata-Flavor: Google"
    
    {"access_token":"ya29.XXXXX","expires_in":3599,"token_type":"Bearer"}
    

    关于authentication - 无法从 Google Container VM 镜像访问服务帐户的元数据 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39855989/

    相关文章:

    authentication - CakePHP - 两种类型的用户进行身份验证

    sql - 如何在 SQL Server (2005) 中找到 WITH RECOMPILE 元数据?

    google-cloud-platform - gcloud : show quota limits for SimulateMaintenanceEvent

    docker - 我正在尝试在Google Cloud Compute VM实例上运行Docker 'hello-world'应用程序,但似乎无法通过Web浏览器访问输出

    mongodb - 如何在 mongodb 配置文件中设置授权?

    MongoDB super 用户身份验证总是失败

    javascript - 向 HTML 元素添加附加信息(元)

    ruby - 使用 ruby​​ 读取视频文件元数据

    google-cloud-platform - 授予代理 SQL 访问 Google Colaboratory 的权限

    php - 注销按钮将用户重定向到同一页面,而不是将用户注销