---
title: "Tomek Habiger (@thabiger) | Hashnode"
description: "Tomek Habiger (@thabiger) writes on Hashnode. Read their latest articles and follow their work."
url: "https://hashnode.com/@thabiger"
---

@thabiger

# Tomek Habiger

@thabiger · Joined February 2024

## Comments

[The main principle of a security group is that the most permissive rule wins. A port is a concept specific to TCP and UDP protocols that operate at the transport layer (Layer 4). If you allow any IP protocol (-1) in your rule, you're essentially saying, 'I don't care about the protocol; just work at the IP network layer (Layer 3).' Such a rule not only disregards ports but also overrides any other protocol-oriented rules you have specified in your set (as it operates at a lower layer). If used consciously, there is nothing wrong with this so far. So let's check if the AWS tooling lets you do anything risky with that setting: UI doesn't even allow you to provide ports in such conditions(protocol set to -1), Terraform won't let you do this as well; with such a code: resource "aws\_security\_group" "example" { name = "MySecurityGroup" description = "My security group" vpc\_id = "\*" ingress { from\_port = 666 to\_port = 666 protocol = "-1" cidr\_blocks = \["0.0.0.0/0"\] } } it throws an error: updating Security Group (\*) ingress rules: updating rules: from\_port (666) and to\_port (666) must both be 0 to use the 'ALL' "-1" protocol! only the CLI allows that, but it must be admitted that in its output, it tells you exactly what it has done: aws ec2 authorize-security-group-ingress \\ --group-id $security\_group\_id \\ --protocol -1 \\ --port 666 \\ --cidr 0.0.0.0/0 { "Return": true, "SecurityGroupRules": \[ { "SecurityGroupRuleId": "", "GroupId": "", "GroupOwnerId": "\*", "IsEgress": false, "IpProtocol": "-1", "FromPort": -1, "ToPort": -1, "CidrIpv4": "0.0.0.0/0" } \] } Consent on one matter: awareness! :)](https://hashnode.com/posts/aws-security-groups-are-tricky/659401cb71deca9b06d6128d/comment/65d0803ad51c276bbe61d2b8)

Comment · Article · Feb 17, 2024 · [AWS Security Groups are tricky!](https://hashnode.com/posts/aws-security-groups-are-tricky/659401cb71deca9b06d6128d)
