如何解决AWS ECR docker 登录成功,但无法拉/推root 用户 IAM 也不起作用相同的配置适用于另一台主机
任务:拉取镜像并将其推送到 AWS ECR(私有)
状态:在一台 Ubuntu 20 主机上工作,在另一台 Ubuntu 20 主机上不工作
简要:我有 IAM,并且能够从工作的 Ubuntu 20 主机推送和拉取。还有另一个主机,我尝试了 IAM,我什至为 root 用户创建了一对凭据,但仍然没有运气。我尝试了 docker login
方法和 https://github.com/awslabs/amazon-ecr-credential-helper
。
作品来自19.03.8
。
从 19.03.12
不起作用,更新到 Docker 20.10.5
,仍然不起作用。
完整说明。
使用docker登录
-
docker login
(零实际上包含我的 acc id)
$ aws ecr get-login-password --region us-east-2 | docker login --username AWS --password-stdin 000000000000.dkr.ecr.us-east-2.amazonaws.com
WARNING! Your password will be stored unencrypted in /home/username/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
-
$ cat ~/.docker/config.json
(零实际上包含我的 acc id)
{
"auths": {
"000000000000.dkr.ecr.us-east-2.amazonaws.com": {
"auth": "QVd[REMOVED A LOT OF CHARACTERS]Q=="
}
}
}
cat ~/.aws/credentials
[default]
aws_access_key_id=A......A
aws_secret_access_key=x.......Q
-
docker pull
(注意:(a) 图像存在 (b) 我可以从第一个 Ubuntu 中拉取和推送 (c) 我用 root 用户凭据替换凭据以进行测试;同样的事情发生在常规用户信用)
$ docker pull 000000000000.dkr.ecr.us-east-2.amazonaws.com/imagename:latest
Error response from daemon: pull access denied
for 000000000000.dkr.ecr.us-east-2.amazonaws.com/imagename:latest,repository does not exist or may require 'docker login': denied: User: arn:aws:iam::000000000000:root is not authorized to perform:ecr:BatchGetImage on resource: arn:aws:ecr:us-east-2:000000000000:repository/imagename
使用 aws-ecr-helper
$ cat ~/.docker/config.json
{
"credsStore": "ecr-login"
}
$cat ~/.ect/cache.json
$ cat cache.json
{
"Registries": {
"us-east-2-Q[REMOVED]s+EJ+-000000000000": {
"AuthorizationToken": "QV[REMOVED LOTS OF CHARACTERS]0=","RequestedAt": "2021-03-07T12:26:37.65116332+01:00","ExpiresAt": "2021-03-07T23:26:37.605Z","ProxyEndpoint": "https://000000000000.dkr.ecr.us-east-2.amazonaws.com","Service": "ecr"
}
},"Version": "1.0"
}
docker pull
$ docker pull 000000000000.dkr.ecr.us-east-2.amazonaws.com/imagename:latest
Error response from daemon: pull access denied
for 000000000000.dkr.ecr.us-east-2.amazonaws.com/imagename:latest,repository does not exist or may require 'docker login': denied: User: arn:aws:iam::000000000000:root is not authorized to perform:
ecr:BatchGetImage on resource: arn:aws:ecr:us-east-2:000000000000:repository/imagename
只是为了澄清。与普通用户和 root 完全相同的配置在另一台主机上工作。请建议下一步去哪里。谢谢。
更新。工作和不工作的主机都在 AWS 生态系统之外。
更新 #2。 我启用了 CloudTrail 日志,这让我可以从 Amazon 的角度查看请求。 所以基本上我在两台电脑上做完全一样的事情。同时,我从第一个收到结果,而从第二个收到拒绝访问。 基本上这意味着两个请求都到达了 AWS,问题是,为什么第二个桌面没有访问权限。
从桌面连接后登录,有效
(000000000000 是我的帐号)
eventVersion "1.08"
userIdentity
type "Root"
principalId "000000000000"
arn "arn:aws:iam::000000000000:root"
accountId "000000000000"
accessKeyId "A[DELETED]Q"
sessionContext
sessionIssuer {}
webIdFederationData {}
attributes
mfaAuthenticated "false"
creationDate "2021-03-07T19:19:57Z"
invokedBy "AWS Internal"
eventTime "2021-03-07T19:20:03Z"
eventSource "ecr.amazonaws.com"
eventName "BatchGetImage"
awsRegion "us-east-2"
sourceIPAddress "AWS Internal"
userAgent "AWS Internal"
requestParameters
registryId "000000000000"
repositoryName "imagename"
imageIds
0
imageTag "latest"
acceptedMediaTypes
0 "application/vnd.docker.distribution.manifest.v2+json"
1 "application/vnd.docker.distribution.manifest.list.v2+json"
2 "application/vnd.oci.image.index.v1+json"
3 "application/vnd.oci.image.manifest.v1+json"
4 "application/vnd.docker.distribution.manifest.v1+prettyjws"
5 "application/json"
responseElements null
requestID "e514746b[DELETED]"
eventID "3e6db33d[DELETED]"
readOnly true
resources
0
accountId "000000000000"
ARN "arn:aws:ecr:us-east-2:000000000000:repository/imagename"
eventType "AwsApiCall"
managementEvent true
eventCategory "Management"
recipientAccountId "000000000000"
同时 从桌面连接后登录,总是被拒绝
eventVersion "1.08"
userIdentity
type "Root"
principalId "000000000000"
arn "arn:aws:iam::000000000000:root"
accountId "000000000000"
accessKeyId "A[DELETED]A"
sessionContext
sessionIssuer {}
webIdFederationData {}
attributes
mfaAuthenticated "false"
creationDate "2021-03-07T17:30:12Z"
invokedBy "AWS Internal"
eventTime "2021-03-07T19:02:50Z"
eventSource "ecr.amazonaws.com"
eventName "BatchGetImage"
awsRegion "us-east-2"
sourceIPAddress "AWS Internal"
userAgent "AWS Internal"
errorCode "AccessDenied"
errorMessage "User: arn:aws:iam::000000000000:root is not authorized to perform: ecr:BatchGetImage on resource: arn:aws:ecr:us-east-2:000000000000:repository/imagename"
requestParameters null
responseElements null
requestID "371354a8[DELETED]"
eventID "2f9f0310[DELETED]"
readOnly true
eventType "AwsApiCall"
managementEvent true
eventCategory "Management"
recipientAccountId "000000000000"
考虑凭据的人请注意,您在这些日志下看到的访问密钥不是用户的访问密钥。每个请求的访问密钥都不同(即使来自工作桌面的每个请求都有不同的访问密钥)。
更新 #3。我使用 Docker 18 和新的 aws cli 从第三个 Ubuntu 17 主机检查,它工作正常。所以这绝对是关于设置、docker 或 aws cli,而不是关于 ECR 本身。
更新 #4。我使用 shell 代理(tinyproxy + SSH 隧道)进行了测试,并测试以消除某种影子 IP 禁止的可能性。所以基本上:
- 工作主机通过基于非工作主机的代理继续工作,
- 非工作主机通过基于工作主机的代理不断失败 这意味着特定主机上的 docker 有问题,但再次删除并安装 docker 并不能解决问题。
解决方法
当您确认这不是 IAM 角色问题时,由于以下问题之一,您可能会收到此错误:
您的启动类型无权访问 Amazon ECR 终端节点。
-
如果您的主机位于私有子网中,请确认您的子网在路由表中具有到 NAT 网关的路由。
-
如果您的主机在公共子网中,请确认该实例具有公共 IP 地址。
-
如果您将 AWS PrivateLink 用于 Amazon ECR,请确认与 Amazon ECR 的接口 VPC 终端节点关联的安全组允许来自您的安全组内的通过 HTTPS(端口 443)的入站流量。 VPC CIDR 或您的主机安全组。
确认连接到您的主机的安全组允许以下内容的出站访问:端口 443 上的 HTTPS、端口 53 上的 DNS(UDP 和 TCP)以及您子网的网络访问控制列表(网络 ACL)。
您的 Amazon ECR 存储库策略限制对存储库映像的访问。 以下存储库策略示例允许 IAM 用户推送和拉取映像:
{
"Version": "2008-10-17","Statement": [
{
"Sid": "AllowPushPull","Effect": "Allow","Principal": {
"AWS": [
"arn:aws:iam::123456789012:user/push-pull-user-1","arn:aws:iam::123456789012:user/push-pull-user-2"
]
},"Action": [
"ecr:GetDownloadUrlForLayer","ecr:BatchGetImage","ecr:BatchCheckLayerAvailability","ecr:PutImage","ecr:InitiateLayerUpload","ecr:UploadLayerPart","ecr:CompleteLayerUpload"
]
}
]
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。