<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>pevans.dev</title><description>Notes on learning cloud security on AWS, posted as they are written.</description><link>https://pevans.dev/</link><language>en</language><item><title>Security groups have no deny rule</title><link>https://pevans.dev/blog/security-groups-have-no-deny-rule/</link><guid isPermaLink="true">https://pevans.dev/blog/security-groups-have-no-deny-rule/</guid><description>Coming from firewalls, I went looking for the deny rule. Security groups don&apos;t have one.</description><content:encoded>&lt;p&gt;On every firewall I&apos;ve run, a rule ends in permit or deny. So when I built my first security group in the lab, I looked for the action field so I could block one address. There isn&apos;t one.&lt;/p&gt;
&lt;h2 id=&quot;what-a-security-group-can-do&quot;&gt;What a security group can do&lt;/h2&gt;
&lt;p&gt;A security group is a list of things you allow. Anything you haven&apos;t allowed is dropped. You can&apos;t write a rule that says deny, so you can&apos;t carve an exception out of a wider allow.&lt;/p&gt;
&lt;p&gt;It is also stateful. If you allow a request in, the reply goes back out without a rule of its own.&lt;/p&gt;
&lt;h2 id=&quot;the-rule-in-terraform&quot;&gt;The rule, in Terraform&lt;/h2&gt;
&lt;p&gt;Here is the ingress rule from the lab. There is no argument for an action, because allow is the only option. The closest thing to a deny is leaving the rule out.&lt;/p&gt;
&lt;figure class=&quot;code&quot;&gt;&lt;figcaption class=&quot;code-caption&quot;&gt;&lt;span&gt;security-group.tf&lt;/span&gt;&lt;span&gt;Terraform&lt;/span&gt;&lt;/figcaption&gt;&lt;pre class=&quot;code-pre&quot; tabindex=&quot;0&quot; data-language=&quot;hcl&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;resource &lt;/span&gt;&lt;span class=&quot;tok-str&quot;&gt;&quot;aws_security_group&quot;&lt;/span&gt;&lt;span class=&quot;tok-str&quot;&gt; &quot;web&quot;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;  name   = &lt;/span&gt;&lt;span class=&quot;tok-str&quot;&gt;&quot;web&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;  vpc_id = aws_vpc.lab.id&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;resource &lt;/span&gt;&lt;span class=&quot;tok-str&quot;&gt;&quot;aws_vpc_security_group_ingress_rule&quot;&lt;/span&gt;&lt;span class=&quot;tok-str&quot;&gt; &quot;https&quot;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;  security_group_id = aws_security_group.web.id&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;  cidr_ipv4         = &lt;/span&gt;&lt;span class=&quot;tok-str&quot;&gt;&quot;0.0.0.0/0&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;  from_port         = 443&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;  to_port           = 443&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;  ip_protocol       = &lt;/span&gt;&lt;span class=&quot;tok-str&quot;&gt;&quot;tcp&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;h2 id=&quot;where-the-deny-lives&quot;&gt;Where the deny lives&lt;/h2&gt;
&lt;p&gt;To block a specific address you go up a level, to the network ACL on the subnet. A NACL has both allow and deny, and it reads the way an access list does: numbered rules, lowest first, first match wins. In Terraform that is &lt;code&gt;aws_network_acl_rule&lt;/code&gt;, and it does have a &lt;code&gt;rule_action&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&quot;table-wrap&quot;&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;th scope=&quot;col&quot;&gt;Security group&lt;/th&gt;
&lt;th scope=&quot;col&quot;&gt;Network ACL&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;th scope=&quot;row&quot;&gt;Applies to&lt;/th&gt;
&lt;td&gt;A network interface&lt;/td&gt;
&lt;td&gt;A subnet&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th scope=&quot;row&quot;&gt;Rules&lt;/th&gt;
&lt;td&gt;Allow only&lt;/td&gt;
&lt;td&gt;Allow and deny&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th scope=&quot;row&quot;&gt;State&lt;/th&gt;
&lt;td&gt;Stateful&lt;/td&gt;
&lt;td&gt;Stateless&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th scope=&quot;row&quot;&gt;Evaluation&lt;/th&gt;
&lt;td&gt;All rules together&lt;/td&gt;
&lt;td&gt;Number order, first match&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;
&lt;aside class=&quot;correction&quot; aria-label=&quot;What I got wrong&quot;&gt;&lt;span class=&quot;correction__label&quot;&gt;&lt;span class=&quot;correction__dot&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;What I got wrong&lt;/span&gt;&lt;p&gt;I first assumed rule order mattered inside a security group, the way it does on an ACL. It doesn&apos;t. All the rules are checked together, and if any one of them allows the traffic, it gets through.&lt;/p&gt;&lt;/aside&gt;
&lt;h2 id=&quot;what-i-do-now&quot;&gt;What I do now&lt;/h2&gt;
&lt;p&gt;In the lab, security groups say who may reach each resource, and each subnet has one NACL for the rare address I need to block. Before I call a security group done, I check three things:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Each rule names a source, a port and a protocol.&lt;/li&gt;
&lt;li&gt;No rule is wider than the thing it protects needs.&lt;/li&gt;
&lt;li&gt;The description says why the rule exists.&lt;/li&gt;
&lt;/ul&gt;</content:encoded><category>VPC</category><category>IaC</category></item></channel></rss>