liveBook · Manning

Firewall rule

As explained in Amazon Web Services in Action, Third Edition: An in-depth guide to AWS

A firewall rule is a configuration statement that allows or blocks network traffic according to specified criteria.

A firewall rule is a configuration statement that allows or denies network traffic according to its direction, protocol, port, and source or destination. Before traffic enters or leaves an EC2 instance, AWS inspects it against rules managed through security groups. section 5.4 section 5.4.1

Apply firewall rules narrowly to reduce exposure:

  • Open only required ports: a public web server commonly needs inbound TCP ports 80 and 443, while unnecessary ports should remain closed. section 5.4
  • Define traffic by direction, IP protocol, port, and IP address, IP range, or—within AWS—a source or destination security group. section 5.4.1
  • Remember the defaults: security groups deny inbound traffic unless rules allow it, but allow all outbound traffic unless that rule is replaced. section 5.4
  • Troubleshoot unexpected results with VPC Reachability Analyzer for simulated paths or VPC Flow Logs for aggregated rejected-connection messages. section 5.4

Allow HTTP to a web server

A CloudFormation security group rule permits inbound TCP traffic from 0.0.0.0/0 to port 80. The associated instance installs and starts Apache, allowing a browser to reach a basic test page. section 5.4.3

Listing 10.6 CloudFormation template extract: Firewall rules for an RDS database
DatabaseSecurityGroup:                                      #1
  Type: 'AWS::EC2::SecurityGroup'
  Properties:
    GroupDescription: 'awsinaction-db-sg'
    VpcId: !Ref VPC
    SecurityGroupIngress:
    - IpProtocol: tcp
      FromPort: 3306                                        #2
      ToPort: 3306
      SourceSecurityGroupId: !Ref WebServerSecurityGroup    #3

Inspect a CloudFormation extract that restricts MySQL traffic on port 3306 to instances attached to WebServerSecurityGroup. section 10.4.2

How Amazon Web Services in Action, Third Edition: An in-depth guide to AWS covers it

How deep it goes
Defines matching criteria, security-group defaults, least-privilege guidance, and troubleshooting, then contrasts stateful security groups with prioritized NACL rules.
Examples
Uses HTTP access to EC2, MySQL access from web servers to RDS, and proxy-subnet traffic governed by NACL entries.
What you can do after
Apply it via AWS security groups and CloudFormation to expose required services while restricting unnecessary network paths.
How it connects
Connects security groups with EC2, RDS, VPC, IAM least privilege, network access control lists, VPC Reachability Analyzer, and VPC Flow Logs.

Also explained in

Compare how 2 books explain firewall rule →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Amazon Web Services in Action, Third Edition: An in-depth guide to AWS. The section links point to the parts of the book it draws on.