As part of securing applications in the cloud, it’s important to set the proper network rules, for maximum security and to minimize collateral damage.
Here’s a quote from the official HIPAA requirement for Transmission Security.
A covered entity must implement technical security measures that guard against unauthorized access to e-PHI that is being transmitted over an electronic network.
For those of you who are not familiar with HIPAA, it’s a very strict regulation that requires protecting medical records and other personal health information (PHI).
Most startup companies that develop a product for the medical-healthcare sector, aspire to become HIPAA compliant.
Here’s the question you need to ask yourself when it comes to Transmission Security
What security measures are currently used to protect e-PHI during transmission? HIPAA - Security Rule - Technical Safeguards
I’d have to write a book to cover all the network security layers, so let’s get a quick glance at the most common network security layers in AWS.
In this blog post, I’ll focus on the Virtual Firewall layer. In AWS, the implementation of a Virtual Firewall is done with AWS Security Groups.
Security groups are stateful, the official docs, describe it as follows:
If you send a request from your instance, the response traffic for that request is allowed to flow in regardless of inbound security group rules. Responses to allowed inbound traffic are allowed to flow out, regardless of outbound rules.
By default, a security group is created without any inbound rules. That means it doesn’t accept traffic from any device that attempts to initiate a connection.
The default outbound rule is 0.0.0.0/0
which allows devices to initiate connections to anywhere. Once a connection is initiated, the security group rule is ignored.
So what is stateless? We’ll cover that in the Blocking Specific IPs section.
Let’s say you want to SSH from your local machine to an EC2 instance, that has a public IP address.
To achieve that, you’ll add an inbound security rule that allows SSH
connections from My IP
(your IP). And then, you’ll SSH to the EC2 and it’ll work as expected.
Here comes the tricky part; What would happen if, during your SSH session, someone removes your inbound security group rule? Nothing. As mentioned earlier, security group rules apply to new connections only, since your SSH session is active, you can still continue with your work. If by any chance, you get disconnected for even a split second, the new security group rules will take place and you’ll get disconnected.
This is very confusing; One might want to deny traffic from a known set of IP addresses. It is common to think that Security Groups can be used to block traffic explicitly, though it is impossible.
Security Groups are designed to Allow access from/to sources, and implicitly block unknown sources. When you add a security group rule, you don’t have an option to set its type (Allow/Deny), it is Allowed by design.
To address the need for explicitly blocking specific sources, you can use AWS Network Access Lists (NACLs), which are stateless, and as part of setting a Network Access Rule, you’ll have the option to set its type (Allow/Deny). It’s important to mention that NACLs operate at the Subnet level, while Security Groups operate at the VPC level.
Reminding you that NACLs are stateless, which means you’ll need to create a rule for both inbound and outbound for any source/target device. Unlike Security Groups, if you haven’t explicitly allowed a connection both inbound/outbound, it is denied by default. The default NACLs rules, for both inbound and outbound, are All traffic, from/to: 0.0.0.0/0
.
NOTE: I rarely use NACLs, unless there’s a specific need to block a set of IP addresses at the subnet’s level, which in my experience, is quite rare and should be used with cautious.
One might think “but hey, I want to allow access to https://myapp.com/admin/dashboard
from my IP only, how can I do that? Since HTTP requests are handled at the application layer, you can use the AWS Web Application Firewall.
URI Path
whitelisted
.Here’s the pseudo-code of the set of rules that should be created
if AND(
URI-Path == https://myapp.com/admin/dashboard,
SourceIP != Whitelisted-IPs
)
then Block
URI-Path
, and allowing traffic only from a specific set of IP addresses (whitelisted).When I first started my journey with AWS, Security Groups were one of the first components that I encountered. I also didn’t have any background with networks, so stateless and stateful didn’t mean anything to me. Once I broke it down and found out which service should be used for each purpose, it was all clear.