cloudformation-coverage-roadmap icon indicating copy to clipboard operation
cloudformation-coverage-roadmap copied to clipboard

AWS::EC2::SecurityGroup - Tagging-OnCreate

Open mderoquefeuil opened this issue 5 years ago • 6 comments

Scope of request

AWS::EC2::SecurityGroup - when I have an IAM deny statement to create a security group without a specifig tag (aws:RequestTags), I can create resource via API, but not via CloudFormation.

Expected behavior

When I create a security group with an IAM policy to enforce tagging, I should be able to create the resource through API or CloudFormation the same way. So far :

  • Creating through API/GUI works
  • Creating through CloudFormation does not work

Suggest specific test cases

Prerequisites

IAM deny policy should be as follow :

- Effect: "Deny"
  Action: 
    - "ec2:CreateSecurityGroup"
  Resource: 
    - "arn:aws:ec2:*:*:security-group/*"
  Condition: 
    "StringNotLike":
  	"aws:RequestTag/project":
  	  - "?*"

User should use the Administrator Policy.

Test case success

CFN Template should be just creating a SG with the tag "project" set to any value with 1 or more character. When running, the template should be successful.

Test case failure

CFN Template should be just creating a SG with no tag "project" set. When running, the template should be failing because of a lack of rights.

Category

Networking & Content : Security Group

mderoquefeuil avatar Dec 09 '20 15:12 mderoquefeuil

I looked at Cloudtrail and, at least in my case, CloudFormation is creating the resource and then tagging it in a separate operation. It's messing up my whole template because DependsOn doesn't wait for the tags to be created.

Cushdrive avatar Jun 20 '21 20:06 Cushdrive

Is there any update on this?

MrSakhs avatar Dec 07 '21 12:12 MrSakhs

Any update? I'm having the same problema here, but using CDK.

diogomelodantas avatar Feb 11 '22 18:02 diogomelodantas

Same here, do not deploy tag at creation is really painfull when play with iam tag restriction

BDeus avatar Oct 12 '22 10:10 BDeus

Hey everyone! Apologies for the delayed response, but we recently updated AWS::EC2::SecurityGroup to use tag-on-create. That should let you use the same IAM policies to enforce tagging on security groups for both CloudFormation and other EC2 API calls.

I'm going to resolve this issue, but please either reopen it or create a new issue if you need anything else.

davidataws avatar May 14 '25 19:05 davidataws

Closing this out based on @davidataws 's comment above. Please let us know if the issue resurfaces or if you have questions.

shantgup avatar May 14 '25 19:05 shantgup