Skip to content

Commit b8f37bd

Browse files
committed
DMZ Tagging: Support multiple tags, move to panther_config
1 parent 2f53632 commit b8f37bd

4 files changed

+31
-9
lines changed

global_helpers/panther_base_helpers.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -59,23 +59,21 @@ def is_dmz_cidr(ip_range):
5959
return any(ip_network(ip_range).overlaps(dmz_network) for dmz_network in DMZ_NETWORKS)
6060

6161

62-
DMZ_TAG_KEY = "environment"
63-
DMZ_TAG_VALUE = "dmz"
64-
65-
6662
# Defaults to False to assume something is not a DMZ if it is not tagged
67-
def is_dmz_tags(resource):
63+
def is_dmz_tags(resource, dmz_tags):
6864
"""This function determines whether a given resource is tagged as existing in a DMZ."""
6965
if resource["Tags"] is None:
7066
return False
71-
return resource["Tags"].get(DMZ_TAG_KEY) == DMZ_TAG_VALUE
67+
for key, value in dmz_tags:
68+
if resource["Tags"].get(key) == value:
69+
return True
70+
return False
7271

7372

7473
# Function variables here so that implementation details of these functions can be changed without
7574
# having to rename the function in all locations its used, or having an outdated name on the actual
7675
# function being used, etc.
7776
IN_PCI_SCOPE = in_pci_scope_tags
78-
IS_DMZ = is_dmz_tags
7977

8078
# # # # # # # # # # # # # #
8179
# GSuite Helpers #

global_helpers/panther_config_defaults.py

+7
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,10 @@
1313
MS_EXCHANGE_ALLOWED_FORWARDING_DESTINATION_DOMAINS = ORGANIZATION_DOMAINS
1414
MS_EXCHANGE_ALLOWED_FORWARDING_DESTINATION_EMAILS = ["postmaster@" + ORGANIZATION_DOMAINS[0]]
1515
TELEPORT_ORGANIZATION_DOMAINS = ORGANIZATION_DOMAINS
16+
17+
# Key/value pairs of tags used to denote resources that are intentionally exposed
18+
DMZ_TAGS = set(
19+
[
20+
("environment", "dmz"),
21+
]
22+
)

policies/aws_vpc_policies/aws_only_dmz_security_groups_publicly_accessible.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
import json
12
from ipaddress import ip_network
3+
from unittest.mock import MagicMock
24

3-
from panther_base_helpers import IS_DMZ
5+
from panther_base_helpers import is_dmz_tags
6+
from panther_config import config
7+
8+
DMZ_TAGS = config.DMZ_TAGS
49

510

611
def policy(resource):
@@ -9,7 +14,10 @@ def policy(resource):
914
return True
1015

1116
# DMZ security groups can have inbound permissions from the internet
12-
if IS_DMZ(resource):
17+
global DMZ_TAGS # pylint: disable=global-statement
18+
if isinstance(DMZ_TAGS, MagicMock):
19+
DMZ_TAGS = {tuple(kv) for kv in json.loads(DMZ_TAGS())}
20+
if is_dmz_tags(resource, DMZ_TAGS):
1321
return True
1422

1523
for permission in resource["IpPermissions"]:

policies/aws_vpc_policies/aws_only_dmz_security_groups_publicly_accessible.yml

+9
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ Tests:
2525
-
2626
Name: DMZ Security Group Does Allows Public Access
2727
ExpectedResult: true
28+
Mocks:
29+
- objectName: DMZ_TAGS
30+
returnValue: '[["environment", "dmz"]]'
2831
Resource:
2932
{
3033
"Description": "example VPC security group",
@@ -88,6 +91,9 @@ Tests:
8891
-
8992
Name: Non DMZ Security Group Allows Public Access
9093
ExpectedResult: false
94+
Mocks:
95+
- objectName: DMZ_TAGS
96+
returnValue: '[["environment", "dmz"]]'
9197
Resource:
9298
{
9399
"Description": "example VPC security group",
@@ -151,6 +157,9 @@ Tests:
151157
-
152158
Name: Non DMZ Security Group Does Not Allow Public Access
153159
ExpectedResult: true
160+
Mocks:
161+
- objectName: DMZ_TAGS
162+
returnValue: '[["environment", "dmz"]]'
154163
Resource:
155164
{
156165
"Description": "example VPC security group",

0 commit comments

Comments
 (0)