Use Network Firewall to capture the DNS domain names from the Server Name Indication (SNI) for outbound traffic
Created by Kirankumar Chandrashekar (AWS)
Environment: PoC or pilot | Technologies: Security, identity, compliance; Networking; Web & mobile apps | Workload: All other workloads |
AWS services: AWS Lambda; AWS Network Firewall; Amazon VPC; Amazon CloudWatch Logs |
Summary
This pattern shows you how to use Amazon Web Services (AWS) Network Firewall to collect the DNS domain names that are provided by the Server Name Indication (SNI) in the HTTPS header of your outbound network traffic. Network Firewall is a managed service that makes it easy to deploy critical network protections for Amazon Virtual Private Cloud (Amazon VPC), including the ability to secure outbound traffic with a firewall that blocks packets that fail to meet certain security requirements. Securing outbound traffic to specific DNS domain names is called egress filtering, which is the practice of monitoring and potentially restricting the flow of outbound information from one network to another.
After you capture the SNI data that passes through Network Firewall, you can use Amazon CloudWatch Logs and AWS Lambda to publish the data to an Amazon Simple Notification Service (Amazon SNS) topic that generates email notifications. The email notifications include the server name and other relevant SNI information. Additionally, you can use the output of this pattern to allow or restrict outbound traffic by domain name in the SNI by using firewall rules. For more information, see Working with stateful rule groups in AWS Network Firewall in the Network Firewall documentation.
Prerequisites and limitations
Prerequisites
An active AWS account
AWS Command Line Interface (AWS CLI) version 2, installed and configured on Linux, macOS, or Windows
Network Firewall, set up and configured in Amazon VPC and in use for inspecting outbound traffic
Note: Network Firewall can use any of the following VPC configurations:
Architecture
The following diagram shows how to use Network Firewall to collect SNI data from outbound network traffic, and then publish that data to an SNS topic by using CloudWatch Logs and Lambda.
The diagram shows the following workflow:
Network Firewall collects domain names from the SNI data in the HTTPS header of your outbound network traffic.
CloudWatch Logs monitors the SNI data and invokes a Lambda function whenever the outbound network traffic passes through Network Firewall.
The Lambda function reads the SNI data captured by CloudWatch Logs and then publishes that data to an SNS topic.
The SNS topic sends you an email notification that includes the SNI data.
Automation and scale
You can use AWS CloudFormation to create this pattern by using infrastructure as code.
Technology stack
Amazon CloudWatch Logs
Amazon SNS
Amazon VPC
AWS Lambda
AWS Network Firewall
Tools
AWS services
Amazon CloudWatch Logs – You can use Amazon CloudWatch Logs to monitor, store, and access your log files from Amazon Elastic Compute Cloud (Amazon EC2) instances, AWS CloudTrail, Amazon Route 53, and other sources.
Amazon SNS – Amazon Simple Notification Service (Amazon SNS) is a managed service that provides message delivery from publishers to subscribers (also known as producers and consumers).
Amazon VPC – Amazon Virtual Private Cloud (Amazon VPC) provisions a logically isolated section of the AWS Cloud where you can launch AWS resources in a virtual network that you've defined. This virtual network closely resembles a traditional network that you'd operate in your own data center, with the benefits of using the scalable infrastructure of AWS.
AWS Lambda – AWS Lambda is a compute service that lets you run code without provisioning or managing servers.
AWS Network Firewall – AWS Network Firewall is a managed service that makes it easy to deploy essential network protections for all of your Amazon VPCs.
Epics
Task | Description | Skills required |
---|---|---|
Create a CloudWatch log group. |
For more information, see Working with log groups and log streams in the CloudWatch documentation. | Cloud administrator |
Task | Description | Skills required |
---|---|---|
Create an SNS topic. | To create an SNS topic, follow the instructions in the Amazon SNS documentation. | Cloud administrator |
Subscribe an endpoint to the SNS topic. | To subscribe an email address as an endpoint to the SNS topic that you created, follow the instructions in the Amazon SNS documentation. For Protocol, choose Email/Email-JSON. Note: You can also choose a different endpoint based on your requirements. | Cloud administrator |
Task | Description | Skills required |
---|---|---|
Enable firewall logging. |
For more information about using CloudWatch Logs as a log destination for Network Firewall, see Amazon CloudWatch Logs in the Network Firewall documentation. | Cloud administrator |
Task | Description | Skills required |
---|---|---|
Create a stateful rule. |
| Cloud administrator |
Associate the stateful rule to Network Firewall. |
| Cloud administrator |
Task | Description | Skills required |
---|---|---|
Create the code for the Lambda function. | In an integrated development environment (IDE) that can read the CloudWatch Logs event from Network Firewall for outbound traffic, paste in the following Python 3 code and replace
This code sample parses the CloudWatch Logs content and captures the server name provided by the SNI in the HTTPS header. | App developer |
Create the Lambda function. | To create the Lambda function, follow the instructions in the Lambda documentation and choose Python 3.9 for Runtime. | Cloud administrator |
Add the code to the Lambda function. | To add your Python code to the Lambda function that you created earlier, follow the instructions in the Lambda documentation. | Cloud administrator |
Add CloudWatch Logs as a trigger to the Lambda function. |
For more information, see Using Lambda with CloudWatch Logs in the Lambda documentation. | Cloud administrator |
Add SNS publish permissions. | Add the sns:Publish permission to the Lambda execution role, so that Lambda can make API calls to publish messages to SNS.
| Cloud administrator |
Task | Description | Skills required |
---|---|---|
Send traffic through Network Firewall. |
Then, check the Network Firewall alert log in Amazon CloudWatch by following the instructions in the Amazon CloudWatch documentation. The alert log shows the following output:
| Test engineer |