Skip to content

Commit 553e433

Browse files
committed
Add route to igw support + tests
Signed-off-by: Alex Chantavy <alex@subimage.io>
1 parent 3e5596d commit 553e433

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

cartography/models/aws/ec2/routes.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,27 @@ class RouteToAWSAccount(CartographyRelSchema):
5050
properties: RouteToAwsAccountRelProperties = RouteToAwsAccountRelProperties()
5151

5252

53+
@dataclass(frozen=True)
54+
class RouteToInternetGatewayRelProperties(CartographyRelProperties):
55+
lastupdated: PropertyRef = PropertyRef('lastupdated', set_in_kwargs=True)
56+
57+
58+
@dataclass(frozen=True)
59+
class RouteToInternetGateway(CartographyRelSchema):
60+
target_node_label: str = 'AWSInternetGateway'
61+
target_node_matcher: TargetNodeMatcher = make_target_node_matcher(
62+
{'id': PropertyRef('gateway_id')},
63+
)
64+
direction: LinkDirection = LinkDirection.OUTWARD
65+
rel_label: str = "ROUTES_TO_GATEWAY"
66+
properties: RouteToInternetGatewayRelProperties = RouteToInternetGatewayRelProperties()
67+
68+
5369
@dataclass(frozen=True)
5470
class RouteSchema(CartographyNodeSchema):
5571
label: str = 'EC2Route'
5672
properties: RouteNodeProperties = RouteNodeProperties()
5773
sub_resource_relationship: RouteToAWSAccount = RouteToAWSAccount()
58-
other_relationships: OtherRelationships = OtherRelationships([])
74+
other_relationships: OtherRelationships = OtherRelationships([
75+
RouteToInternetGateway(),
76+
])

docs/root/modules/aws/schema.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,6 +1320,13 @@ Representation of an AWS EC2 [Subnet](https://docs.aws.amazon.com/AWSEC2/latest/
13201320
(EC2RouteTableAssociation)-[ASSOCIATED_WITH_IGW_FOR_INGRESS]->(AWSInternetGateway)
13211321
```
13221322
1323+
- EC2Route routes to an AWSInternetGateway. In most cases this tells AWS "to reach the internet, use this IGW".
1324+
1325+
```
1326+
(EC2Route)-[ROUTES_TO_GATEWAY]->(AWSInternetGateway)
1327+
```
1328+
1329+
13231330
### ECRRepository
13241331
13251332
Representation of an AWS Elastic Container Registry [Repository](https://docs.aws.amazon.com/AmazonECR/latest/APIReference/API_Repository.html).
@@ -3660,3 +3667,9 @@ Representation of an AWS [EC2 Route](https://docs.aws.amazon.com/AWSEC2/latest/A
36603667
```
36613668
(EC2RouteTable)-[CONTAINS]->(EC2Route)
36623669
```
3670+
3671+
- EC2Route routes to an AWSInternetGateway. In most cases this tells AWS "to reach the internet, use this IGW".
3672+
3673+
```
3674+
(EC2Route)-[ROUTES_TO_GATEWAY]->(AWSInternetGateway)
3675+
```

tests/integration/cartography/intel/aws/ec2/test_ec2_route_tables.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,17 @@ def test_sync_route_tables(mock_get_vpcs, mock_get_gateways, mock_get_route_tabl
220220
) == {
221221
("rtbassoc-ddddddddddddddddd", "igw-013cb"),
222222
}
223+
224+
# Assert route table to internet gateway relationships
225+
assert check_rels(
226+
neo4j_session,
227+
'EC2Route',
228+
'id',
229+
'AWSInternetGateway',
230+
'id',
231+
'ROUTES_TO_GATEWAY',
232+
rel_direction_right=True,
233+
) == {
234+
("rtb-aaaaaaaaaaaaaaaaa|0.0.0.0/0", "igw-0387"),
235+
("rtb-bbbbbbbbbbbbbbbbb|0.0.0.0/0", "igw-0387"),
236+
}

0 commit comments

Comments
 (0)