GitLab CI Runner无法提取私有Docker映像w&引用;无基本身份验证凭据”;但它是通过SSH工作的
我已经研究了有关的问题,所以这似乎不是一个重复 当GitLab CI Runner从AWS ECR提取映像时,它会失败,并出现以下错误:GitLab CI Runner无法提取私有Docker映像w&引用;无基本身份验证凭据”;但它是通过SSH工作的,docker,gitlab,gitlab-ci,amazon-ecs,gitlab-ci-runner,Docker,Gitlab,Gitlab Ci,Amazon Ecs,Gitlab Ci Runner,我已经研究了有关的问题,所以这似乎不是一个重复 当GitLab CI Runner从AWS ECR提取映像时,它会失败,并出现以下错误: ERROR: Preparation failed: API error (500): \ Get https://***.dkr.ecr.***.amazonaws.com/v2/***/manifests/latest: no basic auth credentials 但是我已经用ECR凭据设置了机器,我可以通过SSH进入机器,并且root和gi
ERROR: Preparation failed: API error (500): \
Get https://***.dkr.ecr.***.amazonaws.com/v2/***/manifests/latest: no basic auth credentials
但是我已经用ECR凭据设置了机器,我可以通过SSH进入机器,并且root
和gitlab runner
用户都可以拉取映像。直到最近,这一切都很正常,但我不知道会发生什么变化
“没有基本授权”意味着什么
具体来说,我已经完成了以下步骤:
- 启动一个普通的AWSEC2 Linux实例,并将SSH插入其中
没有基本的身份验证凭据。。为什么?有什么理论吗?感谢所有的帮助和想法
编辑:FWIW。拥有Gitlab进程的linux用户可能没有所需的凭据。您可以通过运行sudo-u-H
或者,您可以将--user
参数传递给runner命令,以使用可以登录到ECR的linux用户 我开始使用AWS ECR访问权限运行我的GitLab runner。
我使用了UBUNTU18AMI,并在ec2配置的用户数据中使用了下面的脚本,或者可以通过ssh将脚本作为root运行到服务器中。
将角色附加到具有足够ECR访问权限的EC2实例
要点链接:https://gist.github.com/piyushsonigra/6f67210aefcbee8071f46dc764fa8936
#!/bin/bash
set -e
apt update -y && apt install awscli make -y
curl -LJO https://gitlab-runner-downloads.s3.amazonaws.com/latest/deb/gitlab-runner_amd64.deb
dpkg -i gitlab-runner_amd64.deb
sed -i -e '/volumes/s/\["\/cache\"]/\["\/cache","\/var\/run\/docker.sock:\/var\/run\/docker.sock"]/' /etc/gitlab-runner/config.toml
curl -fsSL https://get.docker.com -o get-docker.sh && sh get-docker.sh && usermod -aG docker gitlab-runner
gitlab-runner register \
--non-interactive \
--url $GITLAB_URL \
--registration-token $TOKEN \
--executor "docker" \
--docker-image "docker:latest" \
--description "gitlab-runner" \
--tag-list "gitlab,runner,aws" \
--run-untagged="true" \
--locked="false" \
--access-level="not_protected"
echo -e "export AWS_SDK_LOAD_CONFIG=true \nexport AWS_REGION=$REGION >> ~/.bashrc
source ~/.bashrc && mkdir ~/.docker
cat <<EOF >>~/.docker/config.json
{
"credsStore": "ecr-login"
}
EOF
git clone https://github.com/awslabs/amazon-ecr-credential-helper.git
cd amazon-ecr-credential-helper/ && make docker
cp bin/local/docker-credential-ecr-login /usr/local/bin/
systemctl restart docker && gitlab-runner restart
export AWS_REGION=$REGION && docker-credential-ecr-login list >> ~/.ecr-url.log
Yeah Runner正在使用用户gitlab Runner
,该用户本机无权访问Docker,因此无法将其登录到ECR。但我已经这样做了(暴露了docker.sock
+二进制文件),并使docker从中拉出
,但GitLab Runner仍然显示相同的错误。此外,我找不到任何文章表明这是主要原因。这是一个很好的建议,但我开始相信这不是正确的方法。将Docker暴露给用户感觉像是一个令人讨厌的黑客行为,而且过去没有必要这样做。但是很高兴尝试更多的可能性,你知道我如何改变用户吗?这是在AWS Linux上,我仍在寻找它在哪里指定--user标志。您是否尝试将--user
选项与gitlab runner
一起使用?我不知道实际在哪里。谷歌搜索还没有帮到我。我可以看到该标志用于ps aux
,但是[羞愧地垂下头]我不知道在AWS Linux上该值传递到服务的何处。谢谢!我已将其重新配置为使用root和。。同样的结果:(.ps aux
显示它运行w.--user root
。我发现这令人惊讶。
#!/bin/bash
set -e
apt update -y && apt install awscli make -y
curl -LJO https://gitlab-runner-downloads.s3.amazonaws.com/latest/deb/gitlab-runner_amd64.deb
dpkg -i gitlab-runner_amd64.deb
sed -i -e '/volumes/s/\["\/cache\"]/\["\/cache","\/var\/run\/docker.sock:\/var\/run\/docker.sock"]/' /etc/gitlab-runner/config.toml
curl -fsSL https://get.docker.com -o get-docker.sh && sh get-docker.sh && usermod -aG docker gitlab-runner
gitlab-runner register \
--non-interactive \
--url $GITLAB_URL \
--registration-token $TOKEN \
--executor "docker" \
--docker-image "docker:latest" \
--description "gitlab-runner" \
--tag-list "gitlab,runner,aws" \
--run-untagged="true" \
--locked="false" \
--access-level="not_protected"
echo -e "export AWS_SDK_LOAD_CONFIG=true \nexport AWS_REGION=$REGION >> ~/.bashrc
source ~/.bashrc && mkdir ~/.docker
cat <<EOF >>~/.docker/config.json
{
"credsStore": "ecr-login"
}
EOF
git clone https://github.com/awslabs/amazon-ecr-credential-helper.git
cd amazon-ecr-credential-helper/ && make docker
cp bin/local/docker-credential-ecr-login /usr/local/bin/
systemctl restart docker && gitlab-runner restart
export AWS_REGION=$REGION && docker-credential-ecr-login list >> ~/.ecr-url.log
image: aws_account_id.dkr.ecr.REGION.amazonaws.com/IMAGE_NAME:latest
build:
stage: build
script:
- echo "hello"