繁体   English   中英

从gitlab-ci推送到gcr.io,在存储管理员中获得storage.buckets.get权限

[英]Pushing to gcr.io from gitlab-ci, storage.buckets.get permission in storage admin

我正在组装一个gitlab CI管道,用于构建,测试,推送和部署react应用程序。

现在一切正常,除了将图像推送到GCR。

这是我管道中的一部分:

image: docker:stable

stages:
  - build
  - test
  - push-artifacts
  - deploy-dev
  - deploy-prod

services:
  - docker:dind

...

publish: 
  stage: push-artifacts

  script:
    - echo "$GCLOUD_SERVICE_KEY" | base64 -d > /gcloud-service-key.json
    - cat /gcloud-service-key.json | docker login -u _json_key --password-stdin https://$IMAGE_ROOT
    - docker build -t $IMAGE_REPO:$CI_BUILD_REF -f builder/Dockerfile -t $IMAGE_REPO:latest .
    - docker push $IMAGE_REPO

我正在使用同时具有Storage Admin和Storage Object Admin IAM的gitlab-ci服务帐户。

我正在使用dind和docker-builder。 这是我的建造者dockerfile

FROM docker:stable

# add dependencies
RUN apk add --update make ca-certificates openssl python curl bash tree git jq && \
    update-ca-certificates

WORKDIR /
RUN cd / && wget https://dl.google.com/dl/cloudsdk/release/google-cloud-sdk.tar.gz && \
    tar zxvf google-cloud-sdk.tar.gz && \
    ./google-cloud-sdk/install.sh --usage-reporting=false --path-update=true

# add gcloud to PATH
ENV PATH="/google-cloud-sdk/bin/:${PATH}"

# update and auth
RUN gcloud --quiet components update && \
    gcloud components install kubectl 

# install helm
RUN curl https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get | bash
ENV GOOGLE_APPLICATION_CREDENTIALS=/gcloud-service-key.json 
RUN helm init --client-only && helm plugin install https://github.com/nouney/helm-gcs 

react Dockerfile只是一个常规的reactapp dockerfile, serve命令。 但推动部分仍然失败

Successfully built bd60c4bb569e
Successfully tagged eu.gcr.io/project_name/app:46d1e4beea041acef9ca003f452ee4cbda85d5dd
Successfully tagged eu.gcr.io/project_name/app:latest
$ docker push $IMAGE_REPO
The push refers to repository [eu.gcr.io/project_name/app]
11762a30dfcd: Preparing
f475c6042475: Preparing
526599eebb83: Preparing
c328c8c7f46b: Preparing
71d6c8e5f47f: Preparing
48b131779e9d: Preparing
4b2ccfc1ebff: Preparing
2f810bf9ddab: Preparing
968d46c1d20e: Preparing
b87598efb2f0: Preparing
f1b5933fe4b5: Preparing
48b131779e9d: Waiting
4b2ccfc1ebff: Waiting
2f810bf9ddab: Waiting
968d46c1d20e: Waiting
b87598efb2f0: Waiting
f1b5933fe4b5: Waiting
denied: Token exchange failed for project 'project_name'. Caller does not have permission 'storage.buckets.get'. To configure permissions, follow instructions at: https://cloud.google.com/container-registry/docs/access-control

登录成功,但仍然存在权限问题。 为什么?

我的base64编码的服务令牌json密钥位于gitlab环境变量中。

我可以看到您正在使用服务帐户或用户帐户(gcloud-service-key.json的所有者)访问您的项目,但是您需要在帐户中添加存储管理员角色,请选中此链接作为授予的参考角色。

它缺少存储写入作用域,如果要使用docker命令行,另一种解决方案是使用gcloud命令行,您已经通过SDK进行身份验证,那么您只需执行gcloud命令即可推送:

gcloud docker -- push $IMAGE_REPO

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM