简体   繁体   English

允许用户通过 SSO 登录承担 IAM 角色

[英]Allow user to assume an IAM role with SSO login

I am trying to allow a user to assume a role on AWS.我试图让用户在 AWS 上担任角色。 I attached an assume role policy to a group where the IAM user belongs so that they can assume a particular role.我将代入角色策略附加到 IAM 用户所属的组,以便他们可以代入特定角色。 The problem is that the user now uses SSO to login and and is no longer allowed to login into through console with the IAM user credentials, therefore the user is unable to assume the role.问题是用户现在使用 SSO 登录,并且不再允许使用 IAM 用户凭据通过控制台登录,因此用户无法承担该角色。 How can I configure a user with SSO login to assume an existing IAM role?如何配置具有 SSO 登录名的用户以承担现有的 IAM 角色? When i created the Assume role policy I chose both AssumeRole and AssumeRoleWithSaml.当我创建 Assume 角色策略时,我选择了 AssumeRole 和 AssumeRoleWithSaml。 But it's still not working.但它仍然无法正常工作。

This is what the AssumeRole policy looks like这就是 AssumeRole 政策的样子

"Version": "2012-10-17",
"Statement": [
    {
        "Sid": "VisualEditor0",
        "Effect": "Allow",
        "Action": [
            "sts:AssumeRole",
            "sts:AssumeRoleWithSAML"
        ],
        "Resource": "arn:aws:iam::xxxxxxxxxxxx:role/service-role/KinesisFirehoseServiceRole--us-east-1-xxxxxxxxxxxxx"
    }
]

The Trust relationship for the role looks like this该角色的信任关系如下所示

"Version": "2012-10-17",
"Statement": [
    {
        "Effect": "Allow",
        "Principal": {
            "Service": "firehose.amazonaws.com"
        },
        "Action": "sts:AssumeRole"
    }
]

You need to specifically allow that user / role to be able to assume that role.您需要特别允许该用户/角色能够担任该角色。 Right now, the Principal is set to only allow the "firehose service" to assume that role.现在,Principal 设置为仅允许“firehose 服务”承担该角色。

The 2nd problem is that you need to specifically allow a SSO account to be able to access it.第二个问题是您需要特别允许 SSO 帐户才能访问它。 You'll need to get the ARN of your current SSO user session. To get this you should run aws sts get-caller-identity您需要获取当前 SSO 用户 session 的 ARN。为此,您应该运行aws sts get-caller-identity

You should get something like this你应该得到这样的东西

{
    "UserId": "BROA5DAM2TACHAA38V9J1:daryl.teo@appetiser.com.au",
    "Account": "1234567890",
    "Arn": "arn:aws:sts::1234567890:assumed-role/AWSReservedSSO_AWSAdministratorAccess_abe68abec87ew/something.username"
}

Or a 1 liner aws sts get-caller-identity --output text --query Arn或者 1 aws sts get-caller-identity --output text --query Arn

Then take that value and add it to your policy as an additional policy statement.然后采用该值并将其作为附加政策声明添加到您的政策中。

{
    "Version": "2012-10-17",
    "Statement":
    [
        {
            "Effect": "Allow",
            "Principal":
            {
                "Service": "firehose.amazonaws.com"
            },
            "Action": "sts:AssumeRole"
        },
        {
            "Effect": "Allow",
            "Principal":
            {
                "AWS": "arn:aws:sts::1234567890:assumed-role/AWSReservedSSO_AWSAdministratorAccess_abe68abec87ew/something.username"
            },
            "Action": "sts:AssumeRole"
        },
    ]
}

And now you can use:现在您可以使用:

aws sts assume-role --role-arn=arn:aws:iam::123456823432:role/NameOfYourRole --role-session-name=role-session-name

I managed to enable SSO users to assume a role in the account they were authenticated to by using the following.我设法使 SSO 用户能够使用以下内容在他们经过身份验证的帐户中担任角色。 Note that you'll need to replace ${ACCOUNT_ID} , ${SSO_ROLE_NAME} , and ${ASSUMABLE_ROLE_NAME} .请注意,您需要替换${ACCOUNT_ID}${SSO_ROLE_NAME}${ASSUMABLE_ROLE_NAME} You may, of course, need to repackage the bits.当然,您可能需要重新打包这些位。

aws iam create-role --role-name ${ASSUMABLE_ROLE_NAME} --assume-role-policy-document file://policy.json --profile $PROFILE

policy.json:政策.json:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::${ACCOUNT_ID}:root"
      },
      "Action": "sts:AssumeRole",
      "Condition": {
        "ArnLike": {
            "aws:PrincipalArn": [
                "arn:aws:iam::${ACCOUNT_ID}:role/aws-reserved/sso.amazonaws.com/*/AWSReservedSSO_${SSO_ROLE_NAME}_*",
                "arn:aws:iam::${ACCOUNT_ID}:role/aws-reserved/sso.amazonaws.com/AWSReservedSSO_${SSO_ROLE_NAME}_*"
            ]
        }
      }
    }
  ]
}

Thanks to everyone that responded.感谢所有回应的人。 I was able to complete the task using this instructions.我能够使用此说明完成任务。 google saml sso with AWS 谷歌 saml sso 与 AWS

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM