AWS Amazon EC2 Traffic Mirror Filter Rule

This page shows how to write Terraform and CloudFormation for Amazon EC2 Traffic Mirror Filter Rule and write them securely.

aws_ec2_traffic_mirror_filter_rule (Terraform)

The Traffic Mirror Filter Rule in Amazon EC2 can be configured in Terraform with the resource name aws_ec2_traffic_mirror_filter_rule. The following sections describe 3 examples of how to use the resource and its parameters.

Example Usage from GitHub

ise-trf-mir-zk.tf#L18
resource "aws_ec2_traffic_mirror_filter_rule" "zeek_outbound" {
  provider                 = aws.region-master
  description              = "Zeek Outbound Rule"
  traffic_mirror_filter_id = aws_ec2_traffic_mirror_filter.zeek_filter.id
  destination_cidr_block   = "0.0.0.0/0"
  source_cidr_block        = "0.0.0.0/0"
main.tf#L8
resource "aws_ec2_traffic_mirror_filter_rule" "module_outbound" {
  description              = "Capture all outbound"
  traffic_mirror_filter_id = aws_ec2_traffic_mirror_filter.module_filter.id
  destination_cidr_block   = "0.0.0.0/0"
  source_cidr_block        = "0.0.0.0/0"
  rule_number              = 1
main.tf#L8
resource "aws_ec2_traffic_mirror_filter_rule" "module_outbound" {
  description              = "Capture all outbound"
  traffic_mirror_filter_id = aws_ec2_traffic_mirror_filter.module_filter.id
  destination_cidr_block   = "0.0.0.0/0"
  source_cidr_block        = "0.0.0.0/0"
  rule_number              = 1

Review your Terraform file for AWS best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

Explanation in Terraform Registry

Provides an Traffic mirror filter rule.
Read limits and considerations for traffic mirroring

Tips: Best Practices for The Other AWS Amazon EC2 Resources

In addition to the aws_default_vpc, AWS Amazon EC2 has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.

risk-label

aws_default_vpc

Ensure to avoid using default VPC

It is better to define the own VPC and use it.

risk-label

aws_network_acl_rule

Ensure your network ACL rule blocks unwanted inbound traffic

It is better to block unwanted inbound traffic.

risk-label

aws_ebs_volume

Ensure to use a customer-managed key for EBS volume encryption

It is better to use a customer-managed key for EBS volume encryption. It can be gain more control over the encryption by using customer-managed keys (CMK).

risk-label

aws_instance

Ensure to avoid storing AWS access keys in user data

It is better to avoid storing AWS access keys in user data. `aws_iam_instance_profile` could be used instead.

risk-label

aws_security_group

Ensure your security group blocks unwanted inbound traffic

It is better to block unwanted inbound traffic.

Review your AWS Amazon EC2 settings

In addition to the above, there are other security points you should be aware of making sure that your .tf files are protected in Shisho Cloud.

AWS::EC2::TrafficMirrorFilterRule (CloudFormation)

The TrafficMirrorFilterRule in EC2 can be configured in CloudFormation with the resource name AWS::EC2::TrafficMirrorFilterRule. The following sections describe 10 examples of how to use the resource and its parameters.

Example Usage from GitHub

VPCMirrorCFT.yml#L28
    Type: "AWS::EC2::TrafficMirrorFilterRule"
    Properties:
      Description: "Accept RDP"
      TrafficMirrorFilterId: !Ref VPCTrafficMirrorFilter
      TrafficDirection: "ingress"
      RuleNumber: 10
vpc-mirroring.yaml#L63
    Type: AWS::EC2::TrafficMirrorFilterRule
    Properties:
      Description: Mirror all TCP ingress traffic.
      DestinationCidrBlock: 0.0.0.0/0
      DestinationPortRange:
        FromPort: 0
vpc-mirroring.yaml#L47
    Type: AWS::EC2::TrafficMirrorFilterRule
    Properties:
      Description: Mirror all TCP ingress traffic.
      DestinationCidrBlock: 0.0.0.0/0
      DestinationPortRange:
        FromPort: 0
Wireshark-Template.yaml#L199
    Type: AWS::EC2::TrafficMirrorFilterRule
    Properties:
      Description: !Sub "Created by ${AWS::StackName}"
      TrafficMirrorFilterId: !Ref TrafficMirrorFilter
      TrafficDirection: "ingress"
      RuleNumber: 11
nubeva-zeekclient.template.yaml#L124
    Type: "AWS::EC2::TrafficMirrorFilterRule"
    Properties:
      Description: "Filter for ALL ingress traffic"
      TrafficMirrorFilterId: !Ref ZeekTrafficMirrorFilter
      TrafficDirection: "ingress"
      RuleNumber: 10
trafficMirrorMonitor_CFTemplate.json#L458
            "Type": "AWS::EC2::TrafficMirrorFilterRule",
            "Properties": {
                "TrafficMirrorFilterId": { "Ref": "TrafficMirrorFilter1" },
                "TrafficDirection": "ingress",
                "RuleAction": "accept",
                "Protocol": 6,
EC2TrafficMirrorFilterRuleSpecification.json#L3
    "AWS::EC2::TrafficMirrorFilterRule.TrafficMirrorPortRange": {
      "Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-trafficmirrorfilterrule-trafficmirrorportrange.html",
      "Properties": {
        "FromPort": {
          "Required": true,
          "Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-trafficmirrorfilterrule-trafficmirrorportrange.html#cfn-ec2-trafficmirrorfilterrule-trafficmirrorportrange-fromport",
DDI.json#L267
            "Type" : "AWS::EC2::TrafficMirrorFilterRule",
            "Properties" : {
                  "Description" : "Ingress",
                  "DestinationCidrBlock" : "0.0.0.0/0",
                  "RuleAction" : "accept",
                  "RuleNumber" : "100",
awsResouceIconMatches.json#L250
        "resourceType": "AWS::EC2::TrafficMirrorFilterRule",
        "filePath": null
      },
      {
        "resourceType": "AWS::EC2::VPC",
        "filePath": "icons/aws/Service/Arch_Networking-Content/64/Arch_Amazon-Virtual-Private-Cloud_64@5x.png"
template.json#L2363
    "AWS::EC2::TrafficMirrorFilterRule": {
      "Type": "AWS::EC2::TrafficMirrorFilterRule",
      "Properties": {}
    },
    "AWS::ApiGateway::RestApi": {
      "Type": "AWS::ApiGateway::RestApi",

Parameters

Explanation in CloudFormation Registry

Creates a Traffic Mirror filter rule.

A Traffic Mirror rule defines the Traffic Mirror source traffic to mirror.

You need the Traffic Mirror filter ID when you create the rule.

Frequently asked questions

What is AWS Amazon EC2 Traffic Mirror Filter Rule?

AWS Amazon EC2 Traffic Mirror Filter Rule is a resource for Amazon EC2 of Amazon Web Service. Settings can be wrote in Terraform and CloudFormation.

Where can I find the example code for the AWS Amazon EC2 Traffic Mirror Filter Rule?

For Terraform, the jazhans/zeek_terransible_aws, jazhans/terraform_modules and jazhans/terraform_modules source code examples are useful. See the Terraform Example section for further details.

For CloudFormation, the awsvpc/pycompliance, seek-ret/installation and sjakthol/aws-vpc-traffic-mirroring source code examples are useful. See the CloudFormation Example section for further details.