cartography 0.73.1__tar.gz → 0.75.0__tar.gz

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.
Files changed (285) hide show
  1. {cartography-0.73.1/cartography.egg-info → cartography-0.75.0}/PKG-INFO +1 -1
  2. {cartography-0.73.1 → cartography-0.75.0}/cartography/client/core/tx.py +42 -0
  3. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/indexes.cypher +1 -3
  4. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/analysis/aws_ec2_asset_exposure.json +5 -5
  5. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/analysis/aws_ec2_keypair_analysis.json +2 -2
  6. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/analysis/aws_eks_asset_exposure.json +1 -1
  7. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/analysis/aws_foreign_accounts.json +2 -2
  8. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/analysis/gcp_compute_asset_inet_exposure.json +4 -4
  9. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/analysis/gcp_gke_asset_exposure.json +1 -1
  10. cartography-0.75.0/cartography/data/jobs/analysis/gcp_gke_basic_auth.json +15 -0
  11. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_apigateway_details.json +1 -1
  12. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_kms_details.json +1 -1
  13. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_s3_details.json +1 -1
  14. {cartography-0.73.1 → cartography-0.75.0}/cartography/graph/cleanupbuilder.py +18 -38
  15. {cartography-0.73.1 → cartography-0.75.0}/cartography/graph/job.py +1 -3
  16. {cartography-0.73.1 → cartography-0.75.0}/cartography/graph/querybuilder.py +80 -3
  17. {cartography-0.73.1 → cartography-0.75.0}/cartography/graph/statement.py +14 -3
  18. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/aws/apigateway.py +1 -1
  19. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/aws/ecs.py +26 -19
  20. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/aws/emr.py +17 -22
  21. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/aws/iam.py +15 -10
  22. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/aws/kms.py +1 -1
  23. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/aws/rds.py +1 -1
  24. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/aws/s3.py +3 -3
  25. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/azure/util/credentials.py +13 -3
  26. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/oci/iam.py +1 -1
  27. {cartography-0.73.1 → cartography-0.75.0}/cartography/models/aws/emr.py +1 -1
  28. cartography-0.75.0/cartography/models/core/common.py +58 -0
  29. {cartography-0.73.1 → cartography-0.75.0/cartography.egg-info}/PKG-INFO +1 -1
  30. {cartography-0.73.1 → cartography-0.75.0}/setup.py +1 -1
  31. cartography-0.73.1/cartography/data/jobs/analysis/gcp_gke_basic_auth.json +0 -15
  32. cartography-0.73.1/cartography/models/core/common.py +0 -38
  33. {cartography-0.73.1 → cartography-0.75.0}/LICENSE +0 -0
  34. {cartography-0.73.1 → cartography-0.75.0}/NOTICE +0 -0
  35. {cartography-0.73.1 → cartography-0.75.0}/README.md +0 -0
  36. {cartography-0.73.1 → cartography-0.75.0}/cartography/__init__.py +0 -0
  37. {cartography-0.73.1 → cartography-0.75.0}/cartography/__main__.py +0 -0
  38. {cartography-0.73.1 → cartography-0.75.0}/cartography/cli.py +0 -0
  39. {cartography-0.73.1 → cartography-0.75.0}/cartography/client/__init__.py +0 -0
  40. {cartography-0.73.1 → cartography-0.75.0}/cartography/client/aws/__init__.py +0 -0
  41. {cartography-0.73.1 → cartography-0.75.0}/cartography/client/aws/iam.py +0 -0
  42. {cartography-0.73.1 → cartography-0.75.0}/cartography/client/core/__init__.py +0 -0
  43. {cartography-0.73.1 → cartography-0.75.0}/cartography/config.py +0 -0
  44. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/__init__.py +0 -0
  45. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/__init__.py +0 -0
  46. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/analysis/__init__.py +0 -0
  47. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/analysis/aws_ec2_iaminstance.json +0 -0
  48. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/analysis/aws_ec2_iaminstanceprofile.json +0 -0
  49. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/analysis/aws_lambda_ecr.json +0 -0
  50. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/analysis/aws_s3acl_analysis.json +0 -0
  51. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/analysis/gsuite_human_link.json +0 -0
  52. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/__init__.py +0 -0
  53. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_account_cleanup.json +0 -0
  54. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_dns_cleanup.json +0 -0
  55. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_import_account_access_key_cleanup.json +0 -0
  56. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_import_apigateway_cleanup.json +0 -0
  57. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_import_config_cleanup.json +0 -0
  58. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_import_dynamodb_tables_cleanup.json +0 -0
  59. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_import_ec2_images_cleanup.json +0 -0
  60. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_import_ec2_instances_cleanup.json +0 -0
  61. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_import_ec2_key_pairs_cleanup.json +0 -0
  62. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_import_ec2_launch_configurations_cleanup.json +0 -0
  63. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_import_ec2_launch_templates_cleanup.json +0 -0
  64. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_import_ec2_security_groupinfo_cleanup.json +0 -0
  65. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_import_ecr_cleanup.json +0 -0
  66. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_import_ecs_cleanup.json +0 -0
  67. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_import_eks_cleanup.json +0 -0
  68. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_import_elastic_ip_addresses_cleanup.json +0 -0
  69. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_import_elasticache_cleanup.json +0 -0
  70. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_import_es_cleanup.json +0 -0
  71. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_import_groups_cleanup.json +0 -0
  72. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_import_groups_membership_cleanup.json +0 -0
  73. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_import_groups_policy_cleanup.json +0 -0
  74. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_import_inspector_cleanup.json +0 -0
  75. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_import_internet_gateways_cleanup.json +0 -0
  76. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_import_kms_cleanup.json +0 -0
  77. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_import_lambda_cleanup.json +0 -0
  78. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_import_principals_cleanup.json +0 -0
  79. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_import_rds_clusters_cleanup.json +0 -0
  80. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_import_rds_instances_cleanup.json +0 -0
  81. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_import_rds_snapshots_cleanup.json +0 -0
  82. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_import_redshift_clusters_cleanup.json +0 -0
  83. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_import_reserved_instances_cleanup.json +0 -0
  84. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_import_roles_cleanup.json +0 -0
  85. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_import_roles_policy_cleanup.json +0 -0
  86. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_import_s3_acl_cleanup.json +0 -0
  87. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_import_s3_buckets_cleanup.json +0 -0
  88. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_import_secrets_cleanup.json +0 -0
  89. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_import_securityhub_cleanup.json +0 -0
  90. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_import_snapshots_cleanup.json +0 -0
  91. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_import_sqs_queues_cleanup.json +0 -0
  92. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_import_ssm_cleanup.json +0 -0
  93. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_import_tags_cleanup.json +0 -0
  94. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_import_tgw_cleanup.json +0 -0
  95. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_import_users_cleanup.json +0 -0
  96. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_import_volumes_cleanup.json +0 -0
  97. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_import_vpc_cleanup.json +0 -0
  98. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_import_vpc_peering_cleanup.json +0 -0
  99. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_ingest_ec2_auto_scaling_groups_cleanup.json +0 -0
  100. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_ingest_load_balancers_cleanup.json +0 -0
  101. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_ingest_load_balancers_v2_cleanup.json +0 -0
  102. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_ingest_network_interfaces_cleanup.json +0 -0
  103. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_ingest_subnets_cleanup.json +0 -0
  104. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/aws_post_ingestion_principals_cleanup.json +0 -0
  105. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/azure_cosmosdb_cassandra_keyspace_cleanup.json +0 -0
  106. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/azure_cosmosdb_cors_details.json +0 -0
  107. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/azure_cosmosdb_mongodb_database_cleanup.json +0 -0
  108. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/azure_cosmosdb_sql_database_cleanup.json +0 -0
  109. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/azure_cosmosdb_table_resources_cleanup.json +0 -0
  110. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/azure_database_account_cleanup.json +0 -0
  111. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/azure_import_disks_cleanup.json +0 -0
  112. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/azure_import_snapshots_cleanup.json +0 -0
  113. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/azure_import_virtual_machines_cleanup.json +0 -0
  114. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/azure_sql_server_cleanup.json +0 -0
  115. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/azure_storage_account_cleanup.json +0 -0
  116. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/azure_subscriptions_cleanup.json +0 -0
  117. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/azure_tenant_cleanup.json +0 -0
  118. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/crowdstrike_import_cleanup.json +0 -0
  119. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/crxcavator_import_cleanup.json +0 -0
  120. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/digitalocean_droplet_cleanup.json +0 -0
  121. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/digitalocean_project_cleanup.json +0 -0
  122. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/gcp_compute_firewall_cleanup.json +0 -0
  123. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/gcp_compute_forwarding_rules_cleanup.json +0 -0
  124. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/gcp_compute_instance_cleanup.json +0 -0
  125. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/gcp_compute_vpc_cleanup.json +0 -0
  126. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/gcp_compute_vpc_subnet_cleanup.json +0 -0
  127. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/gcp_crm_folder_cleanup.json +0 -0
  128. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/gcp_crm_organization_cleanup.json +0 -0
  129. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/gcp_crm_project_cleanup.json +0 -0
  130. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/gcp_dns_cleanup.json +0 -0
  131. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/gcp_gke_cluster_cleanup.json +0 -0
  132. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/gcp_storage_bucket_cleanup.json +0 -0
  133. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/github_repos_cleanup.json +0 -0
  134. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/github_users_cleanup.json +0 -0
  135. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/gsuite_ingest_groups_cleanup.json +0 -0
  136. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/gsuite_ingest_users_cleanup.json +0 -0
  137. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/jamf_import_computers_cleanup.json +0 -0
  138. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/kubernetes_import_cleanup.json +0 -0
  139. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/oci_import_compartments_cleanup.json +0 -0
  140. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/oci_import_groups_cleanup.json +0 -0
  141. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/oci_import_groups_membership_cleanup.json +0 -0
  142. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/oci_import_policies_cleanup.json +0 -0
  143. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/oci_import_users_cleanup.json +0 -0
  144. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/oci_tenancy_cleanup.json +0 -0
  145. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/okta_groups_cleanup.json +0 -0
  146. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/okta_import_cleanup.json +0 -0
  147. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/jobs/cleanup/pagerduty_import_cleanup.json +0 -0
  148. {cartography-0.73.1 → cartography-0.75.0}/cartography/data/permission_relationships.yaml +0 -0
  149. {cartography-0.73.1 → cartography-0.75.0}/cartography/driftdetect/__init__.py +0 -0
  150. {cartography-0.73.1 → cartography-0.75.0}/cartography/driftdetect/__main__.py +0 -0
  151. {cartography-0.73.1 → cartography-0.75.0}/cartography/driftdetect/add_shortcut.py +0 -0
  152. {cartography-0.73.1 → cartography-0.75.0}/cartography/driftdetect/cli.py +0 -0
  153. {cartography-0.73.1 → cartography-0.75.0}/cartography/driftdetect/config.py +0 -0
  154. {cartography-0.73.1 → cartography-0.75.0}/cartography/driftdetect/detect_deviations.py +0 -0
  155. {cartography-0.73.1 → cartography-0.75.0}/cartography/driftdetect/get_states.py +0 -0
  156. {cartography-0.73.1 → cartography-0.75.0}/cartography/driftdetect/model.py +0 -0
  157. {cartography-0.73.1 → cartography-0.75.0}/cartography/driftdetect/reporter.py +0 -0
  158. {cartography-0.73.1 → cartography-0.75.0}/cartography/driftdetect/serializers.py +0 -0
  159. {cartography-0.73.1 → cartography-0.75.0}/cartography/driftdetect/shortcut.py +0 -0
  160. {cartography-0.73.1 → cartography-0.75.0}/cartography/driftdetect/storage.py +0 -0
  161. {cartography-0.73.1 → cartography-0.75.0}/cartography/driftdetect/util.py +0 -0
  162. {cartography-0.73.1 → cartography-0.75.0}/cartography/graph/__init__.py +0 -0
  163. {cartography-0.73.1 → cartography-0.75.0}/cartography/graph/context.py +0 -0
  164. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/__init__.py +0 -0
  165. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/analysis.py +0 -0
  166. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/aws/__init__.py +0 -0
  167. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/aws/config.py +0 -0
  168. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/aws/dynamodb.py +0 -0
  169. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/aws/ec2/__init__.py +0 -0
  170. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/aws/ec2/auto_scaling_groups.py +0 -0
  171. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/aws/ec2/elastic_ip_addresses.py +0 -0
  172. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/aws/ec2/images.py +0 -0
  173. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/aws/ec2/instances.py +0 -0
  174. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/aws/ec2/internet_gateways.py +0 -0
  175. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/aws/ec2/key_pairs.py +0 -0
  176. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/aws/ec2/launch_templates.py +0 -0
  177. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/aws/ec2/load_balancer_v2s.py +0 -0
  178. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/aws/ec2/load_balancers.py +0 -0
  179. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/aws/ec2/network_interfaces.py +0 -0
  180. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/aws/ec2/reserved_instances.py +0 -0
  181. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/aws/ec2/security_groups.py +0 -0
  182. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/aws/ec2/snapshots.py +0 -0
  183. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/aws/ec2/subnets.py +0 -0
  184. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/aws/ec2/tgw.py +0 -0
  185. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/aws/ec2/util.py +0 -0
  186. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/aws/ec2/volumes.py +0 -0
  187. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/aws/ec2/vpc.py +0 -0
  188. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/aws/ec2/vpc_peerings.py +0 -0
  189. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/aws/ecr.py +0 -0
  190. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/aws/eks.py +0 -0
  191. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/aws/elasticache.py +0 -0
  192. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/aws/elasticsearch.py +0 -0
  193. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/aws/inspector.py +0 -0
  194. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/aws/lambda_function.py +0 -0
  195. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/aws/organizations.py +0 -0
  196. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/aws/permission_relationships.py +0 -0
  197. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/aws/redshift.py +0 -0
  198. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/aws/resourcegroupstaggingapi.py +0 -0
  199. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/aws/resources.py +0 -0
  200. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/aws/route53.py +0 -0
  201. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/aws/secretsmanager.py +0 -0
  202. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/aws/securityhub.py +0 -0
  203. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/aws/sqs.py +0 -0
  204. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/aws/ssm.py +0 -0
  205. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/aws/util/__init__.py +0 -0
  206. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/aws/util/common.py +0 -0
  207. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/azure/__init__.py +0 -0
  208. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/azure/compute.py +0 -0
  209. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/azure/cosmosdb.py +0 -0
  210. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/azure/sql.py +0 -0
  211. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/azure/storage.py +0 -0
  212. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/azure/subscription.py +0 -0
  213. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/azure/tenant.py +0 -0
  214. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/azure/util/__init__.py +0 -0
  215. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/create_indexes.py +0 -0
  216. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/crowdstrike/__init__.py +0 -0
  217. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/crowdstrike/endpoints.py +0 -0
  218. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/crowdstrike/spotlight.py +0 -0
  219. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/crowdstrike/util.py +0 -0
  220. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/crxcavator/__init__.py +0 -0
  221. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/crxcavator/crxcavator.py +0 -0
  222. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/cve/__init__.py +0 -0
  223. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/cve/feed.py +0 -0
  224. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/digitalocean/__init__.py +0 -0
  225. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/digitalocean/compute.py +0 -0
  226. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/digitalocean/management.py +0 -0
  227. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/digitalocean/platform.py +0 -0
  228. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/dns.py +0 -0
  229. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/gcp/__init__.py +0 -0
  230. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/gcp/compute.py +0 -0
  231. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/gcp/crm.py +0 -0
  232. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/gcp/dns.py +0 -0
  233. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/gcp/gke.py +0 -0
  234. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/gcp/storage.py +0 -0
  235. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/github/__init__.py +0 -0
  236. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/github/repos.py +0 -0
  237. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/github/users.py +0 -0
  238. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/github/util.py +0 -0
  239. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/gsuite/__init__.py +0 -0
  240. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/gsuite/api.py +0 -0
  241. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/jamf/__init__.py +0 -0
  242. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/jamf/computers.py +0 -0
  243. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/jamf/util.py +0 -0
  244. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/kubernetes/__init__.py +0 -0
  245. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/kubernetes/namespaces.py +0 -0
  246. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/kubernetes/pods.py +0 -0
  247. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/kubernetes/secrets.py +0 -0
  248. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/kubernetes/services.py +0 -0
  249. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/kubernetes/util.py +0 -0
  250. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/oci/__init__.py +0 -0
  251. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/oci/organizations.py +0 -0
  252. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/oci/utils.py +0 -0
  253. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/okta/__init__.py +0 -0
  254. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/okta/applications.py +0 -0
  255. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/okta/awssaml.py +0 -0
  256. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/okta/factors.py +0 -0
  257. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/okta/groups.py +0 -0
  258. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/okta/organization.py +0 -0
  259. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/okta/origins.py +0 -0
  260. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/okta/roles.py +0 -0
  261. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/okta/sync_state.py +0 -0
  262. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/okta/users.py +0 -0
  263. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/okta/utils.py +0 -0
  264. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/pagerduty/__init__.py +0 -0
  265. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/pagerduty/escalation_policies.py +0 -0
  266. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/pagerduty/schedules.py +0 -0
  267. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/pagerduty/services.py +0 -0
  268. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/pagerduty/teams.py +0 -0
  269. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/pagerduty/users.py +0 -0
  270. {cartography-0.73.1 → cartography-0.75.0}/cartography/intel/pagerduty/vendors.py +0 -0
  271. {cartography-0.73.1 → cartography-0.75.0}/cartography/models/__init__.py +0 -0
  272. {cartography-0.73.1 → cartography-0.75.0}/cartography/models/aws/__init__.py +0 -0
  273. {cartography-0.73.1 → cartography-0.75.0}/cartography/models/core/__init__.py +0 -0
  274. {cartography-0.73.1 → cartography-0.75.0}/cartography/models/core/nodes.py +0 -0
  275. {cartography-0.73.1 → cartography-0.75.0}/cartography/models/core/relationships.py +0 -0
  276. {cartography-0.73.1 → cartography-0.75.0}/cartography/py.typed +0 -0
  277. {cartography-0.73.1 → cartography-0.75.0}/cartography/stats.py +0 -0
  278. {cartography-0.73.1 → cartography-0.75.0}/cartography/sync.py +0 -0
  279. {cartography-0.73.1 → cartography-0.75.0}/cartography/util.py +0 -0
  280. {cartography-0.73.1 → cartography-0.75.0}/cartography.egg-info/SOURCES.txt +0 -0
  281. {cartography-0.73.1 → cartography-0.75.0}/cartography.egg-info/dependency_links.txt +0 -0
  282. {cartography-0.73.1 → cartography-0.75.0}/cartography.egg-info/entry_points.txt +0 -0
  283. {cartography-0.73.1 → cartography-0.75.0}/cartography.egg-info/requires.txt +0 -0
  284. {cartography-0.73.1 → cartography-0.75.0}/cartography.egg-info/top_level.txt +0 -0
  285. {cartography-0.73.1 → cartography-0.75.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cartography
3
- Version: 0.73.1
3
+ Version: 0.75.0
4
4
  Summary: Explore assets and their relationships across your technical infrastructure.
5
5
  Home-page: https://www.github.com/lyft/cartography
6
6
  Maintainer: Lyft
@@ -7,6 +7,9 @@ from typing import Union
7
7
 
8
8
  import neo4j
9
9
 
10
+ from cartography.graph.querybuilder import build_create_index_queries
11
+ from cartography.graph.querybuilder import build_ingestion_query
12
+ from cartography.models.core.nodes import CartographyNodeSchema
10
13
  from cartography.util import batch
11
14
 
12
15
 
@@ -210,3 +213,42 @@ def load_graph_data(
210
213
  DictList=data_batch,
211
214
  **kwargs,
212
215
  )
216
+
217
+
218
+ def ensure_indexes(neo4j_session: neo4j.Session, node_schema: CartographyNodeSchema) -> None:
219
+ """
220
+ Creates indexes if they don't exist for the given CartographyNodeSchema object, as well as for all of the
221
+ relationships defined on its `other_relationships` and `sub_resource_relationship` fields. This operation is
222
+ idempotent.
223
+
224
+ This ensures that every time we need to MATCH on a node to draw a relationship to it, the field used for the MATCH
225
+ will be indexed, making the operation fast.
226
+ :param neo4j_session: The neo4j session
227
+ :param node_schema: The node_schema object to create indexes for.
228
+ """
229
+ queries = build_create_index_queries(node_schema)
230
+
231
+ for query in queries:
232
+ if not query.startswith('CREATE INDEX IF NOT EXISTS'):
233
+ raise ValueError('Query provided to `ensure_indexes()` does not start with "CREATE INDEX IF NOT EXISTS".')
234
+ neo4j_session.run(query)
235
+
236
+
237
+ def load(
238
+ neo4j_session: neo4j.Session,
239
+ node_schema: CartographyNodeSchema,
240
+ dict_list: List[Dict[str, Any]],
241
+ **kwargs,
242
+ ) -> None:
243
+ """
244
+ Main entrypoint for intel modules to write data to the graph. Ensures that indexes exist for the datatypes loaded
245
+ to the graph and then performs the load operation.
246
+ :param neo4j_session: The Neo4j session
247
+ :param node_schema: The CartographyNodeSchema object to create indexes for and generate a query.
248
+ :param dict_list: The data to load to the graph represented as a list of dicts.
249
+ :param kwargs: Allows additional keyword args to be supplied to the Neo4j query.
250
+ :return: None
251
+ """
252
+ ensure_indexes(neo4j_session, node_schema)
253
+ ingestion_query = build_ingestion_query(node_schema)
254
+ load_graph_data(neo4j_session, ingestion_query, dict_list, **kwargs)
@@ -140,6 +140,7 @@ CREATE INDEX IF NOT EXISTS FOR (n:ECSContainerInstance) ON (n.lastupdated);
140
140
  CREATE INDEX IF NOT EXISTS FOR (n:ECSService) ON (n.id);
141
141
  CREATE INDEX IF NOT EXISTS FOR (n:ECSService) ON (n.lastupdated);
142
142
  CREATE INDEX IF NOT EXISTS FOR (n:ECSTaskDefinition) ON (n.id);
143
+ CREATE INDEX IF NOT EXISTS FOR (n:ECSTaskDefinition) ON (n.arn);
143
144
  CREATE INDEX IF NOT EXISTS FOR (n:ECSTaskDefinition) ON (n.lastupdated);
144
145
  CREATE INDEX IF NOT EXISTS FOR (n:ECSTask) ON (n.id);
145
146
  CREATE INDEX IF NOT EXISTS FOR (n:ECSTask) ON (n.lastupdated);
@@ -158,9 +159,6 @@ CREATE INDEX IF NOT EXISTS FOR (n:ELBListener) ON (n.id);
158
159
  CREATE INDEX IF NOT EXISTS FOR (n:ELBListener) ON (n.lastupdated);
159
160
  CREATE INDEX IF NOT EXISTS FOR (n:ELBV2Listener) ON (n.id);
160
161
  CREATE INDEX IF NOT EXISTS FOR (n:ELBV2Listener) ON (n.lastupdated);
161
- CREATE INDEX IF NOT EXISTS FOR (n:EMRCluster) ON (n.id);
162
- CREATE INDEX IF NOT EXISTS FOR (n:EMRCluster) ON (n.arn);
163
- CREATE INDEX IF NOT EXISTS FOR (n:EMRCluster) ON (n.lastupdated);
164
162
  CREATE INDEX IF NOT EXISTS FOR (n:Endpoint) ON (n.id);
165
163
  CREATE INDEX IF NOT EXISTS FOR (n:Endpoint) ON (n.lastupdated);
166
164
  CREATE INDEX IF NOT EXISTS FOR (n:ESDomain) ON (n.arn);
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "statements": [
3
3
  {
4
- "query": "MATCH (n) where EXISTS(n.exposed_internet) AND labels(n) IN ['AutoScalingGroup', 'EC2Instance', 'LoadBalancer', 'LoadBalancerV2'] WITH n LIMIT $LIMIT_SIZE REMOVE n.exposed_internet, n.exposed_internet_type return COUNT(*) as TotalCompleted",
4
+ "query": "MATCH (n) where n.exposed_internet IS NOT NULL AND labels(n) IN ['AutoScalingGroup', 'EC2Instance', 'LoadBalancer', 'LoadBalancerV2'] WITH n LIMIT $LIMIT_SIZE REMOVE n.exposed_internet, n.exposed_internet_type return COUNT(*) as TotalCompleted",
5
5
  "iterative": true,
6
6
  "iterationsize": 1000
7
7
  },
8
8
  {
9
- "query": "MATCH (:IpRange{id: '0.0.0.0/0'})-[:MEMBER_OF_IP_RULE]->(:IpPermissionInbound)-[:MEMBER_OF_EC2_SECURITY_GROUP]->(group:EC2SecurityGroup)<-[:MEMBER_OF_EC2_SECURITY_GROUP|NETWORK_INTERFACE*..2]-(instance:EC2Instance)\nWITH instance\nWHERE (EXISTS(instance.publicipaddress)) AND (NOT EXISTS(instance.exposed_internet_type)) OR (NOT 'direct' IN instance.exposed_internet_type)\nSET instance.exposed_internet = true, instance.exposed_internet_type = coalesce(instance.exposed_internet_type , []) + 'direct';",
9
+ "query": "MATCH (:IpRange{id: '0.0.0.0/0'})-[:MEMBER_OF_IP_RULE]->(:IpPermissionInbound)-[:MEMBER_OF_EC2_SECURITY_GROUP]->(group:EC2SecurityGroup)<-[:MEMBER_OF_EC2_SECURITY_GROUP|NETWORK_INTERFACE*..2]-(instance:EC2Instance)\nWITH instance\nWHERE (instance.publicipaddress IS NOT NULL) AND (instance.exposed_internet_type IS NULL) OR (NOT 'direct' IN instance.exposed_internet_type)\nSET instance.exposed_internet = true, instance.exposed_internet_type = coalesce(instance.exposed_internet_type , []) + 'direct';",
10
10
  "iterative": false
11
11
  },
12
12
  {
@@ -18,15 +18,15 @@
18
18
  "iterative": false
19
19
  },
20
20
  {
21
- "query": "MATCH (elb:LoadBalancer{exposed_internet: true})-[:EXPOSE]->(e:EC2Instance)\nWITH e\nWHERE (NOT EXISTS(e.exposed_internet_type)) OR (NOT 'elb' IN e.exposed_internet_type)\nSET e.exposed_internet = true, e.exposed_internet_type = coalesce(e.exposed_internet_type, []) + 'elb'",
21
+ "query": "MATCH (elb:LoadBalancer{exposed_internet: true})-[:EXPOSE]->(e:EC2Instance)\nWITH e\nWHERE (e.exposed_internet_type IS NULL) OR (NOT 'elb' IN e.exposed_internet_type)\nSET e.exposed_internet = true, e.exposed_internet_type = coalesce(e.exposed_internet_type, []) + 'elb'",
22
22
  "iterative": false
23
23
  },
24
24
  {
25
- "query": "MATCH (elbv2:LoadBalancerV2{exposed_internet: true})-[:EXPOSE]->(e:EC2Instance)\nWITH e\nWHERE (NOT EXISTS(e.exposed_internet_type)) OR (NOT 'elbv2' IN e.exposed_internet_type)\nSET e.exposed_internet = true, e.exposed_internet_type = coalesce(e.exposed_internet_type, []) + 'elbv2'",
25
+ "query": "MATCH (elbv2:LoadBalancerV2{exposed_internet: true})-[:EXPOSE]->(e:EC2Instance)\nWITH e\nWHERE (e.exposed_internet_type IS NULL) OR (NOT 'elbv2' IN e.exposed_internet_type)\nSET e.exposed_internet = true, e.exposed_internet_type = coalesce(e.exposed_internet_type, []) + 'elbv2'",
26
26
  "iterative": false
27
27
  },
28
28
  {
29
- "query": "MATCH (instance:EC2Instance{exposed_internet: true})-[:MEMBER_AUTO_SCALE_GROUP]->(asg:AutoScalingGroup)\nWITH distinct instance.exposed_internet_type as types, asg\nUNWIND types as type\nWITH type, asg\nWHERE NOT EXISTS(asg.exposed_internet_type) OR (NOT type IN asg.exposed_internet_type)\nSET asg.exposed_internet = true, asg.exposed_internet_type = coalesce(asg.exposed_internet_type, []) + type;",
29
+ "query": "MATCH (instance:EC2Instance{exposed_internet: true})-[:MEMBER_AUTO_SCALE_GROUP]->(asg:AutoScalingGroup)\nWITH distinct instance.exposed_internet_type as types, asg\nUNWIND types as type\nWITH type, asg\nWHERE asg.exposed_internet_type IS NULL OR (NOT type IN asg.exposed_internet_type)\nSET asg.exposed_internet = true, asg.exposed_internet_type = coalesce(asg.exposed_internet_type, []) + type;",
30
30
  "iterative": false
31
31
  }
32
32
  ],
@@ -3,12 +3,12 @@
3
3
  "statements": [
4
4
  {
5
5
  "__comment__": "Delete the attribute user_uploaded",
6
- "query": "MATCH (k:EC2KeyPair) WHERE EXISTS (k.user_uploaded) REMOVE k.user_uploaded return COUNT(*) as TotalCompleted",
6
+ "query": "MATCH (k:EC2KeyPair) WHERE k.user_uploaded IS NOT NULL REMOVE k.user_uploaded return COUNT(*) as TotalCompleted",
7
7
  "iterative": false
8
8
  },
9
9
  {
10
10
  "__comment__": "Delete the attribute duplicate_keyfingerprint",
11
- "query": "MATCH (k:EC2KeyPair) WHERE EXISTS (k.duplicate_keyfingerprint) REMOVE k.duplicate_keyfingerprint return COUNT(*) as TotalCompleted",
11
+ "query": "MATCH (k:EC2KeyPair) WHERE k.duplicate_keyfingerprint IS NOT NULL REMOVE k.duplicate_keyfingerprint return COUNT(*) as TotalCompleted",
12
12
  "iterative": false
13
13
  },
14
14
  {
@@ -2,7 +2,7 @@
2
2
  "statements": [
3
3
  {
4
4
  "__comment": "This is a clean-up statement to remove custom attributes",
5
- "query": "MATCH (cluster:EKSCluster) WHERE EXISTS(cluster.exposed_internet) REMOVE cluster.exposed_internet return COUNT(*) as TotalCompleted",
5
+ "query": "MATCH (cluster:EKSCluster) WHERE cluster.exposed_internet IS NOT NULL REMOVE cluster.exposed_internet return COUNT(*) as TotalCompleted",
6
6
  "iterative": false
7
7
  },
8
8
  {
@@ -2,12 +2,12 @@
2
2
  "statements": [
3
3
  {
4
4
  "__comment": "This analyze AWS accounts we created and tag the ones that are foreign. Foreign accounts are ones that were not in the sync scope",
5
- "query": "MATCH (foreign:AWSAccount) where NOT EXISTS(foreign.inscope) SET foreign.foreign = true",
5
+ "query": "MATCH (foreign:AWSAccount) where foreign.inscope IS NULL SET foreign.foreign = true",
6
6
  "iterative": false
7
7
  },
8
8
  {
9
9
  "__comment": "Remove accounts that were set with foreign and inscope. This can happen as we finish the list of sync accounts through assume role mapping and vpc peering",
10
- "query": "MATCH (a:AWSAccount) where EXISTS(a.inscope) AND EXISTS(a.foreign) REMOVE a.foreign",
10
+ "query": "MATCH (a:AWSAccount) where a.inscope IS NOT NULL AND a.foreign IS NOT NULL REMOVE a.foreign",
11
11
  "iterative": false
12
12
  }
13
13
  ],
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "statements": [
3
3
  {
4
- "query": "MATCH (n) where EXISTS(n.exposed_internet) AND labels(n) IN ['GCPInstance'] WITH n LIMIT $LIMIT_SIZE REMOVE n.exposed_internet, n.exposed_internet_type return COUNT(*) as TotalCompleted",
4
+ "query": "MATCH (n) where n.exposed_internet IS NOT NULL AND labels(n) IN ['GCPInstance'] WITH n LIMIT $LIMIT_SIZE REMOVE n.exposed_internet, n.exposed_internet_type return COUNT(*) as TotalCompleted",
5
5
  "iterative": true,
6
6
  "iterationsize": 1000,
7
7
  "__comment__": "Delete exposed_internet off nodes so we can start fresh"
@@ -22,17 +22,17 @@
22
22
  "__comment__": "Delete stale firewall ingress relationships"
23
23
  },
24
24
  {
25
- "query": "MATCH (ac:GCPNicAccessConfig)<-[:RESOURCE]-(:GCPNetworkInterface)<-[:NETWORK_INTERFACE]-(n:GCPInstance)<-[:FIREWALL_INGRESS]-(firewall_a:GCPFirewall)<-[:ALLOWED_BY]-(allow_rule:GCPIpRule{protocol:'tcp'})<-[:MEMBER_OF_IP_RULE]-(:IpRange{id:\"0.0.0.0/0\"})\nOPTIONAL MATCH (n)<-[:FIREWALL_INGRESS]-(firewall_b:GCPFirewall)<-[:DENIED_BY]-(deny_rule:GCPIpRule{protocol:'tcp'})\nWHERE exists(ac.public_ip) and (\n\tdeny_rule is NULL\n\tOR firewall_b.priority > firewall_a.priority\n\tOR NOT allow_rule.fromport IN RANGE(deny_rule.fromport, deny_rule.toport)\n\tOR NOT allow_rule.toport IN RANGE(deny_rule.fromport, deny_rule.toport)\n)\nSET n.exposed_internet = True, n.exposed_internet_type='direct'\nRETURN count(*) as TotalCompleted",
25
+ "query": "MATCH (ac:GCPNicAccessConfig)<-[:RESOURCE]-(:GCPNetworkInterface)<-[:NETWORK_INTERFACE]-(n:GCPInstance)<-[:FIREWALL_INGRESS]-(firewall_a:GCPFirewall)<-[:ALLOWED_BY]-(allow_rule:GCPIpRule{protocol:'tcp'})<-[:MEMBER_OF_IP_RULE]-(:IpRange{id:\"0.0.0.0/0\"})\nOPTIONAL MATCH (n)<-[:FIREWALL_INGRESS]-(firewall_b:GCPFirewall)<-[:DENIED_BY]-(deny_rule:GCPIpRule{protocol:'tcp'})\nWHERE ac.public_ip IS NOT NULL and (\n\tdeny_rule is NULL\n\tOR firewall_b.priority > firewall_a.priority\n\tOR NOT allow_rule.fromport IN RANGE(deny_rule.fromport, deny_rule.toport)\n\tOR NOT allow_rule.toport IN RANGE(deny_rule.fromport, deny_rule.toport)\n)\nSET n.exposed_internet = True, n.exposed_internet_type='direct'\nRETURN count(*) as TotalCompleted",
26
26
  "iterative": false,
27
27
  "__comment__": "Mark a GCP instance with exposed_internet = True and exposed_internet_type = 'direct' if its attached firewalls and TCP rules expose it to the internet."
28
28
  },
29
29
  {
30
- "query": "MATCH (ac:GCPNicAccessConfig)<-[:RESOURCE]-(:GCPNetworkInterface)<-[:NETWORK_INTERFACE]-(n:GCPInstance)<-[:FIREWALL_INGRESS]-(firewall_a:GCPFirewall)<-[:ALLOWED_BY]-(allow_rule:GCPIpRule{protocol:'udp'})<-[:MEMBER_OF_IP_RULE]-(:IpRange{id:\"0.0.0.0/0\"})\nOPTIONAL MATCH (n)<-[:FIREWALL_INGRESS]-(firewall_b:GCPFirewall)<-[:DENIED_BY]-(deny_rule:GCPIpRule{protocol:'udp'})\nWHERE exists(ac.public_ip) and (\n\tdeny_rule is NULL\n\tOR firewall_b.priority > firewall_a.priority\n\tOR NOT allow_rule.fromport IN RANGE(deny_rule.fromport, deny_rule.toport)\n\tOR NOT allow_rule.toport IN RANGE(deny_rule.fromport, deny_rule.toport)\n)\nSET n.exposed_internet = True, n.exposed_internet_type='direct'\nRETURN count(*) as TotalCompleted",
30
+ "query": "MATCH (ac:GCPNicAccessConfig)<-[:RESOURCE]-(:GCPNetworkInterface)<-[:NETWORK_INTERFACE]-(n:GCPInstance)<-[:FIREWALL_INGRESS]-(firewall_a:GCPFirewall)<-[:ALLOWED_BY]-(allow_rule:GCPIpRule{protocol:'udp'})<-[:MEMBER_OF_IP_RULE]-(:IpRange{id:\"0.0.0.0/0\"})\nOPTIONAL MATCH (n)<-[:FIREWALL_INGRESS]-(firewall_b:GCPFirewall)<-[:DENIED_BY]-(deny_rule:GCPIpRule{protocol:'udp'})\nWHERE ac.public_ip IS NOT NULL and (\n\tdeny_rule is NULL\n\tOR firewall_b.priority > firewall_a.priority\n\tOR NOT allow_rule.fromport IN RANGE(deny_rule.fromport, deny_rule.toport)\n\tOR NOT allow_rule.toport IN RANGE(deny_rule.fromport, deny_rule.toport)\n)\nSET n.exposed_internet = True, n.exposed_internet_type='direct'\nRETURN count(*) as TotalCompleted",
31
31
  "iterative": false,
32
32
  "__comment__": "Mark a GCP instance with exposed_internet = True and exposed_internet_type = 'direct' if its attached firewalls and UDP rules expose it to the internet."
33
33
  },
34
34
  {
35
- "query": "MATCH (ac:GCPNicAccessConfig)<-[:RESOURCE]-(:GCPNetworkInterface)<-[:NETWORK_INTERFACE]-(n:GCPInstance)<-[:FIREWALL_INGRESS]-(firewall_a:GCPFirewall)<-[:ALLOWED_BY]-(allow_rule:GCPIpRule{protocol:'all'})<-[:MEMBER_OF_IP_RULE]-(:IpRange{id:\"0.0.0.0/0\"})\nOPTIONAL MATCH (n)<-[:FIREWALL_INGRESS]-(firewall_b:GCPFirewall)<-[:DENIED_BY]-(deny_rule:GCPIpRule{protocol:'all'})\nWHERE exists(ac.public_ip) and exists(allow_rule.fromport) and exists(allow_rule.toport) and (\n\tdeny_rule is NULL\n\tOR firewall_b.priority > firewall_a.priority\n\tOR NOT allow_rule.fromport IN RANGE(deny_rule.fromport, deny_rule.toport)\n\tOR NOT allow_rule.toport IN RANGE(deny_rule.fromport, deny_rule.toport)\n)\nSET n.exposed_internet = True, n.exposed_internet_type='direct'\nRETURN count(*) as TotalCompleted",
35
+ "query": "MATCH (ac:GCPNicAccessConfig)<-[:RESOURCE]-(:GCPNetworkInterface)<-[:NETWORK_INTERFACE]-(n:GCPInstance)<-[:FIREWALL_INGRESS]-(firewall_a:GCPFirewall)<-[:ALLOWED_BY]-(allow_rule:GCPIpRule{protocol:'all'})<-[:MEMBER_OF_IP_RULE]-(:IpRange{id:\"0.0.0.0/0\"})\nOPTIONAL MATCH (n)<-[:FIREWALL_INGRESS]-(firewall_b:GCPFirewall)<-[:DENIED_BY]-(deny_rule:GCPIpRule{protocol:'all'})\nWHERE ac.public_ip IS NOT NULL and allow_rule.fromport IS NOT NULL and allow_rule.toport IS NOT NULL and (\n\tdeny_rule is NULL\n\tOR firewall_b.priority > firewall_a.priority\n\tOR NOT allow_rule.fromport IN RANGE(deny_rule.fromport, deny_rule.toport)\n\tOR NOT allow_rule.toport IN RANGE(deny_rule.fromport, deny_rule.toport)\n)\nSET n.exposed_internet = True, n.exposed_internet_type='direct'\nRETURN count(*) as TotalCompleted",
36
36
  "iterative": false,
37
37
  "__comment__": "Mark a GCP instance with exposed_internet = True and exposed_internet_type = 'direct' if its attached firewalls and ALL rules expose it to the internet."
38
38
  }
@@ -2,7 +2,7 @@
2
2
  "statements": [
3
3
  {
4
4
  "__comment": "This is a clean-up statement to remove custom attributes",
5
- "query": "MATCH (cluster:GKECluster) WHERE EXISTS(cluster.exposed_internet) REMOVE cluster.exposed_internet return COUNT(*) as TotalCompleted",
5
+ "query": "MATCH (cluster:GKECluster) WHERE cluster.exposed_internet IS NOT NULL REMOVE cluster.exposed_internet return COUNT(*) as TotalCompleted",
6
6
  "iterative": false
7
7
  },
8
8
  {
@@ -0,0 +1,15 @@
1
+ {
2
+ "statements": [
3
+ {
4
+ "__comment": "This is a clean-up statement to remove custom attributes",
5
+ "query": "MATCH (cluster:GKECluster) WHERE cluster.basic_auth IS NOT NULL REMOVE cluster.basic_auth return COUNT(*) as TotalCompleted",
6
+ "iterative": false
7
+ },
8
+ {
9
+ "__comment": "This sets the basic_auth attribute",
10
+ "query": "MATCH (cluster:GKECluster) WHERE (cluster.masterauth_username IS NOT NULL AND NOT cluster.masterauth_username = '') AND (cluster.masterauth_password IS NOT NULL AND NOT cluster.masterauth.password = '') SET cluster.basic_auth = true",
11
+ "iterative": false
12
+ }
13
+ ],
14
+ "name": "GCP GKE basic authentication exposure"
15
+ }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "statements": [
3
3
  {
4
- "query": "MATCH (:AWSAccount{id: $AWS_ID})-[:RESOURCE]->(s:RestAPI) WHERE EXISTS(s.anonymous_access)\n WITH s LIMIT $LIMIT_SIZE\nREMOVE s.anonymous_access, s.anonymous_actions",
4
+ "query": "MATCH (:AWSAccount{id: $AWS_ID})-[:RESOURCE]->(s:RestAPI) WHERE s.anonymous_access IS NOT NULL\n WITH s LIMIT $LIMIT_SIZE\nREMOVE s.anonymous_access, s.anonymous_actions",
5
5
  "iterative": true,
6
6
  "iterationsize": 100
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "statements": [
3
3
  {
4
- "query": "MATCH (:AWSAccount{id: $AWS_ID})-[:RESOURCE]->(s:KMSKey) WHERE EXISTS(s.anonymous_access)\n WITH s LIMIT $LIMIT_SIZE\nREMOVE s.anonymous_access, s.anonymous_actions",
4
+ "query": "MATCH (:AWSAccount{id: $AWS_ID})-[:RESOURCE]->(s:KMSKey) WHERE s.anonymous_access IS NOT NULL\n WITH s LIMIT $LIMIT_SIZE\nREMOVE s.anonymous_access, s.anonymous_actions",
5
5
  "iterative": true,
6
6
  "iterationsize": 100
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "statements": [
3
3
  {
4
- "query": "MATCH (:AWSAccount{id: $AWS_ID})-[:RESOURCE]->(s:S3Bucket) WHERE EXISTS(s.anonymous_access)\n WITH s LIMIT $LIMIT_SIZE\nREMOVE s.anonymous_access, s.anonymous_actions",
4
+ "query": "MATCH (:AWSAccount{id: $AWS_ID})-[:RESOURCE]->(s:S3Bucket) WHERE s.anonymous_access IS NOT NULL\n WITH s LIMIT $LIMIT_SIZE\nREMOVE s.anonymous_access, s.anonymous_actions",
5
5
  "iterative": true,
6
6
  "iterationsize": 100
7
7
  }
@@ -1,11 +1,8 @@
1
1
  from dataclasses import asdict
2
2
  from string import Template
3
3
  from typing import List
4
- from typing import Optional
5
- from typing import Set
6
4
 
7
5
  from cartography.graph.querybuilder import _build_match_clause
8
- from cartography.graph.querybuilder import filter_selected_relationships
9
6
  from cartography.graph.querybuilder import rel_present_on_node_schema
10
7
  from cartography.models.core.nodes import CartographyNodeSchema
11
8
  from cartography.models.core.relationships import CartographyRelSchema
@@ -13,49 +10,32 @@ from cartography.models.core.relationships import LinkDirection
13
10
  from cartography.models.core.relationships import TargetNodeMatcher
14
11
 
15
12
 
16
- def build_cleanup_queries(
17
- node_schema: CartographyNodeSchema,
18
- selected_rels: Optional[Set[CartographyRelSchema]] = None,
19
- ) -> List[str]:
13
+ def build_cleanup_queries(node_schema: CartographyNodeSchema) -> List[str]:
20
14
  """
21
15
  Generates queries to clean up stale nodes and relationships from the given CartographyNodeSchema.
22
- :param node_schema: The given CartographyNodeSchema to generate cleanup queries for.
23
- :param selected_rels: Optional. If specified, only generate cleanup queries where the `node_schema` is bound to this
24
- given set of selected relationships. Raises an exception if any of the rels in `selected_rels` aren't actually
25
- defined on the `node_schema`.
26
- If `selected_rels` is not specified (default), we generate cleanup queries against all relationships defined on the
27
- `node_schema`.
28
- :return: A list of Neo4j queries to clean up nodes and relationships. Order matters: we always clean up the sub
29
- resource relationship last because we only clean up stale nodes and rels that are associated with a given sub
30
- resource, so if we delete the sub resource first then we will not be able to reach the stale nodes and rels, thus
31
- leaving orphaned objects behind.
32
- Note also that we return the empty list if the node_schema has no relationships. Doing cleanups of nodes without
33
- relationships can be resource expensive for a large graph, and you might risk deleting unintended objects. Please
34
- write a manual cleanup job if you wish to do this.
16
+ Note that auto-cleanups for a node with no relationships is not currently supported.
17
+ Algorithm:
18
+ 1. First delete all stale nodes attached to the node_schema's sub resource
19
+ 2. Delete all stale node to sub resource relationships
20
+ - We don't expect this to be very common (never for AWS resources, at least), but in case it is possible for an
21
+ asset to change sub resources, we want to handle it properly.
22
+ 3. For all relationships defined on the node schema, delete all stale ones.
23
+ :param node_schema: The given CartographyNodeSchema
24
+ :return: A list of Neo4j queries to clean up nodes and relationships.
35
25
  """
36
- other_rels = node_schema.other_relationships
37
- sub_resource_rel = node_schema.sub_resource_relationship
38
-
39
- if selected_rels:
40
- # Ensure that the selected rels actually exist on the node_schema
41
- sub_resource_rel, other_rels = filter_selected_relationships(node_schema, selected_rels)
42
-
43
- if not sub_resource_rel:
26
+ if not node_schema.sub_resource_relationship:
44
27
  raise ValueError(
45
28
  "Auto-creating a cleanup job for a node_schema without a sub resource relationship is not supported. "
46
- f'Please check the class definition of "{node_schema.__class__.__name__}". If the optional `selected_rels` '
47
- 'param was specified to build_cleanup_queries(), then ensure that the sub resource relationship is '
48
- 'present.',
29
+ f'Please check the class definition of "{node_schema.__class__.__name__}".',
49
30
  )
50
31
 
51
- result = []
52
- if other_rels:
53
- for rel in other_rels.rels:
54
- result.extend(_build_cleanup_node_and_rel_queries(node_schema, rel))
32
+ result = _build_cleanup_node_and_rel_queries(node_schema, node_schema.sub_resource_relationship)
33
+ if node_schema.other_relationships:
34
+ for rel in node_schema.other_relationships.rels:
35
+ # [0] is the delete node query, [1] is the delete relationship query. We only want the latter.
36
+ _, rel_query = _build_cleanup_node_and_rel_queries(node_schema, rel)
37
+ result.append(rel_query)
55
38
 
56
- # Make sure that the sub resource cleanup job is last in the list; order matters.
57
- result.extend(_build_cleanup_node_and_rel_queries(node_schema, sub_resource_rel))
58
- # Note that auto-cleanups for a node with no relationships does not happen at all - we don't support it.
59
39
  return result
60
40
 
61
41
 
@@ -16,7 +16,6 @@ from cartography.graph.cleanupbuilder import build_cleanup_queries
16
16
  from cartography.graph.statement import get_job_shortname
17
17
  from cartography.graph.statement import GraphStatement
18
18
  from cartography.models.core.nodes import CartographyNodeSchema
19
- from cartography.models.core.relationships import CartographyRelSchema
20
19
 
21
20
  logger = logging.getLogger(__name__)
22
21
 
@@ -129,14 +128,13 @@ class GraphJob:
129
128
  cls,
130
129
  node_schema: CartographyNodeSchema,
131
130
  parameters: Dict[str, Any],
132
- selected_rels: Optional[Set[CartographyRelSchema]] = None,
133
131
  ) -> 'GraphJob':
134
132
  """
135
133
  Create a cleanup job from a CartographyNodeSchema object.
136
134
  For a given node, the fields used in the node_schema.sub_resource_relationship.target_node_node_matcher.keys()
137
135
  must be provided as keys and values in the params dict.
138
136
  """
139
- queries: List[str] = build_cleanup_queries(node_schema, selected_rels)
137
+ queries: List[str] = build_cleanup_queries(node_schema)
140
138
 
141
139
  expected_param_keys: Set[str] = get_parameters(queries)
142
140
  actual_param_keys: Set[str] = set(parameters.keys())
@@ -2,6 +2,7 @@ import logging
2
2
  from dataclasses import asdict
3
3
  from string import Template
4
4
  from typing import Dict
5
+ from typing import List
5
6
  from typing import Optional
6
7
  from typing import Set
7
8
  from typing import Tuple
@@ -108,6 +109,28 @@ def _build_match_clause(matcher: TargetNodeMatcher) -> str:
108
109
  return ', '.join(match.safe_substitute(Key=key, PropRef=prop_ref) for key, prop_ref in matcher_asdict.items())
109
110
 
110
111
 
112
+ def _build_where_clause_for_rel_match(node_var: str, matcher: TargetNodeMatcher) -> str:
113
+ """
114
+ Same as _build_match_clause, but puts the matching logic in a WHERE clause.
115
+ This is intended specifically to use for joining with relationships where we need a case-insensitive match.
116
+ :param matcher: A TargetNodeMatcher object
117
+ :return: a Neo4j where clause
118
+ """
119
+ match = Template("$node_var.$key = $prop_ref")
120
+ case_insensitive_match = Template("toLower($node_var.$key) = toLower($prop_ref)")
121
+
122
+ matcher_asdict = asdict(matcher)
123
+
124
+ result = []
125
+ for key, prop_ref in matcher_asdict.items():
126
+ if prop_ref.ignore_case:
127
+ prop_line = case_insensitive_match.safe_substitute(node_var=node_var, key=key, prop_ref=prop_ref)
128
+ else:
129
+ prop_line = match.safe_substitute(node_var=node_var, key=key, prop_ref=prop_ref)
130
+ result.append(prop_line)
131
+ return ' AND\n'.join(result)
132
+
133
+
111
134
  def _asdict_with_validate_relprops(link: CartographyRelSchema) -> Dict[str, PropertyRef]:
112
135
  """
113
136
  Give a helpful error message when forgetting to put `()` when instantiating a CartographyRelSchema, as this
@@ -145,6 +168,7 @@ def _build_attach_sub_resource_statement(sub_resource_link: Optional[Cartography
145
168
 
146
169
  sub_resource_attach_template = Template(
147
170
  """
171
+ WITH i, item
148
172
  OPTIONAL MATCH (j:$SubResourceLabel{$MatchClause})
149
173
  WITH i, item, j WHERE j IS NOT NULL
150
174
  $RelMergeClause
@@ -191,7 +215,9 @@ def _build_attach_additional_links_statement(
191
215
  additional_links_template = Template(
192
216
  """
193
217
  WITH i, item
194
- OPTIONAL MATCH ($node_var:$AddlLabel{$MatchClause})
218
+ OPTIONAL MATCH ($node_var:$AddlLabel)
219
+ WHERE
220
+ $WhereClause
195
221
  WITH i, item, $node_var WHERE $node_var IS NOT NULL
196
222
  $RelMerge
197
223
  ON CREATE SET $rel_var.firstseen = timestamp()
@@ -219,7 +245,7 @@ def _build_attach_additional_links_statement(
219
245
 
220
246
  additional_ref = additional_links_template.safe_substitute(
221
247
  AddlLabel=link.target_node_label,
222
- MatchClause=_build_match_clause(link.target_node_matcher),
248
+ WhereClause=_build_where_clause_for_rel_match(node_var, link.target_node_matcher),
223
249
  node_var=node_var,
224
250
  rel_var=rel_var,
225
251
  RelMerge=rel_merge,
@@ -258,7 +284,6 @@ def _build_attach_relationships_statement(
258
284
  """
259
285
  WITH i, item
260
286
  CALL {
261
- WITH i, item
262
287
  $attach_relationships_statement
263
288
  }
264
289
  """,
@@ -374,3 +399,55 @@ def build_ingestion_query(
374
399
  attach_relationships_statement=_build_attach_relationships_statement(sub_resource_rel, other_rels),
375
400
  )
376
401
  return ingest_query
402
+
403
+
404
+ def build_create_index_queries(node_schema: CartographyNodeSchema) -> List[str]:
405
+ """
406
+ Generate queries to create indexes for the given CartographyNodeSchema and all node types attached to it via its
407
+ relationships.
408
+ :param node_schema: The Cartography node_schema object
409
+ :return: A list of queries of the form `CREATE INDEX IF NOT EXISTS FOR (n:$TargetNodeLabel) ON (n.$TargetAttribute)`
410
+ """
411
+ index_template = Template('CREATE INDEX IF NOT EXISTS FOR (n:$TargetNodeLabel) ON (n.$TargetAttribute);')
412
+
413
+ # First ensure an index exists for the node_schema and all extra labels on the `id` and `lastupdated` fields
414
+ result = [
415
+ index_template.safe_substitute(
416
+ TargetNodeLabel=node_schema.label,
417
+ TargetAttribute='id',
418
+ ),
419
+ index_template.safe_substitute(
420
+ TargetNodeLabel=node_schema.label,
421
+ TargetAttribute='lastupdated',
422
+ ),
423
+ ]
424
+ if node_schema.extra_node_labels:
425
+ result.extend([
426
+ index_template.safe_substitute(
427
+ TargetNodeLabel=label,
428
+ TargetAttribute='id', # Precondition: 'id' is defined on all cartography node_schema objects.
429
+ ) for label in node_schema.extra_node_labels.labels
430
+ ])
431
+
432
+ # Next, for all relationships possible out of this node, ensure that indexes exist for all target nodes' properties
433
+ # as specified in their TargetNodeMatchers.
434
+ rel_schemas = []
435
+ if node_schema.sub_resource_relationship:
436
+ rel_schemas.extend([node_schema.sub_resource_relationship])
437
+ if node_schema.other_relationships:
438
+ rel_schemas.extend(node_schema.other_relationships.rels)
439
+ for rs in rel_schemas:
440
+ for target_key in asdict(rs.target_node_matcher).keys():
441
+ result.append(
442
+ index_template.safe_substitute(TargetNodeLabel=rs.target_node_label, TargetAttribute=target_key),
443
+ )
444
+
445
+ # Now, include extra indexes defined by the module author on the node schema's property refs.
446
+ node_props_as_dict: Dict[str, PropertyRef] = asdict(node_schema.properties)
447
+ result.extend([
448
+ index_template.safe_substitute(
449
+ TargetNodeLabel=node_schema.label,
450
+ TargetAttribute=prop_name,
451
+ ) for prop_name, prop_ref in node_props_as_dict.items() if prop_ref.extra_index
452
+ ])
453
+ return result
@@ -4,6 +4,7 @@ import os
4
4
  from pathlib import Path
5
5
  from typing import Any
6
6
  from typing import Dict
7
+ from typing import Optional
7
8
  from typing import Union
8
9
 
9
10
  import neo4j
@@ -40,8 +41,13 @@ class GraphStatement:
40
41
  """
41
42
 
42
43
  def __init__(
43
- self, query: str, parameters: Dict = None, iterative: bool = False, iterationsize: int = 0,
44
- parent_job_name: str = None, parent_job_sequence_num: int = None,
44
+ self,
45
+ query: str,
46
+ parameters: Optional[Dict[Any, Any]] = None,
47
+ iterative: bool = False,
48
+ iterationsize: int = 0,
49
+ parent_job_name: Optional[str] = None,
50
+ parent_job_sequence_num: Optional[int] = None,
45
51
  ):
46
52
  self.query = query
47
53
  self.parameters = parameters or {}
@@ -122,7 +128,12 @@ class GraphStatement:
122
128
  result.consume()
123
129
 
124
130
  @classmethod
125
- def create_from_json(cls, json_obj: Dict, short_job_name: str = None, job_sequence_num: int = None):
131
+ def create_from_json(
132
+ cls,
133
+ json_obj: Dict[str, Any],
134
+ short_job_name: Optional[str] = None,
135
+ job_sequence_num: Optional[int] = None,
136
+ ):
126
137
  """
127
138
  Create a statement from a JSON blob.
128
139
  """
@@ -171,7 +171,7 @@ def _load_apigateway_policies(
171
171
  def _set_default_values(neo4j_session: neo4j.Session, aws_account_id: str) -> None:
172
172
  set_defaults = """
173
173
  MATCH (:AWSAccount{id: $AWS_ID})-[:RESOURCE]->(restApi:APIGatewayRestAPI)
174
- where NOT EXISTS(restApi.anonymous_actions)
174
+ where restApi.anonymous_actions IS NULL
175
175
  SET restApi.anonymous_access = false, restApi.anonymous_actions = []
176
176
  """
177
177
 
@@ -91,16 +91,16 @@ def get_ecs_services(cluster_arn: str, boto3_session: boto3.session.Session, reg
91
91
 
92
92
  @timeit
93
93
  @aws_handle_regions
94
- def get_ecs_task_definitions(boto3_session: boto3.session.Session, region: str) -> List[Dict[str, Any]]:
94
+ def get_ecs_task_definitions(
95
+ boto3_session: boto3.session.Session,
96
+ region: str,
97
+ tasks: List[Dict[str, Any]],
98
+ ) -> List[Dict[str, Any]]:
95
99
  client = boto3_session.client('ecs', region_name=region)
96
- paginator = client.get_paginator('list_task_definitions')
97
100
  task_definitions: List[Dict[str, Any]] = []
98
- task_definition_arns: List[str] = []
99
- for page in paginator.paginate():
100
- task_definition_arns.extend(page.get('taskDefinitionArns', []))
101
- for arn in task_definition_arns:
101
+ for task in tasks:
102
102
  task_definition = client.describe_task_definition(
103
- taskDefinition=arn,
103
+ taskDefinition=task['taskDefinitionArn'],
104
104
  )
105
105
  task_definitions.append(task_definition['taskDefinition'])
106
106
  return task_definitions
@@ -294,7 +294,8 @@ def load_ecs_task_definitions(
294
294
  UNWIND $Definitions AS def
295
295
  MERGE (d:ECSTaskDefinition{id: def.taskDefinitionArn})
296
296
  ON CREATE SET d.firstseen = timestamp()
297
- SET d.arn = def.taskDefinitionArn, d.region = $Region,
297
+ SET d.arn = def.taskDefinitionArn,
298
+ d.region = $Region,
298
299
  d.family = def.family,
299
300
  d.task_role_arn = def.taskRoleArn,
300
301
  d.execution_role_arn = def.executionRoleArn,
@@ -317,6 +318,11 @@ def load_ecs_task_definitions(
317
318
  d.ephemeral_storage_size_in_gib = def.ephemeralStorage.sizeInGiB,
318
319
  d.lastupdated = $aws_update_tag
319
320
  WITH d
321
+ MATCH (task:ECSTask{task_definition_arn: d.arn})
322
+ MERGE (task)-[r:HAS_TASK_DEFINITION]->(d)
323
+ ON CREATE SET r.firstseen = timestamp()
324
+ SET r.lastupdated = $aws_update_tag
325
+ WITH d
320
326
  MATCH (owner:AWSAccount{id: $AWS_ACCOUNT_ID})
321
327
  MERGE (owner)-[r:RESOURCE]->(d)
322
328
  ON CREATE SET r.firstseen = timestamp()
@@ -565,17 +571,6 @@ def sync(
565
571
  current_aws_account_id,
566
572
  update_tag,
567
573
  )
568
- task_definitions = get_ecs_task_definitions(
569
- boto3_session,
570
- region,
571
- )
572
- load_ecs_task_definitions(
573
- neo4j_session,
574
- task_definitions,
575
- region,
576
- current_aws_account_id,
577
- update_tag,
578
- )
579
574
  services = get_ecs_services(
580
575
  cluster_arn,
581
576
  boto3_session,
@@ -602,4 +597,16 @@ def sync(
602
597
  current_aws_account_id,
603
598
  update_tag,
604
599
  )
600
+ task_definitions = get_ecs_task_definitions(
601
+ boto3_session,
602
+ region,
603
+ tasks,
604
+ )
605
+ load_ecs_task_definitions(
606
+ neo4j_session,
607
+ task_definitions,
608
+ region,
609
+ current_aws_account_id,
610
+ update_tag,
611
+ )
605
612
  cleanup_ecs(neo4j_session, common_job_parameters)