cartography 0.107.0rc2__py3-none-any.whl → 0.108.0rc1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of cartography might be problematic. Click here for more details.

Files changed (40) hide show
  1. cartography/_version.py +2 -2
  2. cartography/cli.py +10 -0
  3. cartography/config.py +5 -0
  4. cartography/data/indexes.cypher +0 -8
  5. cartography/data/jobs/cleanup/github_repos_cleanup.json +2 -0
  6. cartography/intel/aws/__init__.py +1 -0
  7. cartography/intel/aws/cloudwatch.py +77 -0
  8. cartography/intel/aws/ec2/security_groups.py +140 -122
  9. cartography/intel/aws/ec2/snapshots.py +47 -84
  10. cartography/intel/aws/ec2/subnets.py +1 -1
  11. cartography/intel/aws/ecs.py +17 -0
  12. cartography/intel/aws/guardduty.py +275 -0
  13. cartography/intel/aws/resources.py +2 -0
  14. cartography/intel/github/repos.py +370 -28
  15. cartography/intel/sentinelone/__init__.py +8 -2
  16. cartography/intel/sentinelone/application.py +248 -0
  17. cartography/intel/sentinelone/utils.py +20 -1
  18. cartography/models/aws/cloudwatch/log_metric_filter.py +79 -0
  19. cartography/models/aws/ec2/networkinterfaces.py +2 -0
  20. cartography/models/aws/ec2/security_group_rules.py +109 -0
  21. cartography/models/aws/ec2/security_groups.py +90 -0
  22. cartography/models/aws/ec2/snapshots.py +58 -0
  23. cartography/models/aws/ec2/subnet_instance.py +2 -0
  24. cartography/models/aws/ec2/subnet_networkinterface.py +2 -0
  25. cartography/models/aws/ec2/volumes.py +20 -0
  26. cartography/models/aws/ecs/tasks.py +24 -1
  27. cartography/models/aws/guardduty/__init__.py +1 -0
  28. cartography/models/aws/guardduty/findings.py +102 -0
  29. cartography/models/github/dependencies.py +74 -0
  30. cartography/models/github/manifests.py +49 -0
  31. cartography/models/sentinelone/application.py +44 -0
  32. cartography/models/sentinelone/application_version.py +96 -0
  33. {cartography-0.107.0rc2.dist-info → cartography-0.108.0rc1.dist-info}/METADATA +3 -3
  34. {cartography-0.107.0rc2.dist-info → cartography-0.108.0rc1.dist-info}/RECORD +38 -28
  35. cartography/data/jobs/cleanup/aws_import_ec2_security_groupinfo_cleanup.json +0 -24
  36. cartography/data/jobs/cleanup/aws_import_snapshots_cleanup.json +0 -30
  37. {cartography-0.107.0rc2.dist-info → cartography-0.108.0rc1.dist-info}/WHEEL +0 -0
  38. {cartography-0.107.0rc2.dist-info → cartography-0.108.0rc1.dist-info}/entry_points.txt +0 -0
  39. {cartography-0.107.0rc2.dist-info → cartography-0.108.0rc1.dist-info}/licenses/LICENSE +0 -0
  40. {cartography-0.107.0rc2.dist-info → cartography-0.108.0rc1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,248 @@
1
+ import logging
2
+ from typing import Any
3
+
4
+ import neo4j
5
+
6
+ from cartography.client.core.tx import load
7
+ from cartography.graph.job import GraphJob
8
+ from cartography.intel.sentinelone.api import get_paginated_results
9
+ from cartography.intel.sentinelone.utils import get_application_id
10
+ from cartography.intel.sentinelone.utils import get_application_version_id
11
+ from cartography.models.sentinelone.application import S1ApplicationSchema
12
+ from cartography.models.sentinelone.application_version import (
13
+ S1ApplicationVersionSchema,
14
+ )
15
+ from cartography.util import timeit
16
+
17
+ logger = logging.getLogger(__name__)
18
+
19
+
20
+ @timeit
21
+ def get_application_data(
22
+ account_id: str, api_url: str, api_token: str
23
+ ) -> list[dict[str, Any]]:
24
+ """
25
+ Get application data from SentinelOne API
26
+ :param account_id: SentinelOne account ID
27
+ :param api_url: SentinelOne API URL
28
+ :param api_token: SentinelOne API token
29
+ :return: A list of application data dictionaries
30
+ """
31
+ logger.info(f"Retrieving SentinelOne application data for account {account_id}")
32
+ applications = get_paginated_results(
33
+ api_url=api_url,
34
+ endpoint="/web/api/v2.1/application-management/inventory",
35
+ api_token=api_token,
36
+ params={
37
+ "accountIds": account_id,
38
+ "limit": 1000,
39
+ },
40
+ )
41
+
42
+ logger.info(f"Retrieved {len(applications)} applications from SentinelOne")
43
+ return applications
44
+
45
+
46
+ @timeit
47
+ def get_application_installs(
48
+ app_inventory: list[dict[str, Any]], account_id: str, api_url: str, api_token: str
49
+ ) -> list[dict[str, Any]]:
50
+ """
51
+ Get application installs from SentinelOne API
52
+ :param app_inventory: List of applications to get installs for
53
+ :param account_id: SentinelOne account ID
54
+ :param api_url: SentinelOne API URL
55
+ :param api_token: SentinelOne API token
56
+ :return: A list of application installs data dictionaries
57
+ """
58
+ logger.info(
59
+ f"Retrieving SentinelOne application installs for "
60
+ f"{len(app_inventory)} applications in account "
61
+ f"{account_id}",
62
+ )
63
+
64
+ application_installs = []
65
+ for i, app in enumerate(app_inventory):
66
+ logger.info(
67
+ f"Retrieving SentinelOne installs for {app.get('applicationName')} "
68
+ f"{app.get('applicationVendor')} ({i + 1}/{len(app_inventory)})",
69
+ )
70
+ name = app["applicationName"]
71
+ vendor = app["applicationVendor"]
72
+ app_installs = get_paginated_results(
73
+ api_url=api_url,
74
+ endpoint="/web/api/v2.1/application-management/inventory/endpoints",
75
+ api_token=api_token,
76
+ params={
77
+ "accountIds": account_id,
78
+ "limit": 1000,
79
+ "applicationName": name,
80
+ "applicationVendor": vendor,
81
+ },
82
+ )
83
+
84
+ # Replace applicationVendor and applicationName with original values
85
+ # for consistency with the application data
86
+ for app_install in app_installs:
87
+ app_install["applicationVendor"] = vendor
88
+ app_install["applicationName"] = name
89
+ application_installs.extend(app_installs)
90
+
91
+ return application_installs
92
+
93
+
94
+ def transform_applications(
95
+ applications_list: list[dict[str, Any]],
96
+ ) -> list[dict[str, Any]]:
97
+ """
98
+ Transform SentinelOne application data for loading into Neo4j
99
+ :param applications_list: Raw application data from the API
100
+ :return: Transformed application data
101
+ """
102
+ transformed_data = []
103
+ for app in applications_list:
104
+ vendor = app["applicationVendor"].strip()
105
+ name = app["applicationName"].strip()
106
+ app_id = get_application_id(name, vendor)
107
+ transformed_app = {
108
+ "id": app_id,
109
+ "name": name,
110
+ "vendor": vendor,
111
+ }
112
+ transformed_data.append(transformed_app)
113
+
114
+ return transformed_data
115
+
116
+
117
+ def transform_application_versions(
118
+ application_installs_list: list[dict[str, Any]],
119
+ ) -> list[dict[str, Any]]:
120
+ """
121
+ Transform SentinelOne application installs for loading into Neo4j
122
+ :param application_installs_list: Raw application installs data from the API
123
+ :return: Transformed application installs data
124
+ """
125
+ transformed_data = []
126
+ for installed_version in application_installs_list:
127
+ app_name = installed_version["applicationName"]
128
+ app_vendor = installed_version["applicationVendor"]
129
+ version = installed_version["version"]
130
+
131
+ transformed_version = {
132
+ "id": get_application_version_id(
133
+ app_name,
134
+ app_vendor,
135
+ version,
136
+ ),
137
+ "application_id": get_application_id(
138
+ app_name,
139
+ app_vendor,
140
+ ),
141
+ "application_name": app_name,
142
+ "application_vendor": app_vendor,
143
+ "agent_uuid": installed_version.get("endpointUuid"),
144
+ "installation_path": installed_version.get("applicationInstallationPath"),
145
+ "installed_dt": installed_version.get("applicationInstallationDate"),
146
+ "version": version,
147
+ }
148
+ transformed_data.append(transformed_version)
149
+
150
+ return transformed_data
151
+
152
+
153
+ @timeit
154
+ def load_application_data(
155
+ neo4j_session: neo4j.Session,
156
+ data: list[dict[str, Any]],
157
+ account_id: str,
158
+ update_tag: int,
159
+ ) -> None:
160
+ """
161
+ Load SentinelOne application data into Neo4j
162
+ :param neo4j_session: Neo4j session
163
+ :param data: The transformed application data
164
+ :param account_id: The SentinelOne account ID
165
+ :param update_tag: Update tag to set on the nodes
166
+ :return: None
167
+ """
168
+ logger.info(f"Loading {len(data)} SentinelOne applications into Neo4j")
169
+ load(
170
+ neo4j_session,
171
+ S1ApplicationSchema(),
172
+ data,
173
+ lastupdated=update_tag,
174
+ S1_ACCOUNT_ID=account_id,
175
+ )
176
+
177
+
178
+ @timeit
179
+ def load_application_versions(
180
+ neo4j_session: neo4j.Session,
181
+ data: list[dict[str, Any]],
182
+ account_id: str,
183
+ update_tag: int,
184
+ ) -> None:
185
+ logger.info(f"Loading {len(data)} SentinelOne application versions into Neo4j")
186
+ load(
187
+ neo4j_session,
188
+ S1ApplicationVersionSchema(),
189
+ data,
190
+ lastupdated=update_tag,
191
+ S1_ACCOUNT_ID=account_id,
192
+ )
193
+
194
+
195
+ @timeit
196
+ def cleanup(
197
+ neo4j_session: neo4j.Session, common_job_parameters: dict[str, Any]
198
+ ) -> None:
199
+ logger.debug("Running SentinelOne S1Application cleanup")
200
+ GraphJob.from_node_schema(S1ApplicationSchema(), common_job_parameters).run(
201
+ neo4j_session
202
+ )
203
+ logger.debug("Running SentinelOne S1ApplicationVersion cleanup")
204
+ GraphJob.from_node_schema(S1ApplicationVersionSchema(), common_job_parameters).run(
205
+ neo4j_session
206
+ )
207
+
208
+
209
+ @timeit
210
+ def sync(
211
+ neo4j_session: neo4j.Session,
212
+ common_job_parameters: dict[str, Any],
213
+ ) -> None:
214
+ """
215
+ Sync SentinelOne applications
216
+ :param neo4j_session: Neo4j session
217
+ :param common_job_parameters: Common job parameters containing API_URL, API_TOKEN, etc.
218
+ :return: None
219
+ """
220
+ logger.info("Syncing SentinelOne application data")
221
+ account_id = str(common_job_parameters["S1_ACCOUNT_ID"])
222
+ api_url = str(common_job_parameters["API_URL"])
223
+ api_token = str(common_job_parameters["API_TOKEN"])
224
+
225
+ applications = get_application_data(account_id, api_url, api_token)
226
+ application_versions = get_application_installs(
227
+ applications, account_id, api_url, api_token
228
+ )
229
+ transformed_applications = transform_applications(applications)
230
+ transformed_application_versions = transform_application_versions(
231
+ application_versions
232
+ )
233
+
234
+ load_application_data(
235
+ neo4j_session,
236
+ transformed_applications,
237
+ account_id,
238
+ common_job_parameters["UPDATE_TAG"],
239
+ )
240
+
241
+ load_application_versions(
242
+ neo4j_session,
243
+ transformed_application_versions,
244
+ account_id,
245
+ common_job_parameters["UPDATE_TAG"],
246
+ )
247
+
248
+ cleanup(neo4j_session, common_job_parameters)
@@ -2,8 +2,27 @@ import re
2
2
 
3
3
 
4
4
  def get_application_id(name: str, vendor: str) -> str:
5
+ """
6
+ Generate a normalized unique identifier for an application.
7
+ :param name: Application name
8
+ :param vendor: Application vendor/publisher
9
+ :return: Normalized unique identifier in format 'vendor:name'
10
+ """
5
11
  name_normalized = name.strip().lower().replace(" ", "_")
6
12
  vendor_normalized = vendor.strip().lower().replace(" ", "_")
7
13
  name_normalized = re.sub(r"[^\w]", "", name_normalized)
8
- vendor_normalized = re.sub(r"[^\w\s]", "", vendor_normalized)
14
+ vendor_normalized = re.sub(r"[^\w]", "", vendor_normalized)
9
15
  return f"{vendor_normalized}:{name_normalized}"
16
+
17
+
18
+ def get_application_version_id(name: str, vendor: str, version: str) -> str:
19
+ """
20
+ Generate a unique identifier for an application version
21
+ :param name: Application name
22
+ :param vendor: Application vendor
23
+ :param version: Application version
24
+ :return: Unique identifier for the application version in format 'vendor:name:version'
25
+ """
26
+ app_id = get_application_id(name, vendor)
27
+ version_normalized = version.strip().lower().replace(" ", "_")
28
+ return f"{app_id}:{version_normalized}"
@@ -0,0 +1,79 @@
1
+ from dataclasses import dataclass
2
+
3
+ from cartography.models.core.common import PropertyRef
4
+ from cartography.models.core.nodes import CartographyNodeProperties
5
+ from cartography.models.core.nodes import CartographyNodeSchema
6
+ from cartography.models.core.relationships import CartographyRelProperties
7
+ from cartography.models.core.relationships import CartographyRelSchema
8
+ from cartography.models.core.relationships import LinkDirection
9
+ from cartography.models.core.relationships import make_target_node_matcher
10
+ from cartography.models.core.relationships import OtherRelationships
11
+ from cartography.models.core.relationships import TargetNodeMatcher
12
+
13
+
14
+ @dataclass(frozen=True)
15
+ class CloudWatchLogMetricFilterNodeProperties(CartographyNodeProperties):
16
+ id: PropertyRef = PropertyRef("id")
17
+ arn: PropertyRef = PropertyRef("filterName", extra_index=True)
18
+ region: PropertyRef = PropertyRef("Region", set_in_kwargs=True)
19
+ filter_name: PropertyRef = PropertyRef("filterName")
20
+ filter_pattern: PropertyRef = PropertyRef("filterPattern")
21
+ log_group_name: PropertyRef = PropertyRef("logGroupName")
22
+ metric_name: PropertyRef = PropertyRef("metricName")
23
+ metric_namespace: PropertyRef = PropertyRef("metricNamespace")
24
+ metric_value: PropertyRef = PropertyRef("metricValue")
25
+ lastupdated: PropertyRef = PropertyRef("lastupdated", set_in_kwargs=True)
26
+
27
+
28
+ @dataclass(frozen=True)
29
+ class CloudWatchLogMetricFilterToAwsAccountRelProperties(CartographyRelProperties):
30
+ lastupdated: PropertyRef = PropertyRef("lastupdated", set_in_kwargs=True)
31
+
32
+
33
+ @dataclass(frozen=True)
34
+ class CloudWatchLogMetricFilterToAWSAccountRel(CartographyRelSchema):
35
+ target_node_label: str = "AWSAccount"
36
+ target_node_matcher: TargetNodeMatcher = make_target_node_matcher(
37
+ {"id": PropertyRef("AWS_ID", set_in_kwargs=True)},
38
+ )
39
+ direction: LinkDirection = LinkDirection.INWARD
40
+ rel_label: str = "RESOURCE"
41
+ properties: CloudWatchLogMetricFilterToAwsAccountRelProperties = (
42
+ CloudWatchLogMetricFilterToAwsAccountRelProperties()
43
+ )
44
+
45
+
46
+ @dataclass(frozen=True)
47
+ class CloudWatchLogMetricFilterToCloudWatchLogGroupRelProperties(
48
+ CartographyRelProperties
49
+ ):
50
+ lastupdated: PropertyRef = PropertyRef("lastupdated", set_in_kwargs=True)
51
+
52
+
53
+ @dataclass(frozen=True)
54
+ class CloudWatchLogMetricFilterToCloudWatchLogGroupRel(CartographyRelSchema):
55
+ target_node_label: str = "CloudWatchLogGroup"
56
+ target_node_matcher: TargetNodeMatcher = make_target_node_matcher(
57
+ {"log_group_name": PropertyRef("logGroupName")},
58
+ )
59
+ direction: LinkDirection = LinkDirection.OUTWARD
60
+ rel_label: str = "METRIC_FILTER_OF"
61
+ properties: CloudWatchLogMetricFilterToCloudWatchLogGroupRelProperties = (
62
+ CloudWatchLogMetricFilterToCloudWatchLogGroupRelProperties()
63
+ )
64
+
65
+
66
+ @dataclass(frozen=True)
67
+ class CloudWatchLogMetricFilterSchema(CartographyNodeSchema):
68
+ label: str = "CloudWatchLogMetricFilter"
69
+ properties: CloudWatchLogMetricFilterNodeProperties = (
70
+ CloudWatchLogMetricFilterNodeProperties()
71
+ )
72
+ sub_resource_relationship: CloudWatchLogMetricFilterToAWSAccountRel = (
73
+ CloudWatchLogMetricFilterToAWSAccountRel()
74
+ )
75
+ other_relationships: OtherRelationships = OtherRelationships(
76
+ [
77
+ CloudWatchLogMetricFilterToCloudWatchLogGroupRel(),
78
+ ]
79
+ )
@@ -44,7 +44,9 @@ class EC2NetworkInterfaceNodeProperties(CartographyNodeProperties):
44
44
  requester_id: PropertyRef = PropertyRef("RequesterId", extra_index=True)
45
45
  requester_managed: PropertyRef = PropertyRef("RequesterManaged")
46
46
  source_dest_check: PropertyRef = PropertyRef("SourceDestCheck")
47
+ # TODO: remove subnetid once we have migrated to subnet_id
47
48
  subnetid: PropertyRef = PropertyRef("SubnetId", extra_index=True)
49
+ subnet_id: PropertyRef = PropertyRef("SubnetId", extra_index=True)
48
50
 
49
51
 
50
52
  @dataclass(frozen=True)
@@ -0,0 +1,109 @@
1
+ from dataclasses import dataclass
2
+
3
+ from cartography.models.core.common import PropertyRef
4
+ from cartography.models.core.nodes import CartographyNodeProperties
5
+ from cartography.models.core.nodes import CartographyNodeSchema
6
+ from cartography.models.core.nodes import ExtraNodeLabels
7
+ from cartography.models.core.relationships import CartographyRelProperties
8
+ from cartography.models.core.relationships import CartographyRelSchema
9
+ from cartography.models.core.relationships import LinkDirection
10
+ from cartography.models.core.relationships import make_target_node_matcher
11
+ from cartography.models.core.relationships import OtherRelationships
12
+ from cartography.models.core.relationships import TargetNodeMatcher
13
+
14
+
15
+ @dataclass(frozen=True)
16
+ class IpRuleNodeProperties(CartographyNodeProperties):
17
+ id: PropertyRef = PropertyRef("RuleId")
18
+ ruleid: PropertyRef = PropertyRef("RuleId", extra_index=True)
19
+ groupid: PropertyRef = PropertyRef("GroupId", extra_index=True)
20
+ protocol: PropertyRef = PropertyRef("Protocol")
21
+ fromport: PropertyRef = PropertyRef("FromPort")
22
+ toport: PropertyRef = PropertyRef("ToPort")
23
+ lastupdated: PropertyRef = PropertyRef("lastupdated", set_in_kwargs=True)
24
+
25
+
26
+ @dataclass(frozen=True)
27
+ class IpRuleToAWSAccountRelProperties(CartographyRelProperties):
28
+ lastupdated: PropertyRef = PropertyRef("lastupdated", set_in_kwargs=True)
29
+
30
+
31
+ @dataclass(frozen=True)
32
+ class IpRuleToAWSAccountRel(CartographyRelSchema):
33
+ target_node_label: str = "AWSAccount"
34
+ target_node_matcher: TargetNodeMatcher = make_target_node_matcher(
35
+ {"id": PropertyRef("AWS_ID", set_in_kwargs=True)}
36
+ )
37
+ direction: LinkDirection = LinkDirection.INWARD
38
+ rel_label: str = "RESOURCE"
39
+ properties: IpRuleToAWSAccountRelProperties = IpRuleToAWSAccountRelProperties()
40
+
41
+
42
+ @dataclass(frozen=True)
43
+ class IpRuleToSecurityGroupRelProperties(CartographyRelProperties):
44
+ lastupdated: PropertyRef = PropertyRef("lastupdated", set_in_kwargs=True)
45
+
46
+
47
+ @dataclass(frozen=True)
48
+ class IpRuleToSecurityGroupRel(CartographyRelSchema):
49
+ target_node_label: str = "EC2SecurityGroup"
50
+ target_node_matcher: TargetNodeMatcher = make_target_node_matcher(
51
+ {"groupid": PropertyRef("GroupId")}
52
+ )
53
+ direction: LinkDirection = LinkDirection.OUTWARD
54
+ rel_label: str = "MEMBER_OF_EC2_SECURITY_GROUP"
55
+ properties: IpRuleToSecurityGroupRelProperties = (
56
+ IpRuleToSecurityGroupRelProperties()
57
+ )
58
+
59
+
60
+ @dataclass(frozen=True)
61
+ class IpRangeNodeProperties(CartographyNodeProperties):
62
+ id: PropertyRef = PropertyRef("RangeId")
63
+ range: PropertyRef = PropertyRef("RangeId")
64
+ lastupdated: PropertyRef = PropertyRef("lastupdated", set_in_kwargs=True)
65
+
66
+
67
+ @dataclass(frozen=True)
68
+ class IpRangeToIpRuleRelProperties(CartographyRelProperties):
69
+ lastupdated: PropertyRef = PropertyRef("lastupdated", set_in_kwargs=True)
70
+
71
+
72
+ @dataclass(frozen=True)
73
+ class IpRangeToIpRuleRel(CartographyRelSchema):
74
+ target_node_label: str = "IpRule"
75
+ target_node_matcher: TargetNodeMatcher = make_target_node_matcher(
76
+ {"ruleid": PropertyRef("RuleId")}
77
+ )
78
+ direction: LinkDirection = LinkDirection.OUTWARD
79
+ rel_label: str = "MEMBER_OF_IP_RULE"
80
+ properties: IpRangeToIpRuleRelProperties = IpRangeToIpRuleRelProperties()
81
+
82
+
83
+ @dataclass(frozen=True)
84
+ class IpRuleSchema(CartographyNodeSchema):
85
+ label: str = "IpRule"
86
+ properties: IpRuleNodeProperties = IpRuleNodeProperties()
87
+ sub_resource_relationship: IpRuleToAWSAccountRel = IpRuleToAWSAccountRel()
88
+ other_relationships: OtherRelationships = OtherRelationships(
89
+ [IpRuleToSecurityGroupRel()]
90
+ )
91
+
92
+
93
+ @dataclass(frozen=True)
94
+ class IpPermissionInboundSchema(CartographyNodeSchema):
95
+ label: str = "IpRule"
96
+ extra_node_labels: ExtraNodeLabels = ExtraNodeLabels(["IpPermissionInbound"])
97
+ properties: IpRuleNodeProperties = IpRuleNodeProperties()
98
+ sub_resource_relationship: IpRuleToAWSAccountRel = IpRuleToAWSAccountRel()
99
+ other_relationships: OtherRelationships = OtherRelationships(
100
+ [IpRuleToSecurityGroupRel()]
101
+ )
102
+
103
+
104
+ @dataclass(frozen=True)
105
+ class IpRangeSchema(CartographyNodeSchema):
106
+ label: str = "IpRange"
107
+ properties: IpRangeNodeProperties = IpRangeNodeProperties()
108
+ sub_resource_relationship: IpRuleToAWSAccountRel = IpRuleToAWSAccountRel()
109
+ other_relationships: OtherRelationships = OtherRelationships([IpRangeToIpRuleRel()])
@@ -0,0 +1,90 @@
1
+ from dataclasses import dataclass
2
+
3
+ from cartography.models.core.common import PropertyRef
4
+ from cartography.models.core.nodes import CartographyNodeProperties
5
+ from cartography.models.core.nodes import CartographyNodeSchema
6
+ from cartography.models.core.relationships import CartographyRelProperties
7
+ from cartography.models.core.relationships import CartographyRelSchema
8
+ from cartography.models.core.relationships import LinkDirection
9
+ from cartography.models.core.relationships import make_target_node_matcher
10
+ from cartography.models.core.relationships import OtherRelationships
11
+ from cartography.models.core.relationships import TargetNodeMatcher
12
+
13
+
14
+ @dataclass(frozen=True)
15
+ class EC2SecurityGroupNodeProperties(CartographyNodeProperties):
16
+ id: PropertyRef = PropertyRef("GroupId")
17
+ groupid: PropertyRef = PropertyRef("GroupId", extra_index=True)
18
+ name: PropertyRef = PropertyRef("GroupName")
19
+ description: PropertyRef = PropertyRef("Description")
20
+ region: PropertyRef = PropertyRef("Region", set_in_kwargs=True)
21
+ lastupdated: PropertyRef = PropertyRef("lastupdated", set_in_kwargs=True)
22
+
23
+
24
+ @dataclass(frozen=True)
25
+ class EC2SecurityGroupToAWSAccountRelProperties(CartographyRelProperties):
26
+ lastupdated: PropertyRef = PropertyRef("lastupdated", set_in_kwargs=True)
27
+
28
+
29
+ @dataclass(frozen=True)
30
+ class EC2SecurityGroupToAWSAccountRel(CartographyRelSchema):
31
+ target_node_label: str = "AWSAccount"
32
+ target_node_matcher: TargetNodeMatcher = make_target_node_matcher(
33
+ {"id": PropertyRef("AWS_ID", set_in_kwargs=True)}
34
+ )
35
+ direction: LinkDirection = LinkDirection.INWARD
36
+ rel_label: str = "RESOURCE"
37
+ properties: EC2SecurityGroupToAWSAccountRelProperties = (
38
+ EC2SecurityGroupToAWSAccountRelProperties()
39
+ )
40
+
41
+
42
+ @dataclass(frozen=True)
43
+ class EC2SecurityGroupToVpcRelProperties(CartographyRelProperties):
44
+ lastupdated: PropertyRef = PropertyRef("lastupdated", set_in_kwargs=True)
45
+
46
+
47
+ @dataclass(frozen=True)
48
+ class EC2SecurityGroupToVpcRel(CartographyRelSchema):
49
+ target_node_label: str = "AWSVpc"
50
+ target_node_matcher: TargetNodeMatcher = make_target_node_matcher(
51
+ {"vpcid": PropertyRef("VpcId")}
52
+ )
53
+ direction: LinkDirection = LinkDirection.OUTWARD
54
+ rel_label: str = "MEMBER_OF_EC2_SECURITY_GROUP"
55
+ properties: EC2SecurityGroupToVpcRelProperties = (
56
+ EC2SecurityGroupToVpcRelProperties()
57
+ )
58
+
59
+
60
+ @dataclass(frozen=True)
61
+ class EC2SecurityGroupToSourceGroupRelProperties(CartographyRelProperties):
62
+ lastupdated: PropertyRef = PropertyRef("lastupdated", set_in_kwargs=True)
63
+
64
+
65
+ @dataclass(frozen=True)
66
+ class EC2SecurityGroupToSourceGroupRel(CartographyRelSchema):
67
+ target_node_label: str = "EC2SecurityGroup"
68
+ target_node_matcher: TargetNodeMatcher = make_target_node_matcher(
69
+ {"groupid": PropertyRef("SOURCE_GROUP_IDS", one_to_many=True)}
70
+ )
71
+ direction: LinkDirection = LinkDirection.OUTWARD
72
+ rel_label: str = "ALLOWS_TRAFFIC_FROM"
73
+ properties: EC2SecurityGroupToSourceGroupRelProperties = (
74
+ EC2SecurityGroupToSourceGroupRelProperties()
75
+ )
76
+
77
+
78
+ @dataclass(frozen=True)
79
+ class EC2SecurityGroupSchema(CartographyNodeSchema):
80
+ label: str = "EC2SecurityGroup"
81
+ properties: EC2SecurityGroupNodeProperties = EC2SecurityGroupNodeProperties()
82
+ sub_resource_relationship: EC2SecurityGroupToAWSAccountRel = (
83
+ EC2SecurityGroupToAWSAccountRel()
84
+ )
85
+ other_relationships: OtherRelationships = OtherRelationships(
86
+ [
87
+ EC2SecurityGroupToVpcRel(),
88
+ EC2SecurityGroupToSourceGroupRel(),
89
+ ]
90
+ )
@@ -0,0 +1,58 @@
1
+ from dataclasses import dataclass
2
+
3
+ from cartography.models.core.common import PropertyRef
4
+ from cartography.models.core.nodes import CartographyNodeProperties
5
+ from cartography.models.core.nodes import CartographyNodeSchema
6
+ from cartography.models.core.relationships import CartographyRelProperties
7
+ from cartography.models.core.relationships import CartographyRelSchema
8
+ from cartography.models.core.relationships import LinkDirection
9
+ from cartography.models.core.relationships import make_target_node_matcher
10
+ from cartography.models.core.relationships import OtherRelationships
11
+ from cartography.models.core.relationships import TargetNodeMatcher
12
+
13
+
14
+ @dataclass(frozen=True)
15
+ class EBSSnapshotNodeProperties(CartographyNodeProperties):
16
+ id: PropertyRef = PropertyRef("SnapshotId")
17
+ snapshotid: PropertyRef = PropertyRef("SnapshotId", extra_index=True)
18
+ description: PropertyRef = PropertyRef("Description")
19
+ encrypted: PropertyRef = PropertyRef("Encrypted")
20
+ progress: PropertyRef = PropertyRef("Progress")
21
+ starttime: PropertyRef = PropertyRef("StartTime")
22
+ state: PropertyRef = PropertyRef("State")
23
+ statemessage: PropertyRef = PropertyRef("StateMessage")
24
+ volumeid: PropertyRef = PropertyRef("VolumeId")
25
+ volumesize: PropertyRef = PropertyRef("VolumeSize")
26
+ outpostarn: PropertyRef = PropertyRef("OutpostArn")
27
+ dataencryptionkeyid: PropertyRef = PropertyRef("DataEncryptionKeyId")
28
+ kmskeyid: PropertyRef = PropertyRef("KmsKeyId")
29
+ region: PropertyRef = PropertyRef("Region", set_in_kwargs=True)
30
+ lastupdated: PropertyRef = PropertyRef("lastupdated", set_in_kwargs=True)
31
+
32
+
33
+ @dataclass(frozen=True)
34
+ class EBSSnapshotToAWSAccountRelProperties(CartographyRelProperties):
35
+ lastupdated: PropertyRef = PropertyRef("lastupdated", set_in_kwargs=True)
36
+
37
+
38
+ @dataclass(frozen=True)
39
+ class EBSSnapshotToAWSAccountRel(CartographyRelSchema):
40
+ target_node_label: str = "AWSAccount"
41
+ target_node_matcher: TargetNodeMatcher = make_target_node_matcher(
42
+ {
43
+ "id": PropertyRef("AWS_ID", set_in_kwargs=True),
44
+ }
45
+ )
46
+ direction: LinkDirection = LinkDirection.INWARD
47
+ rel_label: str = "RESOURCE"
48
+ properties: EBSSnapshotToAWSAccountRelProperties = (
49
+ EBSSnapshotToAWSAccountRelProperties()
50
+ )
51
+
52
+
53
+ @dataclass(frozen=True)
54
+ class EBSSnapshotSchema(CartographyNodeSchema):
55
+ label: str = "EBSSnapshot"
56
+ properties: EBSSnapshotNodeProperties = EBSSnapshotNodeProperties()
57
+ sub_resource_relationship: EBSSnapshotToAWSAccountRel = EBSSnapshotToAWSAccountRel()
58
+ other_relationships: OtherRelationships = OtherRelationships([])
@@ -15,7 +15,9 @@ from cartography.models.core.relationships import TargetNodeMatcher
15
15
  class EC2SubnetInstanceNodeProperties(CartographyNodeProperties):
16
16
  # arn: PropertyRef = PropertyRef('Arn', extra_index=True) TODO use arn; issue #1024
17
17
  id: PropertyRef = PropertyRef("SubnetId")
18
+ # TODO: remove subnetid once we have migrated to subnet_id
18
19
  subnetid: PropertyRef = PropertyRef("SubnetId", extra_index=True)
20
+ subnet_id: PropertyRef = PropertyRef("SubnetId", extra_index=True)
19
21
  region: PropertyRef = PropertyRef("Region", set_in_kwargs=True)
20
22
  lastupdated: PropertyRef = PropertyRef("lastupdated", set_in_kwargs=True)
21
23
 
@@ -16,6 +16,8 @@ from cartography.models.core.relationships import TargetNodeMatcher
16
16
  @dataclass(frozen=True)
17
17
  class EC2SubnetNetworkInterfaceNodeProperties(CartographyNodeProperties):
18
18
  id: PropertyRef = PropertyRef("SubnetId")
19
+ # TODO: remove subnetid once we have migrated to subnet_id
20
+ subnetid: PropertyRef = PropertyRef("SubnetId", extra_index=True)
19
21
  subnet_id: PropertyRef = PropertyRef("SubnetId", extra_index=True)
20
22
  region: PropertyRef = PropertyRef("Region", set_in_kwargs=True)
21
23
  lastupdated: PropertyRef = PropertyRef("lastupdated", set_in_kwargs=True)
@@ -68,6 +68,24 @@ class EBSVolumeToEC2InstanceRel(CartographyRelSchema):
68
68
  )
69
69
 
70
70
 
71
+ @dataclass(frozen=True)
72
+ class EBSVolumeToEBSSnapshotRelProperties(CartographyRelProperties):
73
+ lastupdated: PropertyRef = PropertyRef("lastupdated", set_in_kwargs=True)
74
+
75
+
76
+ @dataclass(frozen=True)
77
+ class EBSVolumeToEBSSnapshotRel(CartographyRelSchema):
78
+ target_node_label: str = "EBSSnapshot"
79
+ target_node_matcher: TargetNodeMatcher = make_target_node_matcher(
80
+ {"id": PropertyRef("SnapshotId")},
81
+ )
82
+ direction: LinkDirection = LinkDirection.INWARD
83
+ rel_label: str = "CREATED_FROM"
84
+ properties: EBSVolumeToEBSSnapshotRelProperties = (
85
+ EBSVolumeToEBSSnapshotRelProperties()
86
+ )
87
+
88
+
71
89
  @dataclass(frozen=True)
72
90
  class EBSVolumeSchema(CartographyNodeSchema):
73
91
  """
@@ -80,6 +98,7 @@ class EBSVolumeSchema(CartographyNodeSchema):
80
98
  other_relationships: OtherRelationships = OtherRelationships(
81
99
  [
82
100
  EBSVolumeToEC2InstanceRel(),
101
+ EBSVolumeToEBSSnapshotRel(),
83
102
  ],
84
103
  )
85
104
 
@@ -110,5 +129,6 @@ class EBSVolumeInstanceSchema(CartographyNodeSchema):
110
129
  other_relationships: OtherRelationships = OtherRelationships(
111
130
  [
112
131
  EBSVolumeToEC2InstanceRel(),
132
+ EBSVolumeToEBSSnapshotRel(),
113
133
  ],
114
134
  )