Skip to content

Commit 7c9647c

Browse files
authored
Merge pull request #124 from cloudgraphdev/feature/CG-1263-azure-nist-36-update
feat(CG-1263): update azure network watcher cis and nist rule
2 parents b060c72 + af8853e commit 7c9647c

4 files changed

Lines changed: 137 additions & 3 deletions

File tree

src/azure/cis-1.3.1/rules/azure-cis-1.3.1-6.5.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export default {
22
id: 'azure-cis-1.3.1-6.5',
3-
title: 'Azure CIS 6.5 Ensure that Network Watcher is \'Enabled\' (Manual)',
3+
title: 'Azure CIS 6.5 Ensure that Network Watcher is \'Enabled\'',
44

55
description: 'Enable Network Watcher for Azure subscriptions.',
66

@@ -31,5 +31,19 @@ export default {
3131
'https://docs.microsoft.com/en-us/azure/network-watcher/network-watcher-create',
3232
'https://docs.microsoft.com/en-us/azure/security/benchmarks/security-controls-v2-logging-threat-detection#lt-3-enable-logging-for-azure-network-activities',
3333
],
34-
severity: 'high'
34+
severity: 'high',
35+
gql: `{
36+
queryazureResourceGroup {
37+
id
38+
__typename
39+
virtualNetworks {
40+
id
41+
}
42+
}
43+
}`,
44+
resource: 'queryazureResourceGroup[*]',
45+
check: ({ resource }: any) => {
46+
const { virtualNetworks } = resource
47+
return !!virtualNetworks
48+
},
3549
}

src/azure/cis-1.3.1/tests/azure-cis-1.3.1-6.x.test.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Azure_CIS_131_61 from '../rules/azure-cis-1.3.1-6.1'
77
import Azure_CIS_131_62 from '../rules/azure-cis-1.3.1-6.2'
88
import Azure_CIS_131_63 from '../rules/azure-cis-1.3.1-6.3'
99
import Azure_CIS_131_64 from '../rules/azure-cis-1.3.1-6.4'
10+
import Azure_CIS_131_65 from '../rules/azure-cis-1.3.1-6.5'
1011
import Azure_CIS_131_66 from '../rules/azure-cis-1.3.1-6.6'
1112
import { initRuleEngine } from '../../../utils/test'
1213

@@ -38,9 +39,18 @@ export interface QueryazureSqlServer {
3839
firewallRules?: FirewallRules[]
3940
}
4041

42+
export interface VirtualNetwork {
43+
id: string
44+
}
45+
46+
export interface QueryazureResourceGroup {
47+
id: string
48+
virtualNetworks?: VirtualNetwork[]
49+
}
4150
export interface CIS6xQueryResponse {
4251
queryazureNetworkSecurityGroup?: QueryazureNetworkSecurityGroup[]
4352
queryazureSqlServer?: QueryazureSqlServer[]
53+
queryazureResourceGroup?: QueryazureResourceGroup[]
4454
}
4555

4656
describe('CIS Microsoft Azure Foundations: 1.3.1', () => {
@@ -373,6 +383,56 @@ describe('CIS Microsoft Azure Foundations: 1.3.1', () => {
373383
})
374384
})
375385

386+
describe('Azure CIS 6.5 Ensure that Network Watcher is Enabled', () => {
387+
const getTestRuleFixture = (
388+
enabled: boolean,
389+
): CIS6xQueryResponse => {
390+
return {
391+
queryazureResourceGroup: [
392+
{
393+
id: cuid(),
394+
virtualNetworks: enabled? [
395+
{
396+
id: cuid(),
397+
},
398+
]: undefined,
399+
},
400+
],
401+
}
402+
}
403+
404+
const testRule = async (
405+
data: CIS6xQueryResponse,
406+
expectedResult: Result
407+
): Promise<void> => {
408+
// Act
409+
const [processedRule] = await rulesEngine.processRule(
410+
Azure_CIS_131_65 as Rule,
411+
{ ...data }
412+
)
413+
414+
// Asserts
415+
expect(processedRule.result).toBe(expectedResult)
416+
}
417+
418+
test('No Security Issue when Network Watcher is enabled', async () => {
419+
const data: CIS6xQueryResponse = getTestRuleFixture(
420+
true,
421+
)
422+
423+
await testRule(data, Result.PASS)
424+
})
425+
426+
test('Security Issue when Network Watcher is disabled', async () => {
427+
const data: CIS6xQueryResponse = getTestRuleFixture(
428+
false,
429+
)
430+
431+
await testRule(data, Result.FAIL)
432+
})
433+
})
434+
435+
376436
describe('Azure CIS 6.6 Ensure that UDP Services are restricted from the Internet', () => {
377437
const getTestRuleFixture = (
378438
access?: string,

src/azure/nist-800-53-rev4/rules/azure-nist-800-53-rev4-3.6.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,19 @@ export default {
3232
'https://docs.microsoft.com/en-us/azure/network-watcher/network-watcher-create',
3333
'https://docs.microsoft.com/en-us/azure/security/benchmarks/security-controls-v2-logging-threat-detection#lt-3-enable-logging-for-azure-network-activities',
3434
],
35-
severity: 'high'
35+
severity: 'high',
36+
gql: `{
37+
queryazureResourceGroup {
38+
id
39+
__typename
40+
virtualNetworks {
41+
id
42+
}
43+
}
44+
}`,
45+
resource: 'queryazureResourceGroup[*]',
46+
check: ({ resource }: any) => {
47+
const { virtualNetworks } = resource
48+
return !!virtualNetworks
49+
},
3650
}

src/azure/nist-800-53-rev4/tests/nist-800-53-rev4-3.x.test.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Azure_NIST_800_53_32 from '../rules/azure-nist-800-53-rev4-3.2'
88
import Azure_NIST_800_53_33 from '../rules/azure-nist-800-53-rev4-3.3'
99
import Azure_NIST_800_53_34 from '../rules/azure-nist-800-53-rev4-3.4'
1010
import Azure_NIST_800_53_35 from '../rules/azure-nist-800-53-rev4-3.5'
11+
import Azure_NIST_800_53_36 from '../rules/azure-nist-800-53-rev4-3.6'
1112
import Azure_NIST_800_53_37 from '../rules/azure-nist-800-53-rev4-3.7'
1213
import { initRuleEngine, testRule } from '../../../utils/test'
1314

@@ -67,11 +68,21 @@ export interface QueryazureSqlServer {
6768
firewallRules?: FirewallRules[]
6869
}
6970

71+
export interface VirtualNetwork {
72+
id: string
73+
}
74+
75+
export interface QueryazureResourceGroup {
76+
id: string
77+
virtualNetworks?: VirtualNetwork[]
78+
}
79+
7080
export interface NIST3xQueryResponse {
7181
queryazureStorageContainer?: QueryazureStorageContainer[]
7282
queryazureDiagnosticSetting?: QueryazureDiagnosticSetting[]
7383
queryazureSqlServer?: QueryazureSqlServer[]
7484
queryazureSubscription?: QueryazureSubscription[]
85+
queryazureResourceGroup?: QueryazureResourceGroup[]
7586
}
7687

7788
describe('Azure NIST 800-53: Rev. 4', () => {
@@ -341,6 +352,41 @@ describe('Azure NIST 800-53: Rev. 4', () => {
341352
})
342353
})
343354

355+
describe('Azure NIST 3.6 Virtual Network Network Watcher should be enabled', () => {
356+
const getTestRuleFixture = (
357+
enabled: boolean,
358+
): NIST3xQueryResponse => {
359+
return {
360+
queryazureResourceGroup: [
361+
{
362+
id: cuid(),
363+
virtualNetworks: enabled? [
364+
{
365+
id: cuid(),
366+
},
367+
]: undefined,
368+
},
369+
],
370+
}
371+
}
372+
373+
test('No Security Issue when Network Watcher is enabled', async () => {
374+
const data: NIST3xQueryResponse = getTestRuleFixture(
375+
true,
376+
)
377+
378+
await testRule(rulesEngine, data, Azure_NIST_800_53_36 as Rule, Result.PASS)
379+
})
380+
381+
test('Security Issue when Network Watcher is disabled', async () => {
382+
const data: NIST3xQueryResponse = getTestRuleFixture(
383+
false,
384+
)
385+
386+
await testRule(rulesEngine, data, Azure_NIST_800_53_36 as Rule, Result.FAIL)
387+
})
388+
})
389+
344390
describe('Azure NIST 3.7 Ensure that Activity Log Alert exists for Create or Update Network Security Group', () => {
345391
const getTestRuleFixture_527 = (
346392
enabled: boolean,

0 commit comments

Comments
 (0)