cartography 0.111.0rc1__py3-none-any.whl → 0.112.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 (68) hide show
  1. cartography/_version.py +2 -2
  2. cartography/cli.py +57 -0
  3. cartography/config.py +24 -0
  4. cartography/data/indexes.cypher +0 -2
  5. cartography/data/jobs/analysis/keycloak_inheritance.json +30 -0
  6. cartography/intel/aws/apigateway.py +128 -17
  7. cartography/intel/aws/ec2/instances.py +3 -1
  8. cartography/intel/aws/ec2/network_interfaces.py +1 -1
  9. cartography/intel/aws/ec2/vpc_peerings.py +262 -125
  10. cartography/intel/azure/__init__.py +35 -32
  11. cartography/intel/azure/subscription.py +2 -2
  12. cartography/intel/azure/tenant.py +39 -30
  13. cartography/intel/azure/util/credentials.py +49 -174
  14. cartography/intel/entra/__init__.py +47 -1
  15. cartography/intel/entra/applications.py +220 -170
  16. cartography/intel/entra/groups.py +41 -22
  17. cartography/intel/entra/ou.py +28 -20
  18. cartography/intel/entra/users.py +24 -18
  19. cartography/intel/gcp/__init__.py +25 -8
  20. cartography/intel/gcp/compute.py +47 -12
  21. cartography/intel/github/repos.py +19 -10
  22. cartography/intel/github/util.py +12 -0
  23. cartography/intel/keycloak/__init__.py +153 -0
  24. cartography/intel/keycloak/authenticationexecutions.py +322 -0
  25. cartography/intel/keycloak/authenticationflows.py +77 -0
  26. cartography/intel/keycloak/clients.py +187 -0
  27. cartography/intel/keycloak/groups.py +126 -0
  28. cartography/intel/keycloak/identityproviders.py +94 -0
  29. cartography/intel/keycloak/organizations.py +163 -0
  30. cartography/intel/keycloak/realms.py +61 -0
  31. cartography/intel/keycloak/roles.py +202 -0
  32. cartography/intel/keycloak/scopes.py +73 -0
  33. cartography/intel/keycloak/users.py +70 -0
  34. cartography/intel/keycloak/util.py +47 -0
  35. cartography/intel/kubernetes/__init__.py +26 -0
  36. cartography/intel/kubernetes/eks.py +402 -0
  37. cartography/intel/kubernetes/rbac.py +133 -0
  38. cartography/models/aws/apigateway/apigatewayintegration.py +79 -0
  39. cartography/models/aws/apigateway/apigatewaymethod.py +74 -0
  40. cartography/models/aws/ec2/vpc_peering.py +157 -0
  41. cartography/models/azure/principal.py +44 -0
  42. cartography/models/azure/tenant.py +20 -0
  43. cartography/models/keycloak/__init__.py +0 -0
  44. cartography/models/keycloak/authenticationexecution.py +160 -0
  45. cartography/models/keycloak/authenticationflow.py +54 -0
  46. cartography/models/keycloak/client.py +177 -0
  47. cartography/models/keycloak/group.py +101 -0
  48. cartography/models/keycloak/identityprovider.py +89 -0
  49. cartography/models/keycloak/organization.py +116 -0
  50. cartography/models/keycloak/organizationdomain.py +73 -0
  51. cartography/models/keycloak/realm.py +173 -0
  52. cartography/models/keycloak/role.py +126 -0
  53. cartography/models/keycloak/scope.py +73 -0
  54. cartography/models/keycloak/user.py +51 -0
  55. cartography/models/kubernetes/clusterrolebindings.py +40 -0
  56. cartography/models/kubernetes/groups.py +107 -0
  57. cartography/models/kubernetes/oidc.py +51 -0
  58. cartography/models/kubernetes/rolebindings.py +40 -0
  59. cartography/models/kubernetes/users.py +105 -0
  60. cartography/sync.py +2 -0
  61. cartography/util.py +10 -0
  62. {cartography-0.111.0rc1.dist-info → cartography-0.112.0.dist-info}/METADATA +9 -5
  63. {cartography-0.111.0rc1.dist-info → cartography-0.112.0.dist-info}/RECORD +67 -34
  64. cartography/data/jobs/cleanup/aws_import_vpc_peering_cleanup.json +0 -45
  65. {cartography-0.111.0rc1.dist-info → cartography-0.112.0.dist-info}/WHEEL +0 -0
  66. {cartography-0.111.0rc1.dist-info → cartography-0.112.0.dist-info}/entry_points.txt +0 -0
  67. {cartography-0.111.0rc1.dist-info → cartography-0.112.0.dist-info}/licenses/LICENSE +0 -0
  68. {cartography-0.111.0rc1.dist-info → cartography-0.112.0.dist-info}/top_level.txt +0 -0
@@ -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 APIGatewayIntegrationNodeProperties(CartographyNodeProperties):
16
+ id: PropertyRef = PropertyRef("id")
17
+ httpmethod: PropertyRef = PropertyRef("httpMethod")
18
+ integration_http_method: PropertyRef = PropertyRef("integrationHttpMethod")
19
+ resource_id: PropertyRef = PropertyRef("resourceId")
20
+ api_id: PropertyRef = PropertyRef("apiId")
21
+ type: PropertyRef = PropertyRef("type")
22
+ uri: PropertyRef = PropertyRef("uri")
23
+ connection_type: PropertyRef = PropertyRef("connectionType")
24
+ connection_id: PropertyRef = PropertyRef("connectionId")
25
+ credentials: PropertyRef = PropertyRef("credentials")
26
+ lastupdated: PropertyRef = PropertyRef("lastupdated", set_in_kwargs=True)
27
+
28
+
29
+ @dataclass(frozen=True)
30
+ class APIGatewayIntegrationToAPIGatewayResourceRelRelProperties(
31
+ CartographyRelProperties
32
+ ):
33
+ lastupdated: PropertyRef = PropertyRef("lastupdated", set_in_kwargs=True)
34
+
35
+
36
+ @dataclass(frozen=True)
37
+ class APIGatewayIntegrationToAPIGatewayResourceRel(CartographyRelSchema):
38
+ target_node_label: str = "APIGatewayResource"
39
+ target_node_matcher: TargetNodeMatcher = make_target_node_matcher(
40
+ {"id": PropertyRef("resourceId")},
41
+ )
42
+ direction: LinkDirection = LinkDirection.INWARD
43
+ rel_label: str = "HAS_INTEGRATION"
44
+ properties: APIGatewayIntegrationToAPIGatewayResourceRelRelProperties = (
45
+ APIGatewayIntegrationToAPIGatewayResourceRelRelProperties()
46
+ )
47
+
48
+
49
+ @dataclass(frozen=True)
50
+ class APIGatewayIntegrationToAWSAccountRelRelProperties(CartographyRelProperties):
51
+ lastupdated: PropertyRef = PropertyRef("lastupdated", set_in_kwargs=True)
52
+
53
+
54
+ @dataclass(frozen=True)
55
+ # (:APIGatewayIntegration)<-[:RESOURCE]-(:AWSAccount)
56
+ class APIGatewayIntegrationToAWSAccountRel(CartographyRelSchema):
57
+ target_node_label: str = "AWSAccount"
58
+ target_node_matcher: TargetNodeMatcher = make_target_node_matcher(
59
+ {"id": PropertyRef("AWS_ID", set_in_kwargs=True)},
60
+ )
61
+ direction: LinkDirection = LinkDirection.INWARD
62
+ rel_label: str = "RESOURCE"
63
+ properties: APIGatewayIntegrationToAWSAccountRelRelProperties = (
64
+ APIGatewayIntegrationToAWSAccountRelRelProperties()
65
+ )
66
+
67
+
68
+ @dataclass(frozen=True)
69
+ class APIGatewayIntegrationSchema(CartographyNodeSchema):
70
+ label: str = "APIGatewayIntegration"
71
+ properties: APIGatewayIntegrationNodeProperties = (
72
+ APIGatewayIntegrationNodeProperties()
73
+ )
74
+ sub_resource_relationship: APIGatewayIntegrationToAWSAccountRel = (
75
+ APIGatewayIntegrationToAWSAccountRel()
76
+ )
77
+ other_relationships: OtherRelationships = OtherRelationships(
78
+ [APIGatewayIntegrationToAPIGatewayResourceRel()],
79
+ )
@@ -0,0 +1,74 @@
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 APIGatewayMethodNodeProperties(CartographyNodeProperties):
16
+ id: PropertyRef = PropertyRef("id")
17
+ httpmethod: PropertyRef = PropertyRef("httpMethod")
18
+ resource_id: PropertyRef = PropertyRef("resourceId")
19
+ api_id: PropertyRef = PropertyRef("apiId")
20
+ authorization_type: PropertyRef = PropertyRef("authorizationType")
21
+ authorizer_id: PropertyRef = PropertyRef("authorizerId")
22
+ request_validator_id: PropertyRef = PropertyRef("requestValidatorId")
23
+ operation_name: PropertyRef = PropertyRef("operationName")
24
+ api_key_required: PropertyRef = PropertyRef("apiKeyRequired")
25
+ lastupdated: PropertyRef = PropertyRef("lastupdated", set_in_kwargs=True)
26
+
27
+
28
+ @dataclass(frozen=True)
29
+ class APIGatewayMethodToAPIGatewayResourceRelRelProperties(CartographyRelProperties):
30
+ lastupdated: PropertyRef = PropertyRef("lastupdated", set_in_kwargs=True)
31
+
32
+
33
+ @dataclass(frozen=True)
34
+ class APIGatewayMethodToAPIGatewayResourceRel(CartographyRelSchema):
35
+ target_node_label: str = "APIGatewayResource"
36
+ target_node_matcher: TargetNodeMatcher = make_target_node_matcher(
37
+ {"id": PropertyRef("resourceId")},
38
+ )
39
+ direction: LinkDirection = LinkDirection.INWARD
40
+ rel_label: str = "HAS_METHOD"
41
+ properties: APIGatewayMethodToAPIGatewayResourceRelRelProperties = (
42
+ APIGatewayMethodToAPIGatewayResourceRelRelProperties()
43
+ )
44
+
45
+
46
+ @dataclass(frozen=True)
47
+ class APIGatewayMethodToAWSAccountRelRelProperties(CartographyRelProperties):
48
+ lastupdated: PropertyRef = PropertyRef("lastupdated", set_in_kwargs=True)
49
+
50
+
51
+ @dataclass(frozen=True)
52
+ # (:APIGatewayMethod)<-[:RESOURCE]-(:AWSAccount)
53
+ class APIGatewayMethodToAWSAccountRel(CartographyRelSchema):
54
+ target_node_label: str = "AWSAccount"
55
+ target_node_matcher: TargetNodeMatcher = make_target_node_matcher(
56
+ {"id": PropertyRef("AWS_ID", set_in_kwargs=True)},
57
+ )
58
+ direction: LinkDirection = LinkDirection.INWARD
59
+ rel_label: str = "RESOURCE"
60
+ properties: APIGatewayMethodToAWSAccountRelRelProperties = (
61
+ APIGatewayMethodToAWSAccountRelRelProperties()
62
+ )
63
+
64
+
65
+ @dataclass(frozen=True)
66
+ class APIGatewayMethodSchema(CartographyNodeSchema):
67
+ label: str = "APIGatewayMethod"
68
+ properties: APIGatewayMethodNodeProperties = APIGatewayMethodNodeProperties()
69
+ sub_resource_relationship: APIGatewayMethodToAWSAccountRel = (
70
+ APIGatewayMethodToAWSAccountRel()
71
+ )
72
+ other_relationships: OtherRelationships = OtherRelationships(
73
+ [APIGatewayMethodToAPIGatewayResourceRel()],
74
+ )
@@ -0,0 +1,157 @@
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 VPCPeeringNodeProperties(CartographyNodeProperties):
16
+ id: PropertyRef = PropertyRef("VpcPeeringConnectionId")
17
+ allow_dns_resolution_from_remote_vpc: PropertyRef = PropertyRef(
18
+ "AllowDnsResolutionFromRemoteVpc",
19
+ )
20
+ allow_egress_from_local_classic_link_to_remote_vpc: PropertyRef = PropertyRef(
21
+ "AllowEgressFromLocalClassicLinkToRemoteVpc",
22
+ )
23
+ allow_egress_from_local_vpc_to_remote_classic_link: PropertyRef = PropertyRef(
24
+ "AllowEgressFromLocalVpcToRemoteClassicLink",
25
+ )
26
+ requester_region: PropertyRef = PropertyRef("RequesterRegion")
27
+ accepter_region: PropertyRef = PropertyRef("AccepterRegion")
28
+ status_code: PropertyRef = PropertyRef("StatusCode")
29
+ status_message: PropertyRef = PropertyRef("StatusMessage")
30
+ lastupdated: PropertyRef = PropertyRef("lastupdated", set_in_kwargs=True)
31
+
32
+
33
+ @dataclass(frozen=True)
34
+ class PeeringToAccepterVpcRelProperties(CartographyRelProperties):
35
+ lastupdated: PropertyRef = PropertyRef("lastupdated", set_in_kwargs=True)
36
+
37
+
38
+ @dataclass(frozen=True)
39
+ class PeeringToAccepterVpcRel(CartographyRelSchema):
40
+ target_node_label: str = "AWSVpc"
41
+ target_node_matcher: TargetNodeMatcher = make_target_node_matcher(
42
+ {"id": PropertyRef("AccepterVpcId")},
43
+ )
44
+ direction: LinkDirection = LinkDirection.OUTWARD
45
+ rel_label: str = "ACCEPTER_VPC"
46
+ properties: PeeringToAccepterVpcRelProperties = PeeringToAccepterVpcRelProperties()
47
+
48
+
49
+ @dataclass(frozen=True)
50
+ class PeeringToRequesterVpcRelProperties(CartographyRelProperties):
51
+ lastupdated: PropertyRef = PropertyRef("lastupdated", set_in_kwargs=True)
52
+
53
+
54
+ @dataclass(frozen=True)
55
+ class PeeringToRequesterVpcRel(CartographyRelSchema):
56
+ target_node_label: str = "AWSVpc"
57
+ target_node_matcher: TargetNodeMatcher = make_target_node_matcher(
58
+ {"id": PropertyRef("RequesterVpcId")},
59
+ )
60
+ direction: LinkDirection = LinkDirection.OUTWARD
61
+ rel_label: str = "REQUESTER_VPC"
62
+ properties: PeeringToRequesterVpcRelProperties = (
63
+ PeeringToRequesterVpcRelProperties()
64
+ )
65
+
66
+
67
+ @dataclass(frozen=True)
68
+ class PeeringToAccepterCidrRelProperties(CartographyRelProperties):
69
+ lastupdated: PropertyRef = PropertyRef("lastupdated", set_in_kwargs=True)
70
+
71
+
72
+ @dataclass(frozen=True)
73
+ class PeeringToAccepterCidrRel(CartographyRelSchema):
74
+ target_node_label: str = "AWSCidrBlock"
75
+ target_node_matcher: TargetNodeMatcher = make_target_node_matcher(
76
+ {"id": PropertyRef("ACCEPTER_CIDR_BLOCK_IDS", one_to_many=True)},
77
+ )
78
+ direction: LinkDirection = LinkDirection.OUTWARD
79
+ rel_label: str = "ACCEPTER_CIDR"
80
+ properties: PeeringToAccepterCidrRelProperties = (
81
+ PeeringToAccepterCidrRelProperties()
82
+ )
83
+
84
+
85
+ @dataclass(frozen=True)
86
+ class PeeringToRequesterCidrRelProperties(CartographyRelProperties):
87
+ lastupdated: PropertyRef = PropertyRef("lastupdated", set_in_kwargs=True)
88
+
89
+
90
+ @dataclass(frozen=True)
91
+ class PeeringToRequesterCidrRel(CartographyRelSchema):
92
+ target_node_label: str = "AWSCidrBlock"
93
+ target_node_matcher: TargetNodeMatcher = make_target_node_matcher(
94
+ {"id": PropertyRef("REQUESTER_CIDR_BLOCK_IDS", one_to_many=True)},
95
+ )
96
+ direction: LinkDirection = LinkDirection.OUTWARD
97
+ rel_label: str = "REQUESTER_CIDR"
98
+ properties: PeeringToRequesterCidrRelProperties = (
99
+ PeeringToRequesterCidrRelProperties()
100
+ )
101
+
102
+
103
+ @dataclass(frozen=True)
104
+ class PeeringConnectionToAWSAccountRelProperties(CartographyRelProperties):
105
+ lastupdated: PropertyRef = PropertyRef("lastupdated", set_in_kwargs=True)
106
+
107
+
108
+ @dataclass(frozen=True)
109
+ class PeeringConnectionToAWSAccountRel(CartographyRelSchema):
110
+ target_node_label: str = "AWSAccount"
111
+ target_node_matcher: TargetNodeMatcher = make_target_node_matcher(
112
+ {"id": PropertyRef("AWS_ID", set_in_kwargs=True)}
113
+ )
114
+ direction: LinkDirection = LinkDirection.INWARD
115
+ rel_label: str = "RESOURCE"
116
+ properties: PeeringConnectionToAWSAccountRelProperties = (
117
+ PeeringConnectionToAWSAccountRelProperties()
118
+ )
119
+
120
+
121
+ # Composite Node Pattern: AWSAccount as known by VPC Peering
122
+ @dataclass(frozen=True)
123
+ class AWSAccountVPCPeeringNodeProperties(CartographyNodeProperties):
124
+ id: PropertyRef = PropertyRef("id")
125
+ lastupdated: PropertyRef = PropertyRef("lastupdated", set_in_kwargs=True)
126
+
127
+
128
+ @dataclass(frozen=True)
129
+ class AWSAccountVPCPeeringSchema(CartographyNodeSchema):
130
+ """
131
+ Composite schema to represent AWS Accounts as known by VPC Peering.
132
+ Targets the same 'AWSAccount' label as the primary AWS account schema,
133
+ allowing MERGE operations to combine properties from both sources.
134
+ """
135
+
136
+ label: str = "AWSAccount" # Same label as primary AWSAccount schema
137
+ properties: AWSAccountVPCPeeringNodeProperties = (
138
+ AWSAccountVPCPeeringNodeProperties()
139
+ )
140
+ # No sub_resource_relationship - accounts are top-level entities
141
+
142
+
143
+ @dataclass(frozen=True)
144
+ class AWSPeeringConnectionSchema(CartographyNodeSchema):
145
+ label: str = "AWSPeeringConnection"
146
+ properties: VPCPeeringNodeProperties = VPCPeeringNodeProperties()
147
+ sub_resource_relationship: PeeringConnectionToAWSAccountRel = (
148
+ PeeringConnectionToAWSAccountRel()
149
+ )
150
+ other_relationships: OtherRelationships = OtherRelationships(
151
+ [
152
+ PeeringToAccepterVpcRel(),
153
+ PeeringToRequesterVpcRel(),
154
+ PeeringToAccepterCidrRel(),
155
+ PeeringToRequesterCidrRel(),
156
+ ],
157
+ )
@@ -0,0 +1,44 @@
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 AzurePrincipalProperties(CartographyNodeProperties):
18
+ id: PropertyRef = PropertyRef("id")
19
+ lastupdated: PropertyRef = PropertyRef("lastupdated", set_in_kwargs=True)
20
+
21
+
22
+ @dataclass(frozen=True)
23
+ class AzurePrincipalToTenantRelProperties(CartographyRelProperties):
24
+ lastupdated: PropertyRef = PropertyRef("lastupdated", set_in_kwargs=True)
25
+
26
+
27
+ @dataclass(frozen=True)
28
+ class AzurePrincipalToTenantRel(CartographyRelSchema):
29
+ target_node_label: str = "AzureTenant"
30
+ target_node_matcher: TargetNodeMatcher = make_target_node_matcher(
31
+ {"id": PropertyRef("TENANT_ID", set_in_kwargs=True)},
32
+ )
33
+ direction: LinkDirection = LinkDirection.INWARD
34
+ rel_label: str = "RESOURCE"
35
+ properties: AzurePrincipalToTenantRelProperties = (
36
+ AzurePrincipalToTenantRelProperties()
37
+ )
38
+
39
+
40
+ @dataclass(frozen=True)
41
+ class AzurePrincipalSchema(CartographyNodeSchema):
42
+ label: str = "AzurePrincipal"
43
+ properties: AzurePrincipalProperties = AzurePrincipalProperties()
44
+ sub_resource_relationship: AzurePrincipalToTenantRel = AzurePrincipalToTenantRel()
@@ -0,0 +1,20 @@
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
+
8
+ logger = logging.getLogger(__name__)
9
+
10
+
11
+ @dataclass(frozen=True)
12
+ class AzureTenantProperties(CartographyNodeProperties):
13
+ id: PropertyRef = PropertyRef("id")
14
+ lastupdated: PropertyRef = PropertyRef("lastupdated", set_in_kwargs=True)
15
+
16
+
17
+ @dataclass(frozen=True)
18
+ class AzureTenantSchema(CartographyNodeSchema):
19
+ label: str = "AzureTenant"
20
+ properties: AzureTenantProperties = AzureTenantProperties()
File without changes
@@ -0,0 +1,160 @@
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_source_node_matcher
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 SourceNodeMatcher
13
+ from cartography.models.core.relationships import TargetNodeMatcher
14
+
15
+
16
+ @dataclass(frozen=True)
17
+ class KeycloakAuthenticationExecutionNodeProperties(CartographyNodeProperties):
18
+ id: PropertyRef = PropertyRef("id")
19
+ display_name: PropertyRef = PropertyRef("displayName")
20
+ requirement: PropertyRef = PropertyRef("requirement")
21
+ description: PropertyRef = PropertyRef("description")
22
+ configurable: PropertyRef = PropertyRef("configurable")
23
+ authentication_flow: PropertyRef = PropertyRef("authenticationFlow")
24
+ provider_id: PropertyRef = PropertyRef("providerId")
25
+ flow_id: PropertyRef = PropertyRef("flowId")
26
+ level: PropertyRef = PropertyRef("level")
27
+ index: PropertyRef = PropertyRef("index")
28
+ priority: PropertyRef = PropertyRef("priority")
29
+ is_terminal_step: PropertyRef = PropertyRef("is_terminal_step")
30
+ lastupdated: PropertyRef = PropertyRef("LASTUPDATED", set_in_kwargs=True)
31
+
32
+
33
+ @dataclass(frozen=True)
34
+ class KeycloakAuthenticationExecutionToRealmRelProperties(CartographyRelProperties):
35
+ lastupdated: PropertyRef = PropertyRef("LASTUPDATED", set_in_kwargs=True)
36
+
37
+
38
+ @dataclass(frozen=True)
39
+ # (:KeycloakAuthenticationExecution)<-[:RESOURCE]-(:KeycloakRealm)
40
+ class KeycloakAuthenticationExecutionToRealmRel(CartographyRelSchema):
41
+ target_node_label: str = "KeycloakRealm"
42
+ target_node_matcher: TargetNodeMatcher = make_target_node_matcher(
43
+ {"name": PropertyRef("REALM", set_in_kwargs=True)},
44
+ )
45
+ direction: LinkDirection = LinkDirection.INWARD
46
+ rel_label: str = "RESOURCE"
47
+ properties: KeycloakAuthenticationExecutionToRealmRelProperties = (
48
+ KeycloakAuthenticationExecutionToRealmRelProperties()
49
+ )
50
+
51
+
52
+ @dataclass(frozen=True)
53
+ class ExecutionToFlowRelProperties(CartographyRelProperties):
54
+ lastupdated: PropertyRef = PropertyRef("LASTUPDATED", set_in_kwargs=True)
55
+
56
+
57
+ @dataclass(frozen=True)
58
+ # (:KeycloakAuthenticationExecution)<-[:HAS_STEP]-(:KeycloakAuthenticationFlow)
59
+ class ExecutionToFlowRel(CartographyRelSchema):
60
+ target_node_label: str = "KeycloakAuthenticationFlow"
61
+ target_node_matcher: TargetNodeMatcher = make_target_node_matcher(
62
+ {
63
+ "alias": PropertyRef("_parent_flow"),
64
+ "realm": PropertyRef("REALM", set_in_kwargs=True),
65
+ },
66
+ )
67
+ direction: LinkDirection = LinkDirection.INWARD
68
+ rel_label: str = "HAS_STEP"
69
+ properties: ExecutionToFlowRelProperties = ExecutionToFlowRelProperties()
70
+
71
+
72
+ @dataclass(frozen=True)
73
+ class ExecutionToExecutionRelProperties(CartographyRelProperties):
74
+ lastupdated: PropertyRef = PropertyRef("LASTUPDATED", set_in_kwargs=True)
75
+
76
+
77
+ @dataclass(frozen=True)
78
+ # (:KeycloakAuthenticationExecution)<-[:HAS_STEP]-(:KeycloakAuthenticationExecution)
79
+ class ExecutionToExecutionRel(CartographyRelSchema):
80
+ target_node_label: str = "KeycloakAuthenticationExecution"
81
+ target_node_matcher: TargetNodeMatcher = make_target_node_matcher(
82
+ {"id": PropertyRef("_parent_subflow")},
83
+ )
84
+ direction: LinkDirection = LinkDirection.INWARD
85
+ rel_label: str = "HAS_STEP"
86
+ properties: ExecutionToExecutionRelProperties = ExecutionToExecutionRelProperties()
87
+
88
+
89
+ @dataclass(frozen=True)
90
+ class KeycloakAuthenticationExecutionSchema(CartographyNodeSchema):
91
+ label: str = "KeycloakAuthenticationExecution"
92
+ properties: KeycloakAuthenticationExecutionNodeProperties = (
93
+ KeycloakAuthenticationExecutionNodeProperties()
94
+ )
95
+ sub_resource_relationship: KeycloakAuthenticationExecutionToRealmRel = (
96
+ KeycloakAuthenticationExecutionToRealmRel()
97
+ )
98
+ other_relationships: OtherRelationships = OtherRelationships(
99
+ [ExecutionToFlowRel(), ExecutionToExecutionRel()]
100
+ )
101
+
102
+
103
+ # The following relationships are MatchLinks, they are used to modelize all the possible flows
104
+ @dataclass(frozen=True)
105
+ class ExecutionToExecutionStepRelProperties(CartographyRelProperties):
106
+ lastupdated: PropertyRef = PropertyRef("LASTUPDATED", set_in_kwargs=True)
107
+ # Mandatory fields for MatchLinks
108
+ _sub_resource_label: PropertyRef = PropertyRef(
109
+ "_sub_resource_label", set_in_kwargs=True
110
+ )
111
+ _sub_resource_id: PropertyRef = PropertyRef("_sub_resource_id", set_in_kwargs=True)
112
+
113
+
114
+ @dataclass(frozen=True)
115
+ # (:KeycloakAuthenticationExecution)-[:NEXT_STEP]->(:KeycloakAuthenticationExecution)
116
+ class ExecutionToExecutionMatchLink(CartographyRelSchema):
117
+ source_node_label: str = "KeycloakAuthenticationExecution"
118
+ source_node_matcher: SourceNodeMatcher = make_source_node_matcher(
119
+ {"id": PropertyRef("source")},
120
+ )
121
+ target_node_label: str = "KeycloakAuthenticationExecution"
122
+ target_node_matcher: TargetNodeMatcher = make_target_node_matcher(
123
+ {"id": PropertyRef("target")},
124
+ )
125
+ direction: LinkDirection = LinkDirection.OUTWARD
126
+ rel_label: str = "NEXT_STEP"
127
+ properties: ExecutionToExecutionStepRelProperties = (
128
+ ExecutionToExecutionStepRelProperties()
129
+ )
130
+
131
+
132
+ @dataclass(frozen=True)
133
+ class ExecutionToFlowStepRelProperties(CartographyRelProperties):
134
+ lastupdated: PropertyRef = PropertyRef("LASTUPDATED", set_in_kwargs=True)
135
+ # Mandatory fields for MatchLinks
136
+ _sub_resource_label: PropertyRef = PropertyRef(
137
+ "_sub_resource_label", set_in_kwargs=True
138
+ )
139
+ _sub_resource_id: PropertyRef = PropertyRef("_sub_resource_id", set_in_kwargs=True)
140
+
141
+
142
+ @dataclass(frozen=True)
143
+ # (:KeycloakAuthenticationFlow)-[:NEXT_STEP]->(:KeycloakAuthenticationExecution)
144
+ class ExecutionToFlowMatchLink(CartographyRelSchema):
145
+ source_node_label: str = "KeycloakAuthenticationExecution"
146
+ source_node_matcher: SourceNodeMatcher = make_source_node_matcher(
147
+ {"id": PropertyRef("execution_id")},
148
+ )
149
+ target_node_label: str = "KeycloakAuthenticationFlow"
150
+ target_node_matcher: TargetNodeMatcher = make_target_node_matcher(
151
+ {
152
+ "alias": PropertyRef("flow_name"),
153
+ "realm": PropertyRef(
154
+ "realm"
155
+ ), # We need to pass the realm to match the flow correctly as aliases can be shared across realms
156
+ },
157
+ )
158
+ direction: LinkDirection = LinkDirection.INWARD
159
+ rel_label: str = "NEXT_STEP"
160
+ properties: ExecutionToFlowStepRelProperties = ExecutionToFlowStepRelProperties()
@@ -0,0 +1,54 @@
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 KeycloakAuthenticationFlowNodeProperties(CartographyNodeProperties):
15
+ id: PropertyRef = PropertyRef("id")
16
+ alias: PropertyRef = PropertyRef("alias", extra_index=True)
17
+ description: PropertyRef = PropertyRef("description")
18
+ provider_id: PropertyRef = PropertyRef("providerId")
19
+ top_level: PropertyRef = PropertyRef("topLevel")
20
+ built_in: PropertyRef = PropertyRef("builtIn")
21
+ lastupdated: PropertyRef = PropertyRef("LASTUPDATED", set_in_kwargs=True)
22
+ # We need to store the realm name because authentication flows are often referenced by name
23
+ # and not by id, so we need to be able to find the authentication flows by name (that is not unique across realms)
24
+ realm: PropertyRef = PropertyRef("REALM", set_in_kwargs=True, extra_index=True)
25
+
26
+
27
+ @dataclass(frozen=True)
28
+ class KeycloakAuthenticationFlowToRealmRelProperties(CartographyRelProperties):
29
+ lastupdated: PropertyRef = PropertyRef("LASTUPDATED", set_in_kwargs=True)
30
+
31
+
32
+ @dataclass(frozen=True)
33
+ # (:KeycloakAuthenticationFlow)<-[:RESOURCE]-(:KeycloakRealm)
34
+ class KeycloakAuthenticationFlowToRealmRel(CartographyRelSchema):
35
+ target_node_label: str = "KeycloakRealm"
36
+ target_node_matcher: TargetNodeMatcher = make_target_node_matcher(
37
+ {"name": PropertyRef("REALM", set_in_kwargs=True)},
38
+ )
39
+ direction: LinkDirection = LinkDirection.INWARD
40
+ rel_label: str = "RESOURCE"
41
+ properties: KeycloakAuthenticationFlowToRealmRelProperties = (
42
+ KeycloakAuthenticationFlowToRealmRelProperties()
43
+ )
44
+
45
+
46
+ @dataclass(frozen=True)
47
+ class KeycloakAuthenticationFlowSchema(CartographyNodeSchema):
48
+ label: str = "KeycloakAuthenticationFlow"
49
+ properties: KeycloakAuthenticationFlowNodeProperties = (
50
+ KeycloakAuthenticationFlowNodeProperties()
51
+ )
52
+ sub_resource_relationship: KeycloakAuthenticationFlowToRealmRel = (
53
+ KeycloakAuthenticationFlowToRealmRel()
54
+ )