|
7 | 7 | from functools import reduce
|
8 | 8 | from ipaddress import ip_address, ip_network
|
9 | 9 | from typing import Any, List, Optional, Sequence, Union
|
| 10 | +from panther_config import config |
10 | 11 |
|
11 | 12 | # # # # # # # # # # # # # #
|
12 | 13 | # Exceptions #
|
@@ -35,47 +36,36 @@ def in_pci_scope_tags(resource):
|
35 | 36 | return resource["Tags"].get(CDE_TAG_KEY) == CDE_TAG_VALUE
|
36 | 37 |
|
37 | 38 |
|
| 39 | +PCI_NETWORKS = config.PCI_NETWORKS |
38 | 40 | # Expects a string in cidr notation (e.g. '10.0.0.0/24') indicating the ip range being checked
|
39 | 41 | # Returns True if any ip in the range is marked as in scope
|
40 |
| -PCI_NETWORKS = [ |
41 |
| - ip_network("10.0.0.0/24"), |
42 |
| -] |
43 |
| - |
44 |
| - |
45 | 42 | def is_pci_scope_cidr(ip_range):
|
46 | 43 | return any(ip_network(ip_range).overlaps(pci_network) for pci_network in PCI_NETWORKS)
|
47 | 44 |
|
48 | 45 |
|
| 46 | +DMZ_NETWORKS = config.DMZ_NETWORKS |
49 | 47 | # Expects a string in cidr notation (e.g. '10.0.0.0/24') indicating the ip range being checked
|
50 | 48 | # Returns True if any ip in the range is marked as DMZ space.
|
51 |
| -DMZ_NETWORKS = [ |
52 |
| - ip_network("10.1.0.0/24"), |
53 |
| - ip_network("100.1.0.0/24"), |
54 |
| -] |
55 |
| - |
56 |
| - |
57 | 49 | def is_dmz_cidr(ip_range):
|
58 | 50 | """This function determines whether a given IP range is within the defined DMZ IP range."""
|
59 | 51 | return any(ip_network(ip_range).overlaps(dmz_network) for dmz_network in DMZ_NETWORKS)
|
60 | 52 |
|
61 | 53 |
|
62 |
| -DMZ_TAG_KEY = "environment" |
63 |
| -DMZ_TAG_VALUE = "dmz" |
64 |
| - |
65 |
| - |
66 | 54 | # Defaults to False to assume something is not a DMZ if it is not tagged
|
67 |
| -def is_dmz_tags(resource): |
| 55 | +def is_dmz_tags(resource, dmz_tags): |
68 | 56 | """This function determines whether a given resource is tagged as existing in a DMZ."""
|
69 | 57 | if resource["Tags"] is None:
|
70 | 58 | return False
|
71 |
| - return resource["Tags"].get(DMZ_TAG_KEY) == DMZ_TAG_VALUE |
| 59 | + for key, value in dmz_tags: |
| 60 | + if resource["Tags"].get(key) == value: |
| 61 | + return True |
| 62 | + return False |
72 | 63 |
|
73 | 64 |
|
74 | 65 | # Function variables here so that implementation details of these functions can be changed without
|
75 | 66 | # having to rename the function in all locations its used, or having an outdated name on the actual
|
76 | 67 | # function being used, etc.
|
77 | 68 | IN_PCI_SCOPE = in_pci_scope_tags
|
78 |
| -IS_DMZ = is_dmz_tags |
79 | 69 |
|
80 | 70 | # # # # # # # # # # # # # #
|
81 | 71 | # GSuite Helpers #
|
|
0 commit comments