Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Support for adding Metadata to deal with 3rd party tools #8336

Closed
2 tasks
Zirkonium88 opened this issue Jun 3, 2020 · 2 comments
Closed
2 tasks

Add Support for adding Metadata to deal with 3rd party tools #8336

Zirkonium88 opened this issue Jun 3, 2020 · 2 comments
Labels
feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged.

Comments

@Zirkonium88
Copy link

Zirkonium88 commented Jun 3, 2020

Hi ,thanks for your greate effort on CDK development!

Please add the posssibillty to add custom meta data to Cloudformation templates via the CDK.

Use Case

I would like to use cfn_nag. This is security scanning CLI tool for Cloudformation templates. Not all rules apply to my organization. You can add metadata to Cloudformation which disables unnecessary rules of cfn_snag.

Proposed Solution

This snippet

PublicAlbSecurityGroup:
  Properties:
    GroupDescription: 'Security group for a public Application Load Balancer'
    VpcId:
      Ref: vpc
  Type: AWS::EC2::SecurityGroup
PublicAlbSecurityGroupHttpIngress:
  Properties:
    CidrIp: 0.0.0.0/0
    FromPort: 80
    GroupId:
      Ref: PublicAlbSecurityGroup
    IpProtocol: tcp
    ToPort: 80
  Type: AWS::EC2::SecurityGroupIngress

shall be adapted to this

PublicAlbSecurityGroup:
  Properties:
    GroupDescription: 'Security group for a public Application Load Balancer'
    VpcId:
      Ref: vpc
  Type: AWS::EC2::SecurityGroup
  Metadata:
    cfn_nag:
      rules_to_suppress:
        - id: W9
          reason: "This is a public facing ELB and ingress from the internet should be permitted."
        - id: W2
          reason: "This is a public facing ELB and ingress from the internet should be permitted."
PublicAlbSecurityGroupHttpIngress:
  Properties:
    CidrIp: 0.0.0.0/0
    FromPort: 80
    GroupId:
      Ref: PublicAlbSecurityGroup
    IpProtocol: tcp
    ToPort: 80
  Type: AWS::EC2::SecurityGroupIngress

My idea

alb_sg.node.add_metadata(
{
   "cfn_nag": {
      "rules_to_suppress": [
         {
            "id": "W9",
            "reason": "This is a public facing ELB and ingress from the internet should be permitted."
         },
         {
            "id": "W2",
            "reason": "This is a public facing ELB and ingress from the internet should be permitted."
         }
      ]
   }
}
)

Other

Related #6379

  • 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change

This is a 🚀 Feature Request

@Zirkonium88 Zirkonium88 added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Jun 3, 2020
@Zirkonium88
Copy link
Author

I just found this part of the documentation:

# Get the AWS CloudFormation resource
cfn_bucket = bucket.node.default_child

# Change its properties
cfn_bucket.analytics_configuration = [
    {
        "id": "Config",
        # ...
    }
]

This not very straight forward, but it works. It would be nice to extend the documentation witth hints for metadata and cfn-init. This way would also close this issue #777

@longtv2222
Copy link
Contributor

longtv2222 commented Jan 2, 2024

Commenting on this issue since this is the first result on Google.

According to the documentation, to add metadata, we do:

// Get the CloudFormation resource
const cfnBucket = bucket.node.defaultChild as s3.CfnBucket;

// add metadata
cfnBucket.cfnOptions.metadata = {
  MetadataKey: 'MetadataValue'
};

But the above removes all other metadata values (notably aws:cdk:path). If we want to preserve other metadata values, it's better to do:

cfnBucket.addMetadata('MetadataKey', 'MetadataValue');

I've submitted documentation feedback for https://docs.aws.amazon.com/cdk/v2/guide/cfn_layer.html#cfn_layer_resource

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

No branches or pull requests

2 participants