cartography 0.116.1__py3-none-any.whl → 0.118.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 (70) hide show
  1. cartography/_version.py +2 -2
  2. cartography/cli.py +11 -0
  3. cartography/client/core/tx.py +23 -2
  4. cartography/config.py +5 -0
  5. cartography/graph/job.py +6 -2
  6. cartography/graph/statement.py +4 -0
  7. cartography/intel/aws/__init__.py +1 -0
  8. cartography/intel/aws/apigateway.py +18 -5
  9. cartography/intel/aws/ec2/elastic_ip_addresses.py +3 -1
  10. cartography/intel/aws/ec2/internet_gateways.py +4 -2
  11. cartography/intel/aws/ec2/load_balancer_v2s.py +11 -5
  12. cartography/intel/aws/ec2/network_interfaces.py +4 -0
  13. cartography/intel/aws/ec2/reserved_instances.py +3 -1
  14. cartography/intel/aws/ec2/tgw.py +11 -5
  15. cartography/intel/aws/ec2/volumes.py +1 -1
  16. cartography/intel/aws/ecr.py +202 -26
  17. cartography/intel/aws/ecr_image_layers.py +174 -21
  18. cartography/intel/aws/elasticsearch.py +13 -4
  19. cartography/intel/aws/identitycenter.py +93 -54
  20. cartography/intel/aws/inspector.py +26 -14
  21. cartography/intel/aws/permission_relationships.py +3 -3
  22. cartography/intel/aws/s3.py +26 -13
  23. cartography/intel/aws/ssm.py +3 -5
  24. cartography/intel/azure/__init__.py +16 -0
  25. cartography/intel/azure/compute.py +9 -4
  26. cartography/intel/azure/container_instances.py +95 -0
  27. cartography/intel/azure/cosmosdb.py +31 -15
  28. cartography/intel/azure/data_lake.py +124 -0
  29. cartography/intel/azure/sql.py +25 -12
  30. cartography/intel/azure/storage.py +19 -9
  31. cartography/intel/azure/subscription.py +3 -1
  32. cartography/intel/crowdstrike/spotlight.py +5 -2
  33. cartography/intel/entra/app_role_assignments.py +9 -2
  34. cartography/intel/gcp/__init__.py +26 -9
  35. cartography/intel/gcp/clients.py +8 -4
  36. cartography/intel/gcp/compute.py +39 -18
  37. cartography/intel/gcp/crm/folders.py +9 -3
  38. cartography/intel/gcp/crm/orgs.py +8 -3
  39. cartography/intel/gcp/crm/projects.py +14 -3
  40. cartography/intel/github/teams.py +3 -3
  41. cartography/intel/jamf/computers.py +7 -1
  42. cartography/intel/oci/iam.py +23 -9
  43. cartography/intel/oci/organizations.py +3 -1
  44. cartography/intel/oci/utils.py +28 -5
  45. cartography/intel/okta/awssaml.py +8 -7
  46. cartography/intel/pagerduty/escalation_policies.py +13 -6
  47. cartography/intel/pagerduty/schedules.py +9 -4
  48. cartography/intel/pagerduty/services.py +7 -3
  49. cartography/intel/pagerduty/teams.py +5 -2
  50. cartography/intel/pagerduty/users.py +3 -1
  51. cartography/intel/pagerduty/vendors.py +3 -1
  52. cartography/intel/trivy/__init__.py +109 -58
  53. cartography/models/aws/ec2/networkinterfaces.py +2 -0
  54. cartography/models/aws/ecr/image.py +38 -1
  55. cartography/models/aws/ecr/repository_image.py +1 -1
  56. cartography/models/azure/container_instance.py +55 -0
  57. cartography/models/azure/data_lake_filesystem.py +51 -0
  58. cartography/rules/cli.py +8 -6
  59. cartography/rules/data/frameworks/mitre_attack/__init__.py +7 -1
  60. cartography/rules/data/frameworks/mitre_attack/requirements/t1098_account_manipulation/__init__.py +317 -0
  61. cartography/rules/data/frameworks/mitre_attack/requirements/t1190_exploit_public_facing_application/__init__.py +1 -0
  62. cartography/rules/spec/model.py +13 -0
  63. cartography/sync.py +1 -1
  64. cartography/util.py +5 -1
  65. {cartography-0.116.1.dist-info → cartography-0.118.0.dist-info}/METADATA +5 -4
  66. {cartography-0.116.1.dist-info → cartography-0.118.0.dist-info}/RECORD +70 -65
  67. {cartography-0.116.1.dist-info → cartography-0.118.0.dist-info}/WHEEL +0 -0
  68. {cartography-0.116.1.dist-info → cartography-0.118.0.dist-info}/entry_points.txt +0 -0
  69. {cartography-0.116.1.dist-info → cartography-0.118.0.dist-info}/licenses/LICENSE +0 -0
  70. {cartography-0.116.1.dist-info → cartography-0.118.0.dist-info}/top_level.txt +0 -0
@@ -7,6 +7,7 @@ import dateutil.parser
7
7
  import neo4j
8
8
  from pdpyras import APISession
9
9
 
10
+ from cartography.client.core.tx import run_write_query
10
11
  from cartography.util import timeit
11
12
 
12
13
  logger = logging.getLogger(__name__)
@@ -63,7 +64,8 @@ def load_schedule_data(
63
64
  layer["_schedule_id"] = schedule["id"]
64
65
  layers.append(layer)
65
66
 
66
- neo4j_session.run(
67
+ run_write_query(
68
+ neo4j_session,
67
69
  ingestion_cypher_query,
68
70
  Schedules=data,
69
71
  update_tag=update_tag,
@@ -87,7 +89,8 @@ def _attach_users(
87
89
  MERGE (u)-[r:MEMBER_OF]->(s)
88
90
  ON CREATE SET r.firstseen = timestamp()
89
91
  """
90
- neo4j_session.run(
92
+ run_write_query(
93
+ neo4j_session,
91
94
  ingestion_cypher_query,
92
95
  Relations=data,
93
96
  update_tag=update_tag,
@@ -129,7 +132,8 @@ def _attach_layers(
129
132
  users.append(
130
133
  {"layer_id": layer["_layer_id"], "user": user["user"]["id"]},
131
134
  )
132
- neo4j_session.run(
135
+ run_write_query(
136
+ neo4j_session,
133
137
  ingestion_cypher_query,
134
138
  Layers=data,
135
139
  update_tag=update_tag,
@@ -152,7 +156,8 @@ def _attach_layer_users(
152
156
  MERGE (u)-[r:MEMBER_OF]->(l)
153
157
  ON CREATE SET r.firstseen = timestamp()
154
158
  """
155
- neo4j_session.run(
159
+ run_write_query(
160
+ neo4j_session,
156
161
  ingestion_cypher_query,
157
162
  Relations=data,
158
163
  update_tag=update_tag,
@@ -7,6 +7,7 @@ import dateutil.parser
7
7
  import neo4j
8
8
  from pdpyras import APISession
9
9
 
10
+ from cartography.client.core.tx import run_write_query
10
11
  from cartography.util import timeit
11
12
 
12
13
  logger = logging.getLogger(__name__)
@@ -96,7 +97,8 @@ def load_service_data(
96
97
  for team in service["teams"]:
97
98
  team_relations.append({"service": service["id"], "team": team["id"]})
98
99
 
99
- neo4j_session.run(
100
+ run_write_query(
101
+ neo4j_session,
100
102
  ingestion_cypher_query,
101
103
  Services=data,
102
104
  update_tag=update_tag,
@@ -120,7 +122,8 @@ def _attach_teams(
120
122
  MERGE (t)-[r:ASSOCIATED_WITH]->(s)
121
123
  ON CREATE SET r.firstseen = timestamp()
122
124
  """
123
- neo4j_session.run(
125
+ run_write_query(
126
+ neo4j_session,
124
127
  ingestion_cypher_query,
125
128
  Relations=data,
126
129
  update_tag=update_tag,
@@ -162,7 +165,8 @@ def load_integration_data(
162
165
  created_at = dateutil.parser.parse(integration["created_at"])
163
166
  integration["created_at"] = int(created_at.timestamp())
164
167
 
165
- neo4j_session.run(
168
+ run_write_query(
169
+ neo4j_session,
166
170
  ingestion_cypher_query,
167
171
  Integrations=data,
168
172
  update_tag=update_tag,
@@ -6,6 +6,7 @@ from typing import List
6
6
  import neo4j
7
7
  from pdpyras import APISession
8
8
 
9
+ from cartography.client.core.tx import run_write_query
9
10
  from cartography.util import timeit
10
11
 
11
12
  logger = logging.getLogger(__name__)
@@ -68,7 +69,8 @@ def load_team_data(
68
69
  """
69
70
  logger.info(f"Loading {len(data)} pagerduty teams.")
70
71
 
71
- neo4j_session.run(
72
+ run_write_query(
73
+ neo4j_session,
72
74
  ingestion_cypher_query,
73
75
  Teams=data,
74
76
  update_tag=update_tag,
@@ -90,7 +92,8 @@ def load_team_relations(
90
92
  ON CREATE SET r.firstseen = timestamp()
91
93
  SET r.role = relation.role
92
94
  """
93
- neo4j_session.run(
95
+ run_write_query(
96
+ neo4j_session,
94
97
  ingestion_cypher_query,
95
98
  Relations=data,
96
99
  update_tag=update_tag,
@@ -6,6 +6,7 @@ from typing import List
6
6
  import neo4j
7
7
  from pdpyras import APISession
8
8
 
9
+ from cartography.client.core.tx import run_write_query
9
10
  from cartography.util import timeit
10
11
 
11
12
  logger = logging.getLogger(__name__)
@@ -57,7 +58,8 @@ def load_user_data(
57
58
  """
58
59
  logger.info(f"Loading {len(data)} pagerduty users.")
59
60
 
60
- neo4j_session.run(
61
+ run_write_query(
62
+ neo4j_session,
61
63
  ingestion_cypher_query,
62
64
  Users=data,
63
65
  update_tag=update_tag,
@@ -6,6 +6,7 @@ from typing import List
6
6
  import neo4j
7
7
  from pdpyras import APISession
8
8
 
9
+ from cartography.client.core.tx import run_write_query
9
10
  from cartography.util import timeit
10
11
 
11
12
  logger = logging.getLogger(__name__)
@@ -53,7 +54,8 @@ def load_vendor_data(
53
54
  """
54
55
  logger.info(f"Loading {len(data)} pagerduty vendors.")
55
56
 
56
- neo4j_session.run(
57
+ run_write_query(
58
+ neo4j_session,
57
59
  ingestion_cypher_query,
58
60
  Vendors=data,
59
61
  update_tag=update_tag,
@@ -11,8 +11,7 @@ from cartography.config import Config
11
11
  from cartography.intel.trivy.scanner import cleanup
12
12
  from cartography.intel.trivy.scanner import get_json_files_in_dir
13
13
  from cartography.intel.trivy.scanner import get_json_files_in_s3
14
- from cartography.intel.trivy.scanner import sync_single_image_from_file
15
- from cartography.intel.trivy.scanner import sync_single_image_from_s3
14
+ from cartography.intel.trivy.scanner import sync_single_image
16
15
  from cartography.stats import get_stats_client
17
16
  from cartography.util import timeit
18
17
 
@@ -20,53 +19,93 @@ logger = logging.getLogger(__name__)
20
19
  stat_handler = get_stats_client("trivy.scanner")
21
20
 
22
21
 
23
- @timeit
24
- def get_scan_targets(
22
+ def _get_scan_targets_and_aliases(
25
23
  neo4j_session: Session,
26
24
  account_ids: list[str] | None = None,
27
- ) -> set[str]:
25
+ ) -> tuple[set[str], dict[str, str]]:
28
26
  """
29
- Return list of ECR images from all accounts in the graph.
27
+ Return tag URIs and a mapping of digest-qualified URIs to tag URIs.
30
28
  """
31
29
  if not account_ids:
32
30
  aws_accounts = list_accounts(neo4j_session)
33
31
  else:
34
32
  aws_accounts = account_ids
35
33
 
36
- ecr_images: set[str] = set()
34
+ image_uris: set[str] = set()
35
+ digest_aliases: dict[str, str] = {}
36
+
37
37
  for account_id in aws_accounts:
38
- for _, _, image_uri, _, _ in get_ecr_images(neo4j_session, account_id):
39
- ecr_images.add(image_uri)
38
+ for _, _, image_uri, _, digest in get_ecr_images(neo4j_session, account_id):
39
+ if not image_uri:
40
+ continue
41
+ image_uris.add(image_uri)
42
+ if digest:
43
+ # repo URI is everything before the trailing ":" (if present)
44
+ repo_uri = image_uri.rsplit(":", 1)[0]
45
+ digest_uri = f"{repo_uri}@{digest}"
46
+ digest_aliases[digest_uri] = image_uri
40
47
 
41
- return ecr_images
48
+ return image_uris, digest_aliases
42
49
 
43
50
 
44
- def _get_intersection(
45
- image_uris: set[str], json_files: set[str], trivy_s3_prefix: str
46
- ) -> list[tuple[str, str]]:
51
+ @timeit
52
+ def get_scan_targets(
53
+ neo4j_session: Session,
54
+ account_ids: list[str] | None = None,
55
+ ) -> set[str]:
56
+ """
57
+ Return list of ECR images from all accounts in the graph.
47
58
  """
48
- Get the intersection of ECR images in the graph and S3 scan results.
59
+ image_uris, _ = _get_scan_targets_and_aliases(neo4j_session, account_ids)
60
+ return image_uris
49
61
 
50
- Args:
51
- image_uris: Set of ECR images in the graph
52
- json_files: Set of S3 object keys for JSON files
53
- trivy_s3_prefix: S3 prefix path containing scan results
54
62
 
55
- Returns:
56
- List of tuples (image_uri, s3_object_key)
63
+ def _prepare_trivy_data(
64
+ trivy_data: dict[str, Any],
65
+ image_uris: set[str],
66
+ digest_aliases: dict[str, str],
67
+ source: str,
68
+ ) -> tuple[dict[str, Any], str] | None:
57
69
  """
58
- intersection = []
59
- prefix_len = len(trivy_s3_prefix)
60
- for s3_object_key in json_files:
61
- # Sample key "123456789012.dkr.ecr.us-west-2.amazonaws.com/other-repo:v1.0.json"
62
- # Sample key "folder/derp/123456789012.dkr.ecr.us-west-2.amazonaws.com/other-repo:v1.0.json"
63
- # Remove the prefix and the .json suffix
64
- image_uri = s3_object_key[prefix_len:-5]
70
+ Determine the tag URI that corresponds to this Trivy payload.
71
+
72
+ Returns (trivy_data, display_uri) if the payload can be linked to an image present
73
+ in the graph; otherwise returns None so the caller can skip ingestion.
74
+ """
75
+
76
+ artifact_name = (trivy_data.get("ArtifactName") or "").strip()
77
+ metadata = trivy_data.get("Metadata") or {}
78
+ candidates: list[str] = []
79
+
80
+ if artifact_name:
81
+ candidates.append(artifact_name)
65
82
 
66
- if image_uri in image_uris:
67
- intersection.append((image_uri, s3_object_key))
83
+ repo_tags = metadata.get("RepoTags", [])
84
+ repo_digests = metadata.get("RepoDigests", [])
85
+ stripped_tags_digests = [item.strip() for item in repo_tags + repo_digests]
86
+ candidates.extend(stripped_tags_digests)
68
87
 
69
- return intersection
88
+ display_uri: str | None = None
89
+
90
+ for candidate in candidates:
91
+ if not candidate:
92
+ continue
93
+ if candidate in image_uris:
94
+ display_uri = candidate
95
+ break
96
+ alias = digest_aliases.get(candidate)
97
+ if alias:
98
+ display_uri = alias
99
+ break
100
+
101
+ if not display_uri:
102
+ logger.debug(
103
+ "Skipping Trivy results for %s because no matching image URI was found in the graph",
104
+ source,
105
+ )
106
+ return None
107
+
108
+ return trivy_data, display_uri
70
109
 
71
110
 
72
111
  @timeit
@@ -93,15 +132,12 @@ def sync_trivy_aws_ecr_from_s3(
93
132
  f"Using Trivy scan results from s3://{trivy_s3_bucket}/{trivy_s3_prefix}"
94
133
  )
95
134
 
96
- image_uris: set[str] = get_scan_targets(neo4j_session)
135
+ image_uris, digest_aliases = _get_scan_targets_and_aliases(neo4j_session)
97
136
  json_files: set[str] = get_json_files_in_s3(
98
137
  trivy_s3_bucket, trivy_s3_prefix, boto3_session
99
138
  )
100
- intersection: list[tuple[str, str]] = _get_intersection(
101
- image_uris, json_files, trivy_s3_prefix
102
- )
103
139
 
104
- if len(intersection) == 0:
140
+ if len(json_files) == 0:
105
141
  logger.error(
106
142
  f"Trivy sync was configured, but there are no ECR images with S3 json scan results in bucket "
107
143
  f"'{trivy_s3_bucket}' with prefix '{trivy_s3_prefix}'. "
@@ -110,18 +146,33 @@ def sync_trivy_aws_ecr_from_s3(
110
146
  f"`<image_uri>.json` and to be in the same bucket and prefix as the scan results. If the prefix is "
111
147
  "a folder, it MUST end with a trailing slash '/'. "
112
148
  )
113
- logger.error(f"JSON files in S3: {json_files}")
114
149
  raise ValueError("No ECR images with S3 json scan results found.")
115
150
 
116
- logger.info(f"Processing {len(intersection)} ECR images with S3 scan results")
117
- for image_uri, s3_object_key in intersection:
118
- sync_single_image_from_s3(
151
+ logger.info(f"Processing {len(json_files)} Trivy result files from S3")
152
+ s3_client = boto3_session.client("s3")
153
+ for s3_object_key in json_files:
154
+ logger.debug(
155
+ f"Reading scan results from S3: s3://{trivy_s3_bucket}/{s3_object_key}"
156
+ )
157
+ response = s3_client.get_object(Bucket=trivy_s3_bucket, Key=s3_object_key)
158
+ scan_data_json = response["Body"].read().decode("utf-8")
159
+ trivy_data = json.loads(scan_data_json)
160
+
161
+ prepared = _prepare_trivy_data(
162
+ trivy_data,
163
+ image_uris=image_uris,
164
+ digest_aliases=digest_aliases,
165
+ source=f"s3://{trivy_s3_bucket}/{s3_object_key}",
166
+ )
167
+ if prepared is None:
168
+ continue
169
+
170
+ prepared_data, display_uri = prepared
171
+ sync_single_image(
119
172
  neo4j_session,
120
- image_uri,
173
+ prepared_data,
174
+ display_uri,
121
175
  update_tag,
122
- trivy_s3_bucket,
123
- s3_object_key,
124
- boto3_session,
125
176
  )
126
177
 
127
178
  cleanup(neo4j_session, common_job_parameters)
@@ -137,7 +188,7 @@ def sync_trivy_aws_ecr_from_dir(
137
188
  """Sync Trivy scan results from local files for AWS ECR images."""
138
189
  logger.info(f"Using Trivy scan results from {results_dir}")
139
190
 
140
- image_uris: set[str] = get_scan_targets(neo4j_session)
191
+ image_uris, digest_aliases = _get_scan_targets_and_aliases(neo4j_session)
141
192
  json_files: set[str] = get_json_files_in_dir(results_dir)
142
193
 
143
194
  if not json_files:
@@ -149,27 +200,27 @@ def sync_trivy_aws_ecr_from_dir(
149
200
  logger.info(f"Processing {len(json_files)} local Trivy result files")
150
201
 
151
202
  for file_path in json_files:
152
- # First, check if the image exists in the graph before syncing
153
203
  try:
154
- # Peek at the artifact name without processing the file
155
204
  with open(file_path, encoding="utf-8") as f:
156
205
  trivy_data = json.load(f)
157
- artifact_name = trivy_data.get("ArtifactName")
158
-
159
- if artifact_name and artifact_name not in image_uris:
160
- logger.debug(
161
- f"Skipping results for {artifact_name} since the image is not present in the graph"
162
- )
163
- continue
206
+ except json.JSONDecodeError as e:
207
+ logger.error(f"Failed to read Trivy data from {file_path}: {e}")
208
+ continue
164
209
 
165
- except (json.JSONDecodeError, KeyError) as e:
166
- logger.error(f"Failed to read artifact name from {file_path}: {e}")
210
+ prepared = _prepare_trivy_data(
211
+ trivy_data,
212
+ image_uris=image_uris,
213
+ digest_aliases=digest_aliases,
214
+ source=file_path,
215
+ )
216
+ if prepared is None:
167
217
  continue
168
218
 
169
- # Now sync the file since we know the image exists in the graph
170
- sync_single_image_from_file(
219
+ prepared_data, display_uri = prepared
220
+ sync_single_image(
171
221
  neo4j_session,
172
- file_path,
222
+ prepared_data,
223
+ display_uri,
173
224
  update_tag,
174
225
  )
175
226
 
@@ -47,6 +47,8 @@ class EC2NetworkInterfaceNodeProperties(CartographyNodeProperties):
47
47
  # TODO: remove subnetid once we have migrated to subnet_id
48
48
  subnetid: PropertyRef = PropertyRef("SubnetId", extra_index=True)
49
49
  subnet_id: PropertyRef = PropertyRef("SubnetId", extra_index=True)
50
+ attach_time: PropertyRef = PropertyRef("AttachTime")
51
+ device_index: PropertyRef = PropertyRef("DeviceIndex")
50
52
 
51
53
 
52
54
  @dataclass(frozen=True)
@@ -18,6 +18,14 @@ class ECRImageNodeProperties(CartographyNodeProperties):
18
18
  region: PropertyRef = PropertyRef("Region", set_in_kwargs=True)
19
19
  lastupdated: PropertyRef = PropertyRef("lastupdated", set_in_kwargs=True)
20
20
  layer_diff_ids: PropertyRef = PropertyRef("layer_diff_ids")
21
+ type: PropertyRef = PropertyRef("type")
22
+ architecture: PropertyRef = PropertyRef("architecture")
23
+ os: PropertyRef = PropertyRef("os")
24
+ variant: PropertyRef = PropertyRef("variant")
25
+ attestation_type: PropertyRef = PropertyRef("attestation_type")
26
+ attests_digest: PropertyRef = PropertyRef("attests_digest")
27
+ media_type: PropertyRef = PropertyRef("media_type")
28
+ artifact_media_type: PropertyRef = PropertyRef("artifact_media_type")
21
29
 
22
30
 
23
31
  @dataclass(frozen=True)
@@ -52,11 +60,40 @@ class ECRImageHasLayerRel(CartographyRelSchema):
52
60
  properties: ECRImageHasLayerRelProperties = ECRImageHasLayerRelProperties()
53
61
 
54
62
 
63
+ @dataclass(frozen=True)
64
+ class ECRImageToParentImageRelProperties(CartographyRelProperties):
65
+ lastupdated: PropertyRef = PropertyRef("lastupdated", set_in_kwargs=True)
66
+ from_attestation: PropertyRef = PropertyRef("from_attestation")
67
+ parent_image_uri: PropertyRef = PropertyRef("parent_image_uri")
68
+ confidence: PropertyRef = PropertyRef("confidence")
69
+
70
+
71
+ @dataclass(frozen=True)
72
+ class ECRImageToParentImageRel(CartographyRelSchema):
73
+ """
74
+ Relationship from an ECRImage to its parent ECRImage (BUILT_FROM).
75
+ This relationship is created when provenance attestations explicitly specify the parent image.
76
+ """
77
+
78
+ target_node_label: str = "ECRImage"
79
+ target_node_matcher: TargetNodeMatcher = make_target_node_matcher(
80
+ {"digest": PropertyRef("parent_image_digest")},
81
+ )
82
+ direction: LinkDirection = LinkDirection.OUTWARD
83
+ rel_label: str = "BUILT_FROM"
84
+ properties: ECRImageToParentImageRelProperties = (
85
+ ECRImageToParentImageRelProperties()
86
+ )
87
+
88
+
55
89
  @dataclass(frozen=True)
56
90
  class ECRImageSchema(CartographyNodeSchema):
57
91
  label: str = "ECRImage"
58
92
  properties: ECRImageNodeProperties = ECRImageNodeProperties()
59
93
  sub_resource_relationship: ECRImageToAWSAccountRel = ECRImageToAWSAccountRel()
60
94
  other_relationships: OtherRelationships = OtherRelationships(
61
- [ECRImageHasLayerRel()],
95
+ [
96
+ ECRImageHasLayerRel(),
97
+ ECRImageToParentImageRel(),
98
+ ],
62
99
  )
@@ -71,7 +71,7 @@ class ECRRepositoryImageToECRImageRelProperties(CartographyRelProperties):
71
71
  class ECRRepositoryImageToECRImageRel(CartographyRelSchema):
72
72
  target_node_label: str = "ECRImage"
73
73
  target_node_matcher: TargetNodeMatcher = make_target_node_matcher(
74
- {"id": PropertyRef("imageDigest")}
74
+ {"id": PropertyRef("imageDigests", one_to_many=True)}
75
75
  )
76
76
  direction: LinkDirection = LinkDirection.OUTWARD
77
77
  rel_label: str = "IMAGE"
@@ -0,0 +1,55 @@
1
+ import logging
2
+ from dataclasses import dataclass
3
+
4
+ from cartography.models.core.common import PropertyRef
5
+ from cartography.models.core.nodes import CartographyNodeProperties
6
+ from cartography.models.core.nodes import CartographyNodeSchema
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 TargetNodeMatcher
12
+
13
+ logger = logging.getLogger(__name__)
14
+
15
+
16
+ # --- Node Definitions ---
17
+ @dataclass(frozen=True)
18
+ class AzureContainerInstanceProperties(CartographyNodeProperties):
19
+ id: PropertyRef = PropertyRef("id")
20
+ name: PropertyRef = PropertyRef("name")
21
+ location: PropertyRef = PropertyRef("location")
22
+ type: PropertyRef = PropertyRef("type")
23
+ provisioning_state: PropertyRef = PropertyRef("provisioning_state")
24
+ ip_address: PropertyRef = PropertyRef("ip_address")
25
+ os_type: PropertyRef = PropertyRef("os_type")
26
+ lastupdated: PropertyRef = PropertyRef("lastupdated", set_in_kwargs=True)
27
+
28
+
29
+ # --- Relationship Definitions ---
30
+ @dataclass(frozen=True)
31
+ class AzureContainerInstanceToSubscriptionRelProperties(CartographyRelProperties):
32
+ lastupdated: PropertyRef = PropertyRef("lastupdated", set_in_kwargs=True)
33
+
34
+
35
+ @dataclass(frozen=True)
36
+ class AzureContainerInstanceToSubscriptionRel(CartographyRelSchema):
37
+ target_node_label: str = "AzureSubscription"
38
+ target_node_matcher: TargetNodeMatcher = make_target_node_matcher(
39
+ {"id": PropertyRef("AZURE_SUBSCRIPTION_ID", set_in_kwargs=True)},
40
+ )
41
+ direction: LinkDirection = LinkDirection.INWARD
42
+ rel_label: str = "RESOURCE"
43
+ properties: AzureContainerInstanceToSubscriptionRelProperties = (
44
+ AzureContainerInstanceToSubscriptionRelProperties()
45
+ )
46
+
47
+
48
+ # --- Main Schema ---
49
+ @dataclass(frozen=True)
50
+ class AzureContainerInstanceSchema(CartographyNodeSchema):
51
+ label: str = "AzureContainerInstance"
52
+ properties: AzureContainerInstanceProperties = AzureContainerInstanceProperties()
53
+ sub_resource_relationship: AzureContainerInstanceToSubscriptionRel = (
54
+ AzureContainerInstanceToSubscriptionRel()
55
+ )
@@ -0,0 +1,51 @@
1
+ import logging
2
+ from dataclasses import dataclass
3
+
4
+ from cartography.models.core.common import PropertyRef
5
+ from cartography.models.core.nodes import CartographyNodeProperties
6
+ from cartography.models.core.nodes import CartographyNodeSchema
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 TargetNodeMatcher
12
+
13
+ logger = logging.getLogger(__name__)
14
+
15
+
16
+ @dataclass(frozen=True)
17
+ class AzureDataLakeFileSystemProperties(CartographyNodeProperties):
18
+ id: PropertyRef = PropertyRef("id")
19
+ name: PropertyRef = PropertyRef("name")
20
+ public_access: PropertyRef = PropertyRef("public_access")
21
+ last_modified_time: PropertyRef = PropertyRef("last_modified_time")
22
+ has_immutability_policy: PropertyRef = PropertyRef("has_immutability_policy")
23
+ has_legal_hold: PropertyRef = PropertyRef("has_legal_hold")
24
+ lastupdated: PropertyRef = PropertyRef("lastupdated", set_in_kwargs=True)
25
+
26
+
27
+ @dataclass(frozen=True)
28
+ class AzureDataLakeFileSystemToStorageAccountRelProperties(CartographyRelProperties):
29
+ lastupdated: PropertyRef = PropertyRef("lastupdated", set_in_kwargs=True)
30
+
31
+
32
+ @dataclass(frozen=True)
33
+ class AzureDataLakeFileSystemToStorageAccountRel(CartographyRelSchema):
34
+ target_node_label: str = "AzureStorageAccount"
35
+ target_node_matcher: TargetNodeMatcher = make_target_node_matcher(
36
+ {"id": PropertyRef("STORAGE_ACCOUNT_ID", set_in_kwargs=True)},
37
+ )
38
+ direction: LinkDirection = LinkDirection.INWARD
39
+ rel_label: str = "CONTAINS"
40
+ properties: AzureDataLakeFileSystemToStorageAccountRelProperties = (
41
+ AzureDataLakeFileSystemToStorageAccountRelProperties()
42
+ )
43
+
44
+
45
+ @dataclass(frozen=True)
46
+ class AzureDataLakeFileSystemSchema(CartographyNodeSchema):
47
+ label: str = "AzureDataLakeFileSystem"
48
+ properties: AzureDataLakeFileSystemProperties = AzureDataLakeFileSystemProperties()
49
+ sub_resource_relationship: AzureDataLakeFileSystemToStorageAccountRel = (
50
+ AzureDataLakeFileSystemToStorageAccountRel()
51
+ )
cartography/rules/cli.py CHANGED
@@ -47,19 +47,21 @@ def complete_frameworks_with_all(incomplete: str) -> Generator[str, None, None]:
47
47
 
48
48
  def complete_requirements(
49
49
  ctx: typer.Context, incomplete: str
50
- ) -> Generator[str, None, None]:
51
- """Autocomplete requirement IDs based on selected framework."""
50
+ ) -> Generator[tuple[str, str], None, None]:
51
+ """Autocomplete requirement IDs with descriptions based on selected framework."""
52
52
  framework = ctx.params.get("framework")
53
53
  if not framework or framework not in FRAMEWORKS:
54
54
  return
55
55
 
56
56
  for req in FRAMEWORKS[framework].requirements:
57
57
  if req.id.lower().startswith(incomplete.lower()):
58
- yield req.id
58
+ yield (req.id, req.name)
59
59
 
60
60
 
61
- def complete_facts(ctx: typer.Context, incomplete: str) -> Generator[str, None, None]:
62
- """Autocomplete fact IDs based on selected framework and requirement."""
61
+ def complete_facts(
62
+ ctx: typer.Context, incomplete: str
63
+ ) -> Generator[tuple[str, str], None, None]:
64
+ """Autocomplete fact IDs with descriptions based on selected framework and requirement."""
63
65
  framework = ctx.params.get("framework")
64
66
  requirement_id = ctx.params.get("requirement")
65
67
 
@@ -73,7 +75,7 @@ def complete_facts(ctx: typer.Context, incomplete: str) -> Generator[str, None,
73
75
  if req.id.lower() == requirement_id.lower():
74
76
  for fact in req.facts:
75
77
  if fact.id.lower().startswith(incomplete.lower()):
76
- yield fact.id
78
+ yield (fact.id, fact.name)
77
79
  break
78
80
 
79
81
 
@@ -1,4 +1,7 @@
1
1
  # MITRE ATT&CK Framework
2
+ from cartography.rules.data.frameworks.mitre_attack.requirements.t1098_account_manipulation import (
3
+ t1098,
4
+ )
2
5
  from cartography.rules.data.frameworks.mitre_attack.requirements.t1190_exploit_public_facing_application import (
3
6
  t1190,
4
7
  )
@@ -9,6 +12,9 @@ mitre_attack_framework = Framework(
9
12
  name="MITRE ATT&CK",
10
13
  description="Comprehensive security assessment framework based on MITRE ATT&CK tactics and techniques",
11
14
  version="1.0",
12
- requirements=(t1190,),
15
+ requirements=(
16
+ t1098,
17
+ t1190,
18
+ ),
13
19
  source_url="https://attack.mitre.org/",
14
20
  )