Skip to content

Commit 03b4e57

Browse files
authored
Merge pull request #95 from cloudgraphdev/feature/CG-1164-azure-pci-sql-server-auditing-enabled-check
feat(CG-1164): add azure pci sql server auditing enabled check
2 parents 4ca4068 + ec03e27 commit 03b4e57

6 files changed

Lines changed: 281 additions & 1 deletion

src/azure/pci-dss-3.2.1/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ Policy Pack based on the [PCI DSS version 3.2.1](https://www.pcisecuritystandard
5555

5656
| Rule | Description |
5757
| ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
58+
| data-retention-check-1 | Activity Log Retention should be 365 days or greater |
5859
| encryption-check-1 | App Service web apps should have 'HTTPS only' enabled |
5960
| encryption-check-2 | MySQL Database server 'enforce SSL connection' should be enabled |
6061
| encryption-check-3 | PostgreSQL Database server 'enforce SSL connection' should be enabled |
@@ -72,6 +73,7 @@ Policy Pack based on the [PCI DSS version 3.2.1](https://www.pcisecuritystandard
7273
| monitoring-check-11 | Monitor Activity Log Alert should exist for Delete Network Security Group Rule |
7374
| monitoring-check-12 | Monitor Activity Log Alert should exist for Delete Security Solution |
7475
| monitoring-check-13 | Monitor log profile should have activity logs for global services and all regions |
76+
| monitoring-check-14 | SQL Server auditing should be enabled |
7577
| network-access-check-1 | MySQL Database server firewall rules should not permit start and end IP addresses to be 0.0.0.0 |
7678
| network-access-check-2 | PostgreSQL Database server firewall rules should not permit start and end IP addresses to be 0.0.0.0 |
7779
| network-access-check-3 | SQL Server firewall rules should not permit start and end IP addresses to be 0.0.0.0 |

src/azure/pci-dss-3.2.1/rules/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import Azure_PCI_DSS_321_Data_Retention1 from './pci-dss-3.2.1-data-retention-check-1'
12
import Azure_PCI_DSS_321_Encryption_1 from './pci-dss-3.2.1-encryption-check-1'
23
import Azure_PCI_DSS_321_Encryption_2 from './pci-dss-3.2.1-encryption-check-2'
34
import Azure_PCI_DSS_321_Encryption_3 from './pci-dss-3.2.1-encryption-check-3'
@@ -15,6 +16,7 @@ import Azure_PCI_DSS_321_Monitoring_10 from './pci-dss-3.2.1-monitoring-check-10
1516
import Azure_PCI_DSS_321_Monitoring_11 from './pci-dss-3.2.1-monitoring-check-11'
1617
import Azure_PCI_DSS_321_Monitoring_12 from './pci-dss-3.2.1-monitoring-check-12'
1718
import Azure_PCI_DSS_321_Monitoring_13 from './pci-dss-3.2.1-monitoring-check-13'
19+
import Azure_PCI_DSS_321_Monitoring_14 from './pci-dss-3.2.1-monitoring-check-14'
1820
import Azure_PCI_DSS_321_Network_Access_1 from './pci-dss-3.2.1-network-access-check-1'
1921
import Azure_PCI_DSS_321_Network_Access_2 from './pci-dss-3.2.1-network-access-check-2'
2022
import Azure_PCI_DSS_321_Network_Access_3 from './pci-dss-3.2.1-network-access-check-3'
@@ -26,6 +28,7 @@ import Azure_PCI_DSS_321_Policy_Version_1 from './pci-dss-3.2.1-policy-version-c
2628
import Azure_PCI_DSS_321_User_1 from './pci-dss-3.2.1-user-check-1'
2729

2830
export default [
31+
Azure_PCI_DSS_321_Data_Retention1,
2932
Azure_PCI_DSS_321_Encryption_1,
3033
Azure_PCI_DSS_321_Encryption_2,
3134
Azure_PCI_DSS_321_Encryption_3,
@@ -43,6 +46,7 @@ export default [
4346
Azure_PCI_DSS_321_Monitoring_11,
4447
Azure_PCI_DSS_321_Monitoring_12,
4548
Azure_PCI_DSS_321_Monitoring_13,
49+
Azure_PCI_DSS_321_Monitoring_14,
4650
Azure_PCI_DSS_321_Network_Access_1,
4751
Azure_PCI_DSS_321_Network_Access_2,
4852
Azure_PCI_DSS_321_Network_Access_3,
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
export default {
2+
id: 'pci-dss-3.2.1-data-retention-check-1',
3+
title: 'Activity Log Retention should be 365 days or greater',
4+
5+
description: 'A log profile controls how the activity log is exported and retained. Since the average time to detect a breach is 210 days, the activity log should be retained for 365 days or more in order to have time to respond to any incidents.',
6+
7+
audit: '',
8+
9+
rationale: '',
10+
11+
remediation: `**From Azure Console**
12+
13+
Note that log profiles are now a legacy method for sending the activity log to Azure storage or event hubs.
14+
15+
- Navigate to [Monitoring > Activity Log](https://portal.azure.com/#blade/Microsoft_Azure_Monitoring/AzureMonitoringBrowseBlade/activityLog).
16+
- Click Diagnostic settings and select “Looking for the legacy experience? Click here to launch the ‘Export activity log’ blade.”
17+
- Select the Subscription from the drop-down.
18+
- Select the desired regions.
19+
- Select one or both of the following:
20+
- Export to a storage account. Select a storage account.
21+
- Export to an event hub. Select a service bus namespace.
22+
- Set the retention period to 365 days or greater. 0 means logs are kept forever.
23+
- Click Save.
24+
25+
**Azure CLI**
26+
27+
List all log profiles:
28+
29+
az monitor log-profiles list
30+
31+
Remove the log-profile by using the value from the name property:
32+
33+
az monitor log-profiles delete --name "<log profile name>"
34+
35+
- To create a log profile, use the az monitor log-profiles create command with the desired flags (see the Azure documentation for details):
36+
37+
az monitor log-profiles create --categories create
38+
--days
39+
--enabled true
40+
--location
41+
--locations
42+
--name
43+
[--service-bus-rule-id]
44+
[--storage-account-id]
45+
[--subscription]
46+
[--tags]
47+
`,
48+
49+
references: [
50+
'https://docs.microsoft.com/en-us/azure/azure-monitor/platform/platform-logs-overview',
51+
'https://docs.microsoft.com/en-us/azure/azure-monitor/platform/activity-log#legacy-collection-methods',
52+
'https://docs.microsoft.com/en-us/cli/azure/monitor/log-profiles?view=azure-cli-latest#az-monitor-log-profiles-create',
53+
],
54+
gql: `
55+
queryazureLogProfile {
56+
id
57+
__typename
58+
retentionPolicy {
59+
enabled
60+
days
61+
}
62+
}
63+
`,
64+
resource: 'queryazureLogProfile[*]',
65+
severity: 'medium',
66+
conditions: {
67+
and: [
68+
{
69+
path: '@.retentionPolicy.enabled',
70+
equal: true,
71+
},
72+
{
73+
or: [
74+
{
75+
path: '@.retentionPolicy.days',
76+
equal: 0,
77+
},
78+
{
79+
path: '@.retentionPolicy.days',
80+
greaterThanInclusive: 365,
81+
},
82+
]
83+
},
84+
],
85+
},
86+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// similar to NIST 2.5
2+
export default {
3+
id: 'pci-dss-3.2.1-monitoring-check-14',
4+
title: 'Monitoring Check 14: SQL Server auditing should be enabled',
5+
6+
description: 'The Azure platform allows a SQL server to be created as a service. Enabling auditing at the server level ensures that all existing and newly created databases on the SQL server instance are audited. Auditing policy applied on the SQL database does not override auditing policy and settings applied on the particular SQL server where the database is hosted.',
7+
8+
audit: '',
9+
10+
rationale: '',
11+
12+
remediation: `**From Azure Console**
13+
14+
- Navigate to [SQL Servers](https://portal.azure.com/#blade/HubsExtension/BrowseResource/resourceType/Microsoft.Sql%2Fservers).
15+
- Select the SQL server.
16+
- In the left navigation in the Security section, select Auditing.
17+
- Set Auditing to On.
18+
19+
**Using PowerShell:**
20+
21+
- To enable auditing for SQL Server, get a list of all SQL servers:
22+
23+
Get-AzureRmSqlServer
24+
25+
- Enable auditing for each server:
26+
27+
Set-AzureRmSqlServerAuditingPolicy -ResourceGroupName <resource group name> -ServerName <server name> -AuditType <audit type> -StorageAccountName <storage account name>`,
28+
29+
references: [
30+
'https://docs.microsoft.com/en-us/azure/security-center/security-center-sql-service-recommendations',
31+
'https://docs.microsoft.com/en-us/powershell/module/azurerm.sql/get-azurermsqlserverauditing?view=azurermps-6.13.0&viewFallbackFrom=azurermps-5.2.0',
32+
'https://docs.microsoft.com/en-us/powershell/module/azurerm.sql/set-azurermsqlserverauditingpolicy?view=azurermps-6.13.0&viewFallbackFrom=azurermps-5.2.0',
33+
'https://docs.microsoft.com/en-us/azure/azure-sql/database/auditing-overview',
34+
],
35+
gql: `{
36+
queryazureSqlServer {
37+
id
38+
__typename
39+
serverBlobAuditingPolicies {
40+
state
41+
}
42+
}
43+
}`,
44+
resource: 'queryazureSqlServer[*]',
45+
severity: 'medium',
46+
conditions: {
47+
path: '@.serverBlobAuditingPolicies',
48+
array_any: {
49+
path: '[*].state',
50+
equal: 'Enabled'
51+
},
52+
},
53+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import { Rule, Result, Engine } from '@cloudgraph/sdk'
2+
import cuid from 'cuid'
3+
import { initRuleEngine } from '../../../utils/test'
4+
5+
import Azure_PCI_DSS_321_Data_Retention_Check_1 from '../rules/pci-dss-3.2.1-data-retention-check-1'
6+
7+
export interface RetentionPolicy {
8+
enabled: boolean
9+
days: number
10+
}
11+
12+
export interface QueryazureLogProfile {
13+
id: string
14+
name?: string
15+
locations?: string[]
16+
categories?: string[]
17+
retentionPolicy?: RetentionPolicy | null
18+
}
19+
20+
export interface PCIQueryResponse {
21+
queryazureLogProfile?: QueryazureLogProfile[]
22+
}
23+
24+
describe('PCI Data Security Standard: 3.2.1', () => {
25+
let rulesEngine: Engine
26+
beforeAll(() => {
27+
rulesEngine = initRuleEngine('azure', 'PCI')
28+
})
29+
30+
describe('Retention Check 1: Activity Log Retention should be 365 days or greater', () => {
31+
const getTestRuleFixture = (
32+
enabled: boolean,
33+
days: number,
34+
): PCIQueryResponse => {
35+
return {
36+
queryazureLogProfile: [
37+
{
38+
id: cuid(),
39+
retentionPolicy: {
40+
enabled,
41+
days,
42+
},
43+
},
44+
],
45+
}
46+
}
47+
48+
// Act
49+
const testRule = async (
50+
data: PCIQueryResponse,
51+
expectedResult: Result
52+
): Promise<void> => {
53+
// Act
54+
const [processedRule] = await rulesEngine.processRule(
55+
Azure_PCI_DSS_321_Data_Retention_Check_1 as Rule,
56+
{ ...data }
57+
)
58+
59+
// Asserts
60+
expect(processedRule.result).toBe(expectedResult)
61+
}
62+
63+
test('No Security Issue when Monitor audit profile log retention day is 0 means logs are kept forever', async () => {
64+
const data: PCIQueryResponse = getTestRuleFixture(true, 0)
65+
await testRule(data, Result.PASS)
66+
})
67+
68+
test('Security Issue when Monitor audit profile log is less than 365 days', async () => {
69+
const data: PCIQueryResponse = getTestRuleFixture(true, 364)
70+
await testRule(data, Result.FAIL)
71+
})
72+
73+
test('No Security Issue when Monitor audit profile log retention day is 365 days', async () => {
74+
const data: PCIQueryResponse = getTestRuleFixture(true, 365)
75+
await testRule(data, Result.PASS)
76+
})
77+
78+
test('No Security Issue when Monitor audit profile log retention day is more than 365 days', async () => {
79+
const data: PCIQueryResponse = getTestRuleFixture(true, 366)
80+
await testRule(data, Result.PASS)
81+
})
82+
})
83+
})

src/azure/pci-dss-3.2.1/tests/pci-dss-3.2.1-monitoring-checks.test.ts

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import Azure_PCI_DSS_321_Monitoring_10 from '../rules/pci-dss-3.2.1-monitoring-c
1515
import Azure_PCI_DSS_321_Monitoring_11 from '../rules/pci-dss-3.2.1-monitoring-check-11'
1616
import Azure_PCI_DSS_321_Monitoring_12 from '../rules/pci-dss-3.2.1-monitoring-check-12'
1717
import Azure_PCI_DSS_321_Monitoring_13 from '../rules/pci-dss-3.2.1-monitoring-check-13'
18+
import Azure_PCI_DSS_321_Monitoring_14 from '../rules/pci-dss-3.2.1-monitoring-check-14'
1819

1920
export interface azureActivityLogAlertLeafCondition {
2021
id: string
@@ -65,11 +66,18 @@ export interface QueryazurePolicyAssignment {
6566
displayName: string
6667
parameters: Parameter[]
6768
}
68-
69+
export interface ServerBlobAuditingPolicy {
70+
state: string
71+
}
72+
export interface QueryazureSqlServer {
73+
id: string
74+
serverBlobAuditingPolicies: ServerBlobAuditingPolicy[]
75+
}
6976
export interface PCIQueryResponse {
7077
queryazureLogProfile?: QueryazureLogProfile[]
7178
queryazureSubscription?: QueryazureSubscription[]
7279
queryazurePolicyAssignment?: QueryazurePolicyAssignment[]
80+
queryazureSqlServer?: QueryazureSqlServer[]
7381
}
7482

7583
describe('PCI Data Security Standard: 3.2.1', () => {
@@ -956,4 +964,48 @@ describe('PCI Data Security Standard: 3.2.1', () => {
956964
await testRule(data, Result.FAIL)
957965
})
958966
})
967+
968+
describe('Monitoring Check 14: SQL Server auditing should be enabled', () => {
969+
const getTestRuleFixture = (
970+
state: string
971+
): PCIQueryResponse => {
972+
return {
973+
queryazureSqlServer: [
974+
{
975+
id: cuid(),
976+
serverBlobAuditingPolicies: [
977+
{
978+
state
979+
}
980+
]
981+
},
982+
],
983+
}
984+
}
985+
986+
// Act
987+
const testRule = async (
988+
data: PCIQueryResponse,
989+
expectedResult: Result
990+
): Promise<void> => {
991+
// Act
992+
const [processedRule] = await rulesEngine.processRule(
993+
Azure_PCI_DSS_321_Monitoring_14 as Rule,
994+
{ ...data }
995+
)
996+
997+
// Asserts
998+
expect(processedRule.result).toBe(expectedResult)
999+
}
1000+
1001+
test('No Security Issue when SQL Server auditing is enabled', async () => {
1002+
const data: PCIQueryResponse = getTestRuleFixture('Enabled')
1003+
await testRule(data, Result.PASS)
1004+
})
1005+
1006+
test('Security Issue when SQL Server auditing is disabled', async () => {
1007+
const data: PCIQueryResponse = getTestRuleFixture('Disabled')
1008+
await testRule(data, Result.FAIL)
1009+
})
1010+
})
9591011
})

0 commit comments

Comments
 (0)