如何使用HTTP API从gcr.io Docker Registry列出图像和标签?
我试图从Node.js中的Google Container Registry(gcr.io)中获取可用图像及其标签的列表。
我首先使用google-auto-auth
来调用范围为https://www.googleapis.com/auth/devstorage.read_write
的令牌,然后将该令牌gcr.io
令牌,如下所示:
axios.get('https://gcr.io/v2/token?service=gcr.io', { auth: { username: '_token', password: token // token I got from `google-auto-auth` } })
然后我尝试使用它来调用v2/_catalog
端点:
axios.get('https://gcr.io/v2/_catalog', { headers: { Authorization: `Bearer ${gcrToken}` } })
我得到以下错误:
{ errors: [ { code: 'DENIED', message: 'Failed to retrieve projects.' } ] }
公平的,它必须要求我的项目ID,但我应该在哪里提供它?
只是为了看看我能不能做其他工作,我试过了:
axios.get('https://gcr.io/v2/my-project-id/my-image/tags/list', { headers: { Authorization: `Bearer ${gcrToken}` } })
我回头看看以下内容:
{ errors: [ { code: 'NAME_INVALID', message: 'Requested repository does not match bearer token resource: my-project-id/my-image' } ] }
我如何从gcr.io中读取图像信息?
第一个错误可能是因为您缺less列出项目的范围之一: https : //cloud.google.com/resource-manager/reference/rest/v1/projects/list#authorization
你会得到第二个错误,因为你在代币交换中缺less范围。
你想要的东西像:
https://gcr.io/v2/token?service=gcr.io&scope=repository:<my-project-id/my-image>:*
看到这里的例子: https : //docs.docker.com/registry/spec/auth/token/#requesting-a-token
在与GCR的Jon Johnson进行了广泛的交stream后,我们终于find了错误的地方。 如果你赞成这个答案,请同时赞扬乔恩,他超越这个问题解决了这个问题。
这篇文章中大部分都没有记载。
- 需要使用
registry:catalog:*
范围。 - 我的照片被推到了
us.gcr.io
,他们把他们当作独立的登记处 – 我以为他们是镜子。 - 该服务帐户必须在Google Cloud IAM中具有
Project Viewer
angular色。 - 您可以使用GCR令牌以及Google云端令牌。 但是,尽pipeGCR令牌不能与
Basic base64(_token:<token>)
,但Google云令牌可以。
获取GCR标记
// Updated host axios.get('https://us.gcr.io/v2/token?service=gcr.io', { params: { service: 'us.gcr.io', scope: `registry:catalog:*` }, auth: { username: '_token', password: token // token I got from `google-auto-auth` }, })
使用令牌列出存储库
const client = axios.create({ baseURL: `https://us.gcr.io/v2`, headers: { Authorization: `Bearer ${token}` } }) client.get('/_catalog').then((response) => { console.log(response.data.repositories) })