Scp Tag enforcement is not working on Ec2.

0

I have created an SCP to deny ec2 resource creation if there is no tag. The instance is only get created if it has an environment tag key mentioned in it.

Here is my policy :

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "Scp1",
      "Effect": "Deny",
      "Action": [
        "ec2:CreateTags",
        "ec2:RunInstances"
      ],
      "Resource": [
        "arn:aws:ec2:*:*:instance/*",
        "arn:aws:ec2:*:*:volume/*"
      ],
      "Condition": {
        "ForAllValues:StringEquals": {
          "aws:RequestTag/environment": "true"
        }
      }
    }
  ]
}
Shubham
질문됨 2년 전1021회 조회
2개 답변
0

Yes I am trying to achieve this thing but I want to achieve this by using AWS SCP. All post which I have seen they all have same json file as mine. But while implementation it is not working.

Shubham
답변함 2년 전
  • So what condition type you are using?

    ForAllValues:StringEquals? Or StringNotLike?

  • I have used Both but no luck.

  • Can you also post the policy you use with StringNotLike to see if there is any other issue?

  • {
      "Version": "2012-10-17",
      "Statement": [
        {
          "Sid": "Scp1",
          "Effect": "Deny",
          "Action": [
            "ec2:RunInstances"
          ],
          "Resource": [
            "arn:aws:ec2:*:*:instance/*",
            "arn:aws:ec2:*:*:volume/*"
          ],
          "Condition": {
            "ForAllValues:StringEquals": {
              "aws:RequestTag/environment": "true"
            }
          }
        }
      ]
    }
    
    {
      "Version": "2012-10-17",
      "Statement": [
        {
          "Sid": "Scp1",
          "Effect": "Deny",
          "Action": [
            "ec2:RunInstances"
          ],
          "Resource": [
            "arn:aws:ec2:*:*:instance/*",
            "arn:aws:ec2:*:*:volume/*"
          ],
          "Condition": {
            "ForAllValues:StringNotLike": {
              "aws:RequestTag/environment": "true"
            }
          }
        }
      ]
    }
    
  • Your policy with

    "ForAllValues:StringNotLike": {
              "aws:RequestTag/environment": "true"
            }
    

    means all your new EC2 instances need to have a tag environment and the tag value must be exactly true

    Is this what you expect and what you get?

0

I guess you are trying to achieve something like this: https://aws.amazon.com/premiumsupport/knowledge-center/iam-policy-tags-deny/ (Sid: AllowRunInstancesWithRestrictions1)

Your policy can be modified as follow:

{
    "Effect": "Deny",
    "Action": [
        "ec2: CreateTags",
        "ec2: RunInstances"
    ],
    "Resource": [
        "arn:aws:ec2:*:*:instance/*",
        "arn:aws:ec2:*:*:volume/*"
    ],
    "Condition": {
        "StringNotLike": {
            "aws:RequestTag/cost_center": "?*"
        }
    }
}
답변함 2년 전

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

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

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

관련 콘텐츠