【问题标题】:use aws-vault to push docker image to ECR failed使用 aws-vault 将 docker 镜像推送到 ECR 失败
【发布时间】:2021-10-21 00:00:48
【问题描述】:

我正在尝试将 docker 映像从我的 mac 推送到 ECR。我将身份添加到 aws-vault,但使用 aws-vault 无法获取密码。我的同伴有同样的权限,他可以毫无问题地登录 ECR。

.aws % aws-vault list                                                                                
    Profile                  Credentials              Sessions                 
    =======                  ===========              ========                 
    identity                 identity                 -                        
.aws % ENCRYPTED_PASSWORD=$(aws-vault exec identity -- aws ecr get-login-password --region us-west-2)
    
    An error occurred (AccessDeniedException) when calling the GetAuthorizationToken operation: User: arn:aws:iam::97xxxxxxxxxx:user/xxxxx.xxxxxx@xxxxxxxxx.com is not authorized to perform: ecr:GetAuthorizationToken on resource: * with an explicit deny in an identity-based policy

我们使用的是同一个角色。我打算在获得 ENCRYPTED_PASSWORD 后执行以下行--

aws-vault exec identity -- aws ecr --region us-west-2 | docker login -u AWS -p ${ENCRYPTED_PASSWORD} xxxxxxxxxxxx.dkr.ecr.us-west-2.amazonaws.com/my-ecr

我的 .aws/config 有这行参考上面。

[profile identity]

由于我的队友拥有相同的策略/权限,我不认为“GetAuthorizationToken”是个问题。还有什么?我正在尝试找到一种方法将我的 docker 图像从 Mac 推送到 ECR。

完全重做配置,将所有角色与身份相关联。

[profile xx-xxxx-services-monitoring]
role_arn=arn:aws:iam::xxxxxxxxxxxx:role/XXMonitoring
source_profile=identity
sparent_profile=mfa

[profile identity]

现在是令牌问题——我从 MFA Authenticator 输入了代码但失败了

.aws % aws-vault exec xx-xxxx-main-admin  -- aws ecr get-login --region us-west-2
Warning: parent_profile is deprecated, please use include_profile instead in your AWS config
Enter token for arn:aws:iam::xxxxxxxxxxxx:mfa/xxxxxx.xxxx@xxxxxx.com: **125492**
aws-vault: error: exec: Failed to get credentials for xx-xxxx-main-admin: AccessDenied: MultiFactorAuthentication failed, unable to validate MFA code.  Please verify your MFA serial number is valid and associated with this user.
    status code: 403, request id: 25808115-d9fa-480d-87d4-xxxxxxxxxxxxx

从 Authenticator MFA 来看,令牌似乎无效

【问题讨论】:

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


    【解决方案1】:
    1. 第一个 aws-vault "GetAuthorizationToken" 是由不健康、格式错误的 ~/.aws/config 文件引起的。必须使用以下格式指定角色--

      [profile xx-xxxx-services-monitoring] role_arn=arn:aws:iam::xxxxxxxxxxxx:role/XXMonitoring source_profile=身份 parent_profile=mfa

      [个人资料身份]

    2. 第二部分是 MFA 问题。 MFA 序列号必须与您在身份验证器中配置的相匹配。 (DUO, Authy, Authenticator...) 你的 ~/.aws/config 应该有这个部分--

      [个人资料 mfa] mfa_serial=arn:aws:iam::xxxxxxxxxxx:mfa/xxxxx.xxxx@xxxxx.com

    【讨论】:

      猜你喜欢
      • 2020-02-13
      • 2018-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-30
      • 1970-01-01
      • 2018-06-17
      相关资源
      最近更新 更多