简体   繁体   English

如何让 Docker Swarm 管理器使用 IAM 角色权限从 AWS ECR 中提取图像?

[英]How do I get a Docker Swarm manager to pull images from AWS ECR using IAM Role permissions?

I'm having trouble pulling images from AWS ECR, running Docker Swarm.我无法从 AWS ECR 中提取图像,运行 Docker Swarm。 It's been working ok for years, but my swarm manager nodes were changed to new EC2 instances.多年来一直运行良好,但我的 swarm 管理器节点已更改为新的 EC2 实例。 Now my services fail to deploy:现在我的服务无法部署:

~ $ docker stack deploy -c dkr_compose_geo_site:3.2.0 --with-registry-auth geo_stack

The manager node log shows "no basic auth credentials":管理器节点日志显示“没有基本身份验证凭据”:

May 19 21:21:12 ip-172-31-3-108 root: time="2020-05-19T21:21:12.857007050Z" level=error msg="pulling image failed" error="Get https://445523.dkr.ecr.us-west-2.amazonaws.com/v2/geo_site/manifests/sha256:da5820742cd0ecd52e3a2c61179a039ce80996564604b70465e3966087380a09: no basic auth credentials" module=node/agent/taskmanager node.id=eix8c6orbunemismg03ib1rih service.id=smilb788pets7y5rgbu3aze9l task.id=zd3ozdpr9exphwlz318pa9lpe 
May 19 21:21:12 ip-172-31-3-108 root: time="2020-05-19T21:21:12.857701347Z" level=error msg="fatal task error" error="No such image: 445523.dkr.ecr.us-west-2.amazonaws.com/geo_site@sha256:da5820742cd0ecd52e3a2c61179a039ce80996564604b70465e3966087380a09" module=node/agent/taskmanager node.id=eix8c6orbunemismg03ib1rih service.id=smilb788pets7y5rgbu3aze9l task.id=zd3ozdpr9exphwlz318pa9lpe 

This manager node is running on an EC2 Instance with an IAM Role;此管理器节点在具有 IAM 角色的 EC2 实例上运行; the IAM Role has an ECR policy that appears to grant permissions: IAM 角色具有似乎授予权限的 ECR 策略:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Action": [
                "ecr:GetAuthorizationToken",
                "ecr:BatchCheckLayerAvailability",
                "ecr:GetDownloadUrlForLayer",
                "ecr:GetRepositoryPolicy",
                "ecr:DescribeRepositories",
                "ecr:ListImages",
                "ecr:DescribeImages",
                "ecr:BatchGetImage"
            ],
            "Resource": "*",
            "Effect": "Allow"
        }
    ]
}

From reading the AWS/Docker docs, I thought docker commands run on a manager node should adopt the Instance IAM Role and access the ECR repo using the associated policy permissions.通过阅读 AWS/Docker 文档,我认为在管理器节点上运行的 docker 命令应该采用实例 IAM 角色并使用关联的策略权限访问 ECR 存储库。 It's always seemed to work that way, but now it's looking like there might have been some config file hidden on the old manager node;它似乎总是以这种方式工作,但现在看起来可能在旧的管理器节点上隐藏了一些配置文件; I'm on a new instance and it doesn't work.我在一个新实例上,它不起作用。 I don't run an AWS-CLI on these manager nodes, so there's no aws ecr get-login to login manually.我没有在这些管理器节点上运行 AWS-CLI,因此没有手动登录的aws ecr get-login How do I get this new manager node to authenticate with ECR?如何让这个新的管理器节点通过 ECR 进行身份验证?

Thanks!谢谢!

My solution, based on comment by Luigi Lopez and amazon-ecr-credential-helper :我的解决方案,基于 Luigi Lopez 和amazon-ecr-credential-helper 的评论:

The AWS IAM Role allows authentication, but the docker cli must still present credentials to the ECR, as Luigi pointed out in his comment.正如 Luigi 在评论中指出的那样,AWS IAM 角色允许身份验证,但 docker cli 仍必须向 ECR 提供凭证。

This is a Docker Swarm implementation, with nodes running the Alpine OS.这是一个 Docker Swarm 实现,节点运行 Alpine OS。 There is an aws-cli package available for Alpine, but the installation took a lot of fussing around and in the end the binary crashed anyway.有一个适用于 Alpine 的aws-cli package,但是安装过程非常麻烦,最终二进制文件还是崩溃了。

The Amazon ECR Credential Helper is a better long-term solution in any case because you don't need to get new tokens every 12 hours or set up a proxy server, etc. It uses the recommended IAM Role authentication, with no credentials stored on the machine or leaking into log files. Amazon ECR Credential Helper 在任何情况下都是更好的长期解决方案,因为您不需要每 12 小时获取新令牌或设置代理服务器等。它使用推荐的 IAM 角色身份验证,不存储任何凭证机器或泄漏到日志文件中。

So under Alpine I followed the instructions in the link above to build from sources.所以在 Alpine 下,我按照上面链接中的说明从源代码构建。 I installed go, git, and make, and then built the credential-helper as described.我安装了 go、git 并制作,然后按照描述构建了凭证助手。 I set up the PATH as described, created a config file, and then my deployment worked.我按照描述设置了 PATH,创建了一个配置文件,然后我的部署工作了。 There's no docker login required.无需docker login

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

相关问题 从 AWS EC2 上的 AWS ECR 中提取图像而不使用 docker login 但使用 EC2 Instance 角色和 ECR 存储库权限 - Pull images from AWS ECR on AWS EC2 without using docker login but using EC2 Instance role and ECR repository permissions 为什么无法在Docker集群中自动从AWS上的ECR中提取图像? - Why can't pull images from ecr on aws automatically in a docker swarm cluster? 如何从Vagrant中的隐私AWS ECR存储库中获取Docker映像 - How to get docker images from privacy AWS ECR repository in Vagrant 如何在 Terraform for Amazon ECR 中创建 IAM 角色? - How do I create an IAM role in Terraform for Amazon ECR? 是否可以在不使用 docker 登录的情况下从 ECR 中提取图像 - Is it possible to pull images from ECR without using docker login 如何匿名从 AWS ECR docker 镜像中提取? - How to pull from AWS ECR docker image anonymously? AWS:AWS IAM 角色和 IAM 用户权限相加吗 - AWS: Do the AWS IAM role and IAM user permissions add up 使用api密钥的docker swarm和aws ecr身份验证 - docker swarm and aws ecr authentication using api keys 您如何管理您假定的角色IAM策略以访问AWS Secret Manager中的机密? - how do you manager your assumed role IAM policies to access secrets in AWS secret manager? 如何使用 python boto3 将新角色权限附加到 aws 中的 iam_role? - How to attach new role permissions to iam_role in aws using python boto3?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM