Adding a condition to an IAM Permission causes ec2:CreateImage to not be authorized

0

So I have a SSO Role, and I added ec2:CreateImage to the permission set attached to it, and resource is "*". It works fine. As soon as I add a condition like "StringEquals", with the condition being a tag, i.e. aws:ResourceTag/Example, it will not work. It does not have some explicit deny etc. The tag value is correct. I've tried different key,values to rule out spelling errors or some silly mistake.

I have tested this in two different environments and I trouble shooted using the Policy Builder (So no syntax issues). I have double checked by deleting the permission (and seeing it blocked), adding the bare permission without conditions (it passes), and then adding a condition (it then fails).

I dont see anything in the documentation or dependencies that would cause this to fail. Any reason?

  • For clarity, can you post an excerpt of the policy json that you are trying to troubleshoot?

1개 답변
1

Reading your question, it sounds like you are trying to specify Resource:* when using the ConditionKey aws:ResourceTag/${TagKey}. For the action ec2:CreateImage, you must also specify which Resource type when using this ConditionKey. In this case, the Resource type is instance as the other supported Resource type image does not support this ConditionKey.

https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonec2.html#amazonec2-policy-keys

If the column includes a resource type, then you can specify an ARN of that type in a statement with that action. Required resources are indicated in the table with an asterisk (*). If you specify a resource-level permission ARN in a statement using this action, then it must be of this type. Some actions support multiple resource types. If the resource type is optional (not indicated as required), then you can choose to use one but not the other.

For example, to match tags on all ec2 instances in an account with ID 111111111111, we must specify "Resource": "arn:aws:ec2:*: 111111111111:instance/*"

    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": "ec2:CreateImage",
            "Resource": "arn:aws:ec2:*:111111111111:instance/*",
            "Condition": {
                "StringEquals": {
                    "aws:ResourceTag/TAG_KEY": "TAG_VALUE"
                }
            }
        }
    ]
}```
profile pictureAWS
simon
답변함 일 년 전
  • Hi Simon,

    I tried that and used the following policy with an example account #, unfortunately it did not work. Is there any possibility that SSO may be conflicting with this? Or that there are dependent permissions? I couldn't see anything amiss in the docs

            {
                "Sid": "CreateImageCustom",
                "Effect": "Allow",
                "Action": "ec2:CreateImage",
                "Resource": "arn:aws:ec2:*:111111111111:instance/*",
                "Condition": {
                    "StringEquals": {
                        "aws:ResourceTag/Example": "ExampleValue"
                    }
                }
            }
    

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠