cartography 0.107.0rc2__py3-none-any.whl → 0.108.0__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 (58) 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 -10
  5. cartography/data/jobs/cleanup/github_repos_cleanup.json +2 -0
  6. cartography/intel/aws/__init__.py +1 -0
  7. cartography/intel/aws/cloudtrail.py +17 -4
  8. cartography/intel/aws/cloudtrail_management_events.py +560 -16
  9. cartography/intel/aws/cloudwatch.py +150 -4
  10. cartography/intel/aws/ec2/security_groups.py +140 -122
  11. cartography/intel/aws/ec2/snapshots.py +47 -84
  12. cartography/intel/aws/ec2/subnets.py +37 -63
  13. cartography/intel/aws/ecr.py +55 -80
  14. cartography/intel/aws/ecs.py +17 -0
  15. cartography/intel/aws/elasticache.py +102 -79
  16. cartography/intel/aws/guardduty.py +275 -0
  17. cartography/intel/aws/resources.py +2 -0
  18. cartography/intel/aws/secretsmanager.py +62 -44
  19. cartography/intel/github/repos.py +370 -28
  20. cartography/intel/sentinelone/__init__.py +8 -2
  21. cartography/intel/sentinelone/application.py +248 -0
  22. cartography/intel/sentinelone/utils.py +20 -1
  23. cartography/models/aws/cloudtrail/management_events.py +95 -6
  24. cartography/models/aws/cloudtrail/trail.py +21 -0
  25. cartography/models/aws/cloudwatch/log_metric_filter.py +79 -0
  26. cartography/models/aws/cloudwatch/metric_alarm.py +53 -0
  27. cartography/models/aws/ec2/networkinterfaces.py +2 -0
  28. cartography/models/aws/ec2/security_group_rules.py +109 -0
  29. cartography/models/aws/ec2/security_groups.py +90 -0
  30. cartography/models/aws/ec2/snapshots.py +58 -0
  31. cartography/models/aws/ec2/subnet_instance.py +2 -0
  32. cartography/models/aws/ec2/subnet_networkinterface.py +2 -0
  33. cartography/models/aws/ec2/subnets.py +65 -0
  34. cartography/models/aws/ec2/volumes.py +20 -0
  35. cartography/models/aws/ecr/__init__.py +0 -0
  36. cartography/models/aws/ecr/image.py +41 -0
  37. cartography/models/aws/ecr/repository.py +72 -0
  38. cartography/models/aws/ecr/repository_image.py +95 -0
  39. cartography/models/aws/ecs/tasks.py +24 -1
  40. cartography/models/aws/elasticache/__init__.py +0 -0
  41. cartography/models/aws/elasticache/cluster.py +65 -0
  42. cartography/models/aws/elasticache/topic.py +67 -0
  43. cartography/models/aws/guardduty/__init__.py +1 -0
  44. cartography/models/aws/guardduty/findings.py +102 -0
  45. cartography/models/aws/secretsmanager/secret.py +106 -0
  46. cartography/models/github/dependencies.py +74 -0
  47. cartography/models/github/manifests.py +49 -0
  48. cartography/models/sentinelone/application.py +44 -0
  49. cartography/models/sentinelone/application_version.py +96 -0
  50. {cartography-0.107.0rc2.dist-info → cartography-0.108.0.dist-info}/METADATA +3 -3
  51. {cartography-0.107.0rc2.dist-info → cartography-0.108.0.dist-info}/RECORD +55 -36
  52. cartography/data/jobs/cleanup/aws_import_ec2_security_groupinfo_cleanup.json +0 -24
  53. cartography/data/jobs/cleanup/aws_import_secrets_cleanup.json +0 -8
  54. cartography/data/jobs/cleanup/aws_import_snapshots_cleanup.json +0 -30
  55. {cartography-0.107.0rc2.dist-info → cartography-0.108.0.dist-info}/WHEEL +0 -0
  56. {cartography-0.107.0rc2.dist-info → cartography-0.108.0.dist-info}/entry_points.txt +0 -0
  57. {cartography-0.107.0rc2.dist-info → cartography-0.108.0.dist-info}/licenses/LICENSE +0 -0
  58. {cartography-0.107.0rc2.dist-info → cartography-0.108.0.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}"
@@ -29,12 +29,6 @@ class AssumedRoleRelProperties(CartographyRelProperties):
29
29
  times_used: PropertyRef = PropertyRef("times_used")
30
30
  first_seen_in_time_window: PropertyRef = PropertyRef("first_seen_in_time_window")
31
31
 
32
- # Event type tracking properties
33
- event_types: PropertyRef = PropertyRef("event_types")
34
- assume_role_count: PropertyRef = PropertyRef("assume_role_count")
35
- saml_count: PropertyRef = PropertyRef("saml_count")
36
- web_identity_count: PropertyRef = PropertyRef("web_identity_count")
37
-
38
32
 
39
33
  @dataclass(frozen=True)
40
34
  class AssumedRoleMatchLink(CartographyRelSchema):
@@ -62,3 +56,98 @@ class AssumedRoleMatchLink(CartographyRelSchema):
62
56
  direction: LinkDirection = LinkDirection.OUTWARD
63
57
  rel_label: str = "ASSUMED_ROLE"
64
58
  properties: AssumedRoleRelProperties = AssumedRoleRelProperties()
59
+
60
+
61
+ @dataclass(frozen=True)
62
+ class AssumedRoleWithSAMLRelProperties(CartographyRelProperties):
63
+ """
64
+ Properties for the ASSUMED_ROLE_WITH_SAML relationship representing SAML-based role assumption events.
65
+ Focuses specifically on SAML federated identity role assumptions.
66
+ """
67
+
68
+ # Mandatory fields for MatchLinks
69
+ lastupdated: PropertyRef = PropertyRef("lastupdated", set_in_kwargs=True)
70
+ _sub_resource_label: PropertyRef = PropertyRef(
71
+ "_sub_resource_label", set_in_kwargs=True
72
+ )
73
+ _sub_resource_id: PropertyRef = PropertyRef("_sub_resource_id", set_in_kwargs=True)
74
+
75
+ # CloudTrail-specific relationship properties
76
+ last_used: PropertyRef = PropertyRef("last_used")
77
+ times_used: PropertyRef = PropertyRef("times_used")
78
+ first_seen_in_time_window: PropertyRef = PropertyRef("first_seen_in_time_window")
79
+
80
+
81
+ @dataclass(frozen=True)
82
+ class AssumedRoleWithSAMLMatchLink(CartographyRelSchema):
83
+ """
84
+ MatchLink schema for ASSUMED_ROLE_WITH_SAML relationships from CloudTrail SAML events.
85
+ Creates relationships like: (AWSRole)-[:ASSUMED_ROLE_WITH_SAML]->(AWSRole)
86
+
87
+ This MatchLink handles SAML-based role assumption relationships discovered via CloudTrail
88
+ AssumeRoleWithSAML events. It creates separate relationships from regular AssumeRole events
89
+ to preserve visibility into authentication methods used.
90
+ """
91
+
92
+ # MatchLink-specific fields
93
+ source_node_label: str = "AWSSSOUser" # Match against AWS SSO User nodes
94
+ source_node_matcher: SourceNodeMatcher = make_source_node_matcher(
95
+ {"user_name": PropertyRef("source_principal_arn")},
96
+ )
97
+
98
+ # Standard CartographyRelSchema fields
99
+ target_node_label: str = "AWSRole"
100
+ target_node_matcher: TargetNodeMatcher = make_target_node_matcher(
101
+ {"arn": PropertyRef("destination_principal_arn")},
102
+ )
103
+ direction: LinkDirection = LinkDirection.OUTWARD
104
+ rel_label: str = "ASSUMED_ROLE_WITH_SAML"
105
+ properties: AssumedRoleWithSAMLRelProperties = AssumedRoleWithSAMLRelProperties()
106
+
107
+
108
+ @dataclass(frozen=True)
109
+ class AssumeRoleWithWebIdentityRelProperties(CartographyRelProperties):
110
+ """
111
+ Properties for the ASSUMED_ROLE_WITH_WEB_IDENTITY relationship representing web identity-based role assumption events.
112
+ Focuses specifically on web identity federation role assumptions (Google, Amazon, Facebook, etc.).
113
+ """
114
+
115
+ # Mandatory fields for MatchLinks
116
+ lastupdated: PropertyRef = PropertyRef("lastupdated", set_in_kwargs=True)
117
+ _sub_resource_label: PropertyRef = PropertyRef(
118
+ "_sub_resource_label", set_in_kwargs=True
119
+ )
120
+ _sub_resource_id: PropertyRef = PropertyRef("_sub_resource_id", set_in_kwargs=True)
121
+
122
+ # CloudTrail-specific relationship properties
123
+ last_used: PropertyRef = PropertyRef("last_used")
124
+ times_used: PropertyRef = PropertyRef("times_used")
125
+ first_seen_in_time_window: PropertyRef = PropertyRef("first_seen_in_time_window")
126
+
127
+
128
+ @dataclass(frozen=True)
129
+ class GitHubRepoAssumeRoleWithWebIdentityMatchLink(CartographyRelSchema):
130
+ """
131
+ MatchLink schema for ASSUMED_ROLE_WITH_WEB_IDENTITY relationships from GitHub Actions to AWS roles.
132
+ Creates relationships like: (GitHubRepository)-[:ASSUMED_ROLE_WITH_WEB_IDENTITY]->(AWSRole)
133
+
134
+ This MatchLink provides granular visibility into which specific GitHub repositories are assuming
135
+ AWS roles via GitHub Actions OIDC, rather than just showing provider-level relationships.
136
+ """
137
+
138
+ # MatchLink-specific fields for GitHub repositories
139
+ source_node_label: str = "GitHubRepository"
140
+ source_node_matcher: SourceNodeMatcher = make_source_node_matcher(
141
+ {"fullname": PropertyRef("source_repo_fullname")},
142
+ )
143
+
144
+ # Standard CartographyRelSchema fields
145
+ target_node_label: str = "AWSRole"
146
+ target_node_matcher: TargetNodeMatcher = make_target_node_matcher(
147
+ {"arn": PropertyRef("destination_principal_arn")},
148
+ )
149
+ direction: LinkDirection = LinkDirection.OUTWARD
150
+ rel_label: str = "ASSUMED_ROLE_WITH_WEB_IDENTITY"
151
+ properties: AssumeRoleWithWebIdentityRelProperties = (
152
+ AssumeRoleWithWebIdentityRelProperties()
153
+ )
@@ -73,6 +73,26 @@ class CloudTrailTrailToS3BucketRel(CartographyRelSchema):
73
73
  )
74
74
 
75
75
 
76
+ @dataclass(frozen=True)
77
+ class CloudTrailTrailToCloudWatchLogGroupRelProperties(CartographyRelProperties):
78
+ lastupdated: PropertyRef = PropertyRef("lastupdated", set_in_kwargs=True)
79
+
80
+
81
+ @dataclass(frozen=True)
82
+ class CloudTrailTrailToCloudWatchLogGroupRel(CartographyRelSchema):
83
+ target_node_label: str = "CloudWatchLogGroup"
84
+ target_node_matcher: TargetNodeMatcher = make_target_node_matcher(
85
+ {
86
+ "id": PropertyRef("CloudWatchLogsLogGroupArn"),
87
+ }
88
+ )
89
+ direction: LinkDirection = LinkDirection.OUTWARD
90
+ rel_label: str = "SENDS_LOGS_TO_CLOUDWATCH"
91
+ properties: CloudTrailTrailToCloudWatchLogGroupRelProperties = (
92
+ CloudTrailTrailToCloudWatchLogGroupRelProperties()
93
+ )
94
+
95
+
76
96
  @dataclass(frozen=True)
77
97
  class CloudTrailTrailSchema(CartographyNodeSchema):
78
98
  label: str = "CloudTrailTrail"
@@ -81,5 +101,6 @@ class CloudTrailTrailSchema(CartographyNodeSchema):
81
101
  other_relationships: OtherRelationships = OtherRelationships(
82
102
  [
83
103
  CloudTrailTrailToS3BucketRel(),
104
+ CloudTrailTrailToCloudWatchLogGroupRel(),
84
105
  ]
85
106
  )
@@ -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
+ )
@@ -0,0 +1,53 @@
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 TargetNodeMatcher
11
+
12
+
13
+ @dataclass(frozen=True)
14
+ class CloudWatchMetricAlarmNodeProperties(CartographyNodeProperties):
15
+ id: PropertyRef = PropertyRef("AlarmArn")
16
+ arn: PropertyRef = PropertyRef("AlarmArn", extra_index=True)
17
+ alarm_name: PropertyRef = PropertyRef("AlarmName")
18
+ alarm_description: PropertyRef = PropertyRef("AlarmDescription")
19
+ state_value: PropertyRef = PropertyRef("StateValue")
20
+ state_reason: PropertyRef = PropertyRef("StateReason")
21
+ actions_enabled: PropertyRef = PropertyRef("ActionsEnabled")
22
+ comparison_operator: PropertyRef = PropertyRef("ComparisonOperator")
23
+ region: PropertyRef = PropertyRef("Region", set_in_kwargs=True)
24
+ lastupdated: PropertyRef = PropertyRef("lastupdated", set_in_kwargs=True)
25
+
26
+
27
+ @dataclass(frozen=True)
28
+ class CloudWatchMetricAlarmToAwsAccountRelProperties(CartographyRelProperties):
29
+ lastupdated: PropertyRef = PropertyRef("lastupdated", set_in_kwargs=True)
30
+
31
+
32
+ @dataclass(frozen=True)
33
+ class CloudWatchMetricAlarmToAWSAccountRel(CartographyRelSchema):
34
+ target_node_label: str = "AWSAccount"
35
+ target_node_matcher: TargetNodeMatcher = make_target_node_matcher(
36
+ {"id": PropertyRef("AWS_ID", set_in_kwargs=True)},
37
+ )
38
+ direction: LinkDirection = LinkDirection.INWARD
39
+ rel_label: str = "RESOURCE"
40
+ properties: CloudWatchMetricAlarmToAwsAccountRelProperties = (
41
+ CloudWatchMetricAlarmToAwsAccountRelProperties()
42
+ )
43
+
44
+
45
+ @dataclass(frozen=True)
46
+ class CloudWatchMetricAlarmSchema(CartographyNodeSchema):
47
+ label: str = "CloudWatchMetricAlarm"
48
+ properties: CloudWatchMetricAlarmNodeProperties = (
49
+ CloudWatchMetricAlarmNodeProperties()
50
+ )
51
+ sub_resource_relationship: CloudWatchMetricAlarmToAWSAccountRel = (
52
+ CloudWatchMetricAlarmToAWSAccountRel()
53
+ )
@@ -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()])