【问题标题】:How to make AWS CodeCommit repo accessible to Cognito UserPool Users?如何让 Cognito UserPool 用户可以访问 AWS CodeCommit 存储库?
【发布时间】:2021-05-10 09:04:18
【问题描述】:

尝试让 Cognito UserPool 用户as described here 可以访问 AWS CodeCommit:

  1. 使用AWSCodeCommitPowerUser 创建了一个IAM 角色
  2. 用户池建立信任关系,
  3. 已安装 git-remote-codecommitconfigured the profile
  4. 接下来,尝试以下任一方法:
  • 设置source_profile = default,其中default 凭证配置文件包含一个IAM 用户(错误的方式,但只是为了检查)。
    执行git clone codecommit://CodeAccessProfile@repo 抛出:

An error occurred (AccessDenied) when calling the AssumeRole operation: User: arn:aws:iam::123456789:user/name.surname is not authorized to perform: sts:AssumeRole on resource...

  • 在 Web 应用程序中以 Cognito 用户池用户身份登录,
    从响应中获取 Cognito IdToken
    并使用它调用assume-role-with-web-identity。获取:

An error occurred (InvalidIdentityToken) when calling the AssumeRoleWithWebIdentity operation: Provided Token is not a Login With Amazon token

我可能需要在配置文件中设置web_identity_token_file=token-file.txt,但是从哪里获取与 Cognito 用户关联的令牌?

我想知道如何让 git-remote-codecommit 为 Cognito UserPool 用户工作,从而避免使用 STS 令牌带来的痛苦,只需正确配置配置文件?

更新:
汇报

在基于 AWS 的 POC 上花了几周时间后,我们决定在运行在 k8 中的轻量级且完全可控的服务上实施所有管道,例如 Gitea ????????

【问题讨论】:

    标签: git amazon-web-services jwt amazon-cognito gitea


    【解决方案1】:

    加上我的两分钱:我正面临着你的用例,但即使我可能已经取得了一些进展,我仍然无法使用 Cognito 用户克隆一个 repo。

    要获取token-file.txt,我使用以下命令:

        aws cognito-idp initiate-auth \
        --region eu-central-1 \
        --auth-flow USER_PASSWORD_AUTH \
        --client-id 1234abcd1234abcd1234abcd \
        --auth-parameters USERNAME=<username>,PASSWORD=<password> | \
        jq .AuthenticationResult.IdToken | \
        sed 's/"//g' > token-file.txt
    

    遵循this 答案中的建议。

    我的.aws/credentials 文件如下所示:

        role_arn=arn:aws:iam::1234567890123:role/Cognito_TESTAuth_Role
        web_identity_token_file=<path-to-token-file.txt>
    

    Cognito_TESTAuth_Role 是在我创建与 Cognito 用户池链接的身份池时由 AWS 添加的 IAM 角色。 我添加了 AWSCodeCommitPowerUser 策略和一个允许所有sts 对该角色执行操作的策略:

        {
            "Version": "2012-10-17",
            "Statement": [
                {
                   "Sid": "VisualEditor0",
                   "Effect": "Allow",
                   "Action": "sts:*",
                   "Resource": "*"
                }
           ]
        }
    

    但是当我尝试克隆 repo 时,我收到以下错误:

    An error occurred (AccessDenied) when calling the AssumeRoleWithWebIdentity operation: Not authorized to perform sts:AssumeRoleWithWebIdentity
    

    这与您的不同:虽然看起来我得到了一个有效的令牌(这令人鼓舞),但看起来我仍然缺少其他东西。

    我想知道您是否在此问题上取得了任何进展,以及如上所述获取令牌是否允许您访问 CodeCommit。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-28
      • 2020-03-19
      • 2016-02-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-03
      • 2020-07-03
      相关资源
      最近更新 更多