Failing to PassRole with iam:PassedToService for CodeBuild

泪湿孤枕 提交于 2021-02-07 09:31:36

问题


I'm trying to allow users to execute codebuild:StartBuild, while restricting iam:PassRole to pass the custom codebuild role only to the CodeBuild service.

The canned policies never restrict iam:PassRole, and even use "Resource":"*", effectively allowing passing of any role to any service. This strikes me as a bit sloppy, but maybe it's just me.

The policy below is an excerpt – codebuild:StartBuild, codebuild:List*, etc, are all allowed.

{   "Version": "2012-10-17",
    "Statement": [
        {   "Effect": "Allow",
            "Action": "iam:PassRole",
            "Resource": "arn:aws:iam::*:role/my-codebuild-role",
            "Condition": {
                "StringLike": {
                    "iam:PassedToService": "*"
                }
            }
        }
    ]
}

This policy makes codebuild:StartBuild return an error:

User: arn:aws:sts::123456789:assumed-role/MyDevRole/me@example.com
  is not authorized to perform: iam:PassRole on resource:
    arn:aws:iam::123456789:role/my-codebuild-role

Now, removing the Condition part of the policy makes codebuild:StartBuild succeed.

The CloudTrail logs state exactly the same, without providing any additional information, neither in that particular event, nor in events before or after it.

I have also tried variations of the Condition match, including: Specify codebuild.amazonaws.com as the service; specify codebuild.eu-west-1.amazonaws.com as the service; ditto using StringEquals; specifying a list of all AWS principals and using ForAnyValue:StringLike.

It doesn't make sense that a StringLike match on * fails, while removing the Condition altogether makes it work.

What am I doing wrong? What is AWS not telling me? Or, what is AWS doing wrong here?

来源:https://stackoverflow.com/questions/55335505/failing-to-passrole-with-iampassedtoservice-for-codebuild

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!