Skip to content

Commit ec03e27

Browse files
feat(CG-1164): add Activity Log Retention
1 parent e1e9221 commit ec03e27

4 files changed

Lines changed: 172 additions & 0 deletions

File tree

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

Lines changed: 1 addition & 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 |

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

Lines changed: 2 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'
@@ -27,6 +28,7 @@ import Azure_PCI_DSS_321_Policy_Version_1 from './pci-dss-3.2.1-policy-version-c
2728
import Azure_PCI_DSS_321_User_1 from './pci-dss-3.2.1-user-check-1'
2829

2930
export default [
31+
Azure_PCI_DSS_321_Data_Retention1,
3032
Azure_PCI_DSS_321_Encryption_1,
3133
Azure_PCI_DSS_321_Encryption_2,
3234
Azure_PCI_DSS_321_Encryption_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: 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+
})

0 commit comments

Comments
 (0)