8

我正在尝试允许一个 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 <second> <first>)"

我得到了这个结果:

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 <first>.dkr.ecr.us-east-1.amazonaws.com/<repo>:<tag>并得到这个结果:

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.

我不知道还能尝试什么才能拉出这张图片!

Principal将ECR 权限更改为"AWS": "arn:aws:iam::<second>:user/<user>"没有任何区别。

4

2 回答 2

8

我想通了——“第二个”账户中的 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工作了!

于 2019-01-08T20:10:05.250 回答
0

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

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

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

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

于 2019-01-08T18:04:27.970 回答