【问题标题】:Unable to access ECR repository from separate account via `docker pull`无法通过“docker pull”从单独的帐户访问 ECR 存储库
【发布时间】:2019-01-09 04:10:05
【问题描述】:

我正在尝试允许一个 AWS 账户(下面称为“第二个”)在另一个 AWS 账户(下面称为“第一个”)的 ECR 存储库中提取图像。

我正在关注这些文件:

我已将以下权限添加到 ECR 存储库:

{
  "Version": "2008-10-17",
  "Statement": [
    {
      "Sid": "AllowCrossAccountPull",
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::<second>:root"
      },
      "Action": [
        "ecr:BatchCheckLayerAvailability",
        "ecr:BatchGetImage",
        "ecr:GetDownloadUrlForLayer"
      ]
    }
  ]
}

然后我运行这个命令:eval "$(aws ecr get-login --no-include-email --region us-east-1 --profile second --registry-ids &lt;second&gt; &lt;first&gt;)"

我得到了这个结果:

WARNING! Using --password via the CLI is insecure. Use --password-stdin.
WARNING! Your password will be stored unencrypted in /Users/libby/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
WARNING! Your password will be stored unencrypted in /Users/libby/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded

我暂时将商店更改为config.json,以确保我可以看到身份验证已按预期添加到文件中,它是:

{
        "auths": {
                "<second>.dkr.ecr.us-east-1.amazonaws.com": {
                        "auth": "<super long token>"
                },
                "<first>.dkr.ecr.us-east-1.amazonaws.com": {
                        "auth": "<super long token>"
                }
        },
        "HttpHeaders": {
                "User-Agent": "Docker-Client/18.09.0 (darwin)"
        },
        "stackOrchestrator": "swarm"
}

最后我运行:docker pull &lt;first&gt;.dkr.ecr.us-east-1.amazonaws.com/&lt;repo&gt;:&lt;tag&gt; 并得到这个结果:

Error response from daemon: pull access denied for <first>.dkr.ecr.us-east-1.amazonaws.com/<repo>, repository does not exist or may require 'docker login'

我已经三次检查了所有帐号是否正确,回购肯定在那里。如果我使用相同的get-login 命令但--profile first 登录,我可以拉它。

我不确定还可以尝试什么才能拉出这张图片!

将 ECR 权限中的 Principal 更改为 "AWS": "arn:aws:iam::&lt;second&gt;:user/&lt;user&gt;" 没有任何区别。

【问题讨论】:

    标签: amazon-web-services docker aws-iam aws-ecr


    【解决方案1】:

    我想通了——“第二个”账户中的 IAM 用户附加了一个限制其 ECR 访问的策略。政策是:

        {
            "Sid": "ECRAccess",
            "Effect": "Allow",
            "Action": "ecr:*",
            "Resource": "arn:aws:ecr:us-east-1:<second>:repository/<unrelated-repo>"
        }
    

    因此,即使“第一个”帐户中的 ECR 存储库具有允许用户访问的权限,用户自己的帐户也会限制其对单个无关存储库的访问。

    当我使用第一个帐户的存储库 ARN 添加另一个部分时:

        {
            "Sid": "FirstAccountECRAccess",
            "Effect": "Allow",
            "Action": "ecr:*",
            "Resource": "arn:aws:ecr:us-east-1:<first>:repository/<repo>"
        }
    

    然后docker pull 工作了!

    【讨论】:

    • 谢谢!我一开始持怀疑态度,但当我看到限制访问 AWS::AccountId 的政策时,我感到很震惊
    【解决方案2】:

    您的第二个账户是否在您的计算机上使用 IAM 用户?因为在您的政策中,您在第二个帐户访问权限时授予了 root 用户:

    "Principal": { "AWS": "arn:aws:iam::<second>:root" },

    考虑在您的政策中将其更改为:

    "Principal": { "AWS": "arn:aws:iam::<second>:user/[nameofuser]" },

    【讨论】:

    • 不幸的是,这似乎没有什么不同。
    猜你喜欢
    • 2021-01-23
    • 2021-10-29
    • 1970-01-01
    • 2017-01-01
    • 2021-01-29
    • 1970-01-01
    • 2021-04-07
    • 2020-10-03
    • 1970-01-01
    相关资源
    最近更新 更多