Skip to content
This repository was archived by the owner on Jun 25, 2024. It is now read-only.

Commit d738880

Browse files
Additional mapping changes for firewalls
1 parent d1e040b commit d738880

File tree

8 files changed

+249
-52
lines changed

8 files changed

+249
-52
lines changed

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@
2727
"create-env-file": "yarn ts-node ./scripts/createEnvFile $1"
2828
},
2929
"peerDependencies": {
30-
"@jupiterone/integration-sdk-core": "^3.5.0"
30+
"@jupiterone/integration-sdk-core": "^3.5.1"
3131
},
3232
"devDependencies": {
33-
"@jupiterone/integration-sdk-core": "^3.5.0",
34-
"@jupiterone/integration-sdk-dev-tools": "^3.5.0",
35-
"@jupiterone/integration-sdk-testing": "^3.5.0",
33+
"@jupiterone/integration-sdk-core": "^3.5.1",
34+
"@jupiterone/integration-sdk-dev-tools": "^3.5.1",
35+
"@jupiterone/integration-sdk-testing": "^3.5.1",
3636
"dotenv": "^8.2.0",
3737
"ts-node": "^8.10.2"
3838
},

src/steps/compute/__snapshots__/converters.test.ts.snap

+10-1
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,10 @@ Object {
341341
"labelFingerprint": "42WmSpB8rSM=",
342342
"machineType": "n1-standard-1",
343343
"name": "testvm",
344+
"privateIpAddress": Array [
345+
"10.128.0.2",
346+
],
347+
"publicIpAddress": Array [],
344348
"startRestricted": false,
345349
"status": "RUNNING",
346350
"zone": "us-central1-a",
@@ -467,6 +471,10 @@ Object {
467471
"labelFingerprint": "42WmSpB8rSM=",
468472
"machineType": "n1-standard-1",
469473
"name": "testvm",
474+
"privateIpAddress": Array [
475+
"10.128.0.2",
476+
],
477+
"publicIpAddress": Array [],
470478
"startRestricted": false,
471479
"status": "SUSPENDED",
472480
"zone": "us-central1-a",
@@ -490,6 +498,7 @@ Object {
490498

491499
exports[`#createComputeNetworkEntity should convert to entity 1`] = `
492500
Object {
501+
"CIDR": null,
493502
"_class": Array [
494503
"Network",
495504
],
@@ -576,7 +585,7 @@ Object {
576585
exports[`#createFirewallRuleMappedRelationship should convert to mapped relationship 1`] = `
577586
Object {
578587
"_class": "ALLOWS",
579-
"_key": "https://www.googleapis.com/compute/v1/projects/j1-gc-integration-dev/global/firewalls/public-compute-app-fw-allow-https:0.0.0.0/0:443",
588+
"_key": "https://www.googleapis.com/compute/v1/projects/j1-gc-integration-dev/global/firewalls/public-compute-app-fw-allow-https:tcp:0.0.0.0/0:443",
580589
"_mapping": Object {
581590
"relationshipDirection": "REVERSE",
582591
"skipTargetCreation": true,

src/steps/compute/__snapshots__/index.test.ts.snap

+104-7
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ exports[`#fetchComputeFirewalls should collect data 1`] = `
8888
Object {
8989
"collectedEntities": Array [
9090
Object {
91+
"CIDR": null,
9192
"_class": Array [
9293
"Network",
9394
],
@@ -175,6 +176,7 @@ Object {
175176
"webLink": "https://console.cloud.google.com/networking/networks/details/default?project=j1-gc-integration-dev",
176177
},
177178
Object {
179+
"CIDR": null,
178180
"_class": Array [
179181
"Network",
180182
],
@@ -215,6 +217,7 @@ Object {
215217
"webLink": "https://console.cloud.google.com/networking/networks/details/public-compute-app-vpc?project=j1-gc-integration-dev",
216218
},
217219
Object {
220+
"CIDR": null,
218221
"_class": Array [
219222
"Network",
220223
],
@@ -3090,7 +3093,7 @@ Object {
30903093
},
30913094
Object {
30923095
"_class": "ALLOWS",
3093-
"_key": "https://www.googleapis.com/compute/v1/projects/j1-gc-integration-dev/global/firewalls/default-allow-icmp:0.0.0.0/0:*",
3096+
"_key": "https://www.googleapis.com/compute/v1/projects/j1-gc-integration-dev/global/firewalls/default-allow-icmp:icmp:0.0.0.0/0:*",
30943097
"_mapping": Object {
30953098
"relationshipDirection": "REVERSE",
30963099
"skipTargetCreation": true,
@@ -3138,6 +3141,90 @@ Object {
31383141
"_type": "google_compute_network_has_firewall",
31393142
"displayName": "HAS",
31403143
},
3144+
Object {
3145+
"_class": "ALLOWS",
3146+
"_key": "https://www.googleapis.com/compute/v1/projects/j1-gc-integration-dev/global/firewalls/default-allow-internal:tcp:10.128.0.0/9:*",
3147+
"_mapping": Object {
3148+
"relationshipDirection": "REVERSE",
3149+
"skipTargetCreation": true,
3150+
"sourceEntityKey": "https://www.googleapis.com/compute/v1/projects/j1-gc-integration-dev/global/firewalls/default-allow-internal",
3151+
"targetEntity": Object {
3152+
"CIDR": "10.128.0.0/9",
3153+
"_class": "Network",
3154+
"netmask": "9",
3155+
},
3156+
"targetFilterKeys": Array [
3157+
Array [
3158+
"_class",
3159+
"CIDR",
3160+
],
3161+
],
3162+
},
3163+
"_type": "google_cloud_firewall_rule",
3164+
"displayName": "ALLOWS",
3165+
"fromPort": 0,
3166+
"ipProtocol": "tcp",
3167+
"ipRange": "10.128.0.0/9",
3168+
"portRange": "*",
3169+
"protocol": "tcp",
3170+
"toPort": 65535,
3171+
},
3172+
Object {
3173+
"_class": "ALLOWS",
3174+
"_key": "https://www.googleapis.com/compute/v1/projects/j1-gc-integration-dev/global/firewalls/default-allow-internal:udp:10.128.0.0/9:*",
3175+
"_mapping": Object {
3176+
"relationshipDirection": "REVERSE",
3177+
"skipTargetCreation": true,
3178+
"sourceEntityKey": "https://www.googleapis.com/compute/v1/projects/j1-gc-integration-dev/global/firewalls/default-allow-internal",
3179+
"targetEntity": Object {
3180+
"CIDR": "10.128.0.0/9",
3181+
"_class": "Network",
3182+
"netmask": "9",
3183+
},
3184+
"targetFilterKeys": Array [
3185+
Array [
3186+
"_class",
3187+
"CIDR",
3188+
],
3189+
],
3190+
},
3191+
"_type": "google_cloud_firewall_rule",
3192+
"displayName": "ALLOWS",
3193+
"fromPort": 0,
3194+
"ipProtocol": "udp",
3195+
"ipRange": "10.128.0.0/9",
3196+
"portRange": "*",
3197+
"protocol": "udp",
3198+
"toPort": 65535,
3199+
},
3200+
Object {
3201+
"_class": "ALLOWS",
3202+
"_key": "https://www.googleapis.com/compute/v1/projects/j1-gc-integration-dev/global/firewalls/default-allow-internal:icmp:10.128.0.0/9:*",
3203+
"_mapping": Object {
3204+
"relationshipDirection": "REVERSE",
3205+
"skipTargetCreation": true,
3206+
"sourceEntityKey": "https://www.googleapis.com/compute/v1/projects/j1-gc-integration-dev/global/firewalls/default-allow-internal",
3207+
"targetEntity": Object {
3208+
"CIDR": "10.128.0.0/9",
3209+
"_class": "Network",
3210+
"netmask": "9",
3211+
},
3212+
"targetFilterKeys": Array [
3213+
Array [
3214+
"_class",
3215+
"CIDR",
3216+
],
3217+
],
3218+
},
3219+
"_type": "google_cloud_firewall_rule",
3220+
"displayName": "ALLOWS",
3221+
"fromPort": 0,
3222+
"ipProtocol": "icmp",
3223+
"ipRange": "10.128.0.0/9",
3224+
"portRange": "*",
3225+
"protocol": "icmp",
3226+
"toPort": 65535,
3227+
},
31413228
Object {
31423229
"_class": "PROTECTS",
31433230
"_fromEntityKey": "https://www.googleapis.com/compute/v1/projects/j1-gc-integration-dev/global/firewalls/default-allow-rdp",
@@ -3156,7 +3243,7 @@ Object {
31563243
},
31573244
Object {
31583245
"_class": "ALLOWS",
3159-
"_key": "https://www.googleapis.com/compute/v1/projects/j1-gc-integration-dev/global/firewalls/default-allow-rdp:0.0.0.0/0:3389",
3246+
"_key": "https://www.googleapis.com/compute/v1/projects/j1-gc-integration-dev/global/firewalls/default-allow-rdp:tcp:0.0.0.0/0:3389",
31603247
"_mapping": Object {
31613248
"relationshipDirection": "REVERSE",
31623249
"skipTargetCreation": true,
@@ -3206,7 +3293,7 @@ Object {
32063293
},
32073294
Object {
32083295
"_class": "ALLOWS",
3209-
"_key": "https://www.googleapis.com/compute/v1/projects/j1-gc-integration-dev/global/firewalls/default-allow-ssh:0.0.0.0/0:22",
3296+
"_key": "https://www.googleapis.com/compute/v1/projects/j1-gc-integration-dev/global/firewalls/default-allow-ssh:tcp:0.0.0.0/0:22",
32103297
"_mapping": Object {
32113298
"relationshipDirection": "REVERSE",
32123299
"skipTargetCreation": true,
@@ -3256,7 +3343,7 @@ Object {
32563343
},
32573344
Object {
32583345
"_class": "ALLOWS",
3259-
"_key": "https://www.googleapis.com/compute/v1/projects/j1-gc-integration-dev/global/firewalls/public-compute-app-fw-allow-http:0.0.0.0/0:80",
3346+
"_key": "https://www.googleapis.com/compute/v1/projects/j1-gc-integration-dev/global/firewalls/public-compute-app-fw-allow-http:tcp:0.0.0.0/0:80",
32603347
"_mapping": Object {
32613348
"relationshipDirection": "REVERSE",
32623349
"skipTargetCreation": true,
@@ -3306,7 +3393,7 @@ Object {
33063393
},
33073394
Object {
33083395
"_class": "ALLOWS",
3309-
"_key": "https://www.googleapis.com/compute/v1/projects/j1-gc-integration-dev/global/firewalls/public-compute-app-fw-allow-https:0.0.0.0/0:443",
3396+
"_key": "https://www.googleapis.com/compute/v1/projects/j1-gc-integration-dev/global/firewalls/public-compute-app-fw-allow-https:tcp:0.0.0.0/0:443",
33103397
"_mapping": Object {
33113398
"relationshipDirection": "REVERSE",
33123399
"skipTargetCreation": true,
@@ -3356,7 +3443,7 @@ Object {
33563443
},
33573444
Object {
33583445
"_class": "DENIES",
3359-
"_key": "https://www.googleapis.com/compute/v1/projects/j1-gc-integration-dev/global/firewalls/public-compute-app-fw-deny-ssh:0.0.0.0/0:22",
3446+
"_key": "https://www.googleapis.com/compute/v1/projects/j1-gc-integration-dev/global/firewalls/public-compute-app-fw-deny-ssh:tcp:0.0.0.0/0:22",
33603447
"_mapping": Object {
33613448
"relationshipDirection": "REVERSE",
33623449
"skipTargetCreation": true,
@@ -3399,7 +3486,7 @@ Object {
33993486
"google_cloud_firewall_rule",
34003487
],
34013488
"numCollectedEntities": 59,
3402-
"numCollectedRelationships": 69,
3489+
"numCollectedRelationships": 72,
34033490
}
34043491
`;
34053492

@@ -4036,6 +4123,10 @@ Object {
40364123
"labelFingerprint": "42WmSpB8rSM=",
40374124
"machineType": "n1-standard-1",
40384125
"name": "testvm",
4126+
"privateIpAddress": Array [
4127+
"10.128.0.2",
4128+
],
4129+
"publicIpAddress": Array [],
40394130
"startRestricted": false,
40404131
"status": "RUNNING",
40414132
"zone": "us-central1-a",
@@ -4181,6 +4272,7 @@ exports[`#fetchComputeNetworks should collect data 1`] = `
41814272
Object {
41824273
"collectedEntities": Array [
41834274
Object {
4275+
"CIDR": null,
41844276
"_class": Array [
41854277
"Network",
41864278
],
@@ -4268,6 +4360,7 @@ Object {
42684360
"webLink": "https://console.cloud.google.com/networking/networks/details/default?project=j1-gc-integration-dev",
42694361
},
42704362
Object {
4363+
"CIDR": null,
42714364
"_class": Array [
42724365
"Network",
42734366
],
@@ -4308,6 +4401,7 @@ Object {
43084401
"webLink": "https://console.cloud.google.com/networking/networks/details/public-compute-app-vpc?project=j1-gc-integration-dev",
43094402
},
43104403
Object {
4404+
"CIDR": null,
43114405
"_class": Array [
43124406
"Network",
43134407
],
@@ -4408,6 +4502,7 @@ exports[`#fetchComputeSubnetworks should collect data 1`] = `
44084502
Object {
44094503
"collectedEntities": Array [
44104504
Object {
4505+
"CIDR": null,
44114506
"_class": Array [
44124507
"Network",
44134508
],
@@ -4495,6 +4590,7 @@ Object {
44954590
"webLink": "https://console.cloud.google.com/networking/networks/details/default?project=j1-gc-integration-dev",
44964591
},
44974592
Object {
4593+
"CIDR": null,
44984594
"_class": Array [
44994595
"Network",
45004596
],
@@ -4535,6 +4631,7 @@ Object {
45354631
"webLink": "https://console.cloud.google.com/networking/networks/details/public-compute-app-vpc?project=j1-gc-integration-dev",
45364632
},
45374633
Object {
4634+
"CIDR": null,
45384635
"_class": Array [
45394636
"Network",
45404637
],

src/steps/compute/converters.test.ts

+36
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
createComputeNetworkEntity,
77
createComputeSubnetEntity,
88
createFirewallRuleMappedRelationship,
9+
getIpAddressesForComputeInstance,
910
} from './converters';
1011
import {
1112
getMockComputeDisk,
@@ -123,3 +124,38 @@ describe('#createComputeNetworkEntity', () => {
123124
).toMatchSnapshot();
124125
});
125126
});
127+
128+
describe('#getIpAddressesForComputeInstance', () => {
129+
test('should get IP addresses given a compute instance with network interfaces and accessConfigs', () => {
130+
expect(
131+
getIpAddressesForComputeInstance(
132+
getMockComputeInstance({
133+
networkInterfaces: [
134+
{
135+
network:
136+
'https://www.googleapis.com/compute/v1/projects/j1-gc-integration-dev/global/networks/public-compute-app-vpc',
137+
subnetwork:
138+
'https://www.googleapis.com/compute/v1/projects/j1-gc-integration-dev/regions/us-central1/subnetworks/public-compute-app-public-subnet-1',
139+
networkIP: '10.10.1.2',
140+
name: 'nic0',
141+
accessConfigs: [
142+
{
143+
type: 'ONE_TO_ONE_NAT',
144+
name: 'external-nat',
145+
natIP: '34.71.33.132',
146+
networkTier: 'PREMIUM',
147+
kind: 'compute#accessConfig',
148+
},
149+
],
150+
fingerprint: 'ElJkype-dKI=',
151+
kind: 'compute#networkInterface',
152+
},
153+
],
154+
}),
155+
),
156+
).toEqual({
157+
publicIpAddresses: ['34.71.33.132'],
158+
privateIpAddresses: ['10.10.1.2'],
159+
});
160+
});
161+
});

0 commit comments

Comments
 (0)