guardrail-compliance 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/audit/emitter.d.ts +97 -0
- package/dist/audit/emitter.d.ts.map +1 -0
- package/dist/audit/emitter.js +197 -0
- package/dist/audit/events.d.ts +304 -0
- package/dist/audit/events.d.ts.map +1 -0
- package/dist/audit/events.js +267 -0
- package/dist/audit/index.d.ts +11 -0
- package/dist/audit/index.d.ts.map +1 -0
- package/dist/audit/index.js +51 -0
- package/dist/audit/storage.d.ts +93 -0
- package/dist/audit/storage.d.ts.map +1 -0
- package/dist/audit/storage.js +337 -0
- package/dist/automation/__tests__/compliance-scheduler.test.d.ts +2 -0
- package/dist/automation/__tests__/compliance-scheduler.test.d.ts.map +1 -0
- package/dist/automation/__tests__/compliance-scheduler.test.js +140 -0
- package/dist/automation/audit-logger.d.ts +129 -0
- package/dist/automation/audit-logger.d.ts.map +1 -0
- package/dist/automation/audit-logger.js +473 -0
- package/dist/automation/compliance-scheduler-fixed.d.ts +1 -0
- package/dist/automation/compliance-scheduler-fixed.d.ts.map +1 -0
- package/dist/automation/compliance-scheduler-fixed.js +1 -0
- package/dist/automation/compliance-scheduler.d.ts +83 -0
- package/dist/automation/compliance-scheduler.d.ts.map +1 -0
- package/dist/automation/compliance-scheduler.js +414 -0
- package/dist/automation/dashboard.d.ts +194 -0
- package/dist/automation/dashboard.d.ts.map +1 -0
- package/dist/automation/dashboard.js +768 -0
- package/dist/automation/email-service.d.ts +69 -0
- package/dist/automation/email-service.d.ts.map +1 -0
- package/dist/automation/email-service.js +218 -0
- package/dist/automation/evidence-collector.d.ts +140 -0
- package/dist/automation/evidence-collector.d.ts.map +1 -0
- package/dist/automation/evidence-collector.js +682 -0
- package/dist/automation/index.d.ts +8 -0
- package/dist/automation/index.d.ts.map +1 -0
- package/dist/automation/index.js +24 -0
- package/dist/automation/pdf-exporter.d.ts +90 -0
- package/dist/automation/pdf-exporter.d.ts.map +1 -0
- package/dist/automation/pdf-exporter.js +381 -0
- package/dist/automation/reporting-engine.d.ts +116 -0
- package/dist/automation/reporting-engine.d.ts.map +1 -0
- package/dist/automation/reporting-engine.js +329 -0
- package/dist/container/index.d.ts +4 -0
- package/dist/container/index.d.ts.map +1 -0
- package/dist/container/index.js +19 -0
- package/dist/container/kubernetes.d.ts +94 -0
- package/dist/container/kubernetes.d.ts.map +1 -0
- package/dist/container/kubernetes.js +268 -0
- package/dist/container/rules.d.ts +27 -0
- package/dist/container/rules.d.ts.map +1 -0
- package/dist/container/rules.js +216 -0
- package/dist/container/scanner.d.ts +50 -0
- package/dist/container/scanner.d.ts.map +1 -0
- package/dist/container/scanner.js +143 -0
- package/dist/frameworks/engine.d.ts +108 -0
- package/dist/frameworks/engine.d.ts.map +1 -0
- package/dist/frameworks/engine.js +206 -0
- package/dist/frameworks/gdpr.d.ts +6 -0
- package/dist/frameworks/gdpr.d.ts.map +1 -0
- package/dist/frameworks/gdpr.js +198 -0
- package/dist/frameworks/hipaa.d.ts +6 -0
- package/dist/frameworks/hipaa.d.ts.map +1 -0
- package/dist/frameworks/hipaa.js +183 -0
- package/dist/frameworks/index.d.ts +8 -0
- package/dist/frameworks/index.d.ts.map +1 -0
- package/dist/frameworks/index.js +30 -0
- package/dist/frameworks/iso27001.d.ts +63 -0
- package/dist/frameworks/iso27001.d.ts.map +1 -0
- package/dist/frameworks/iso27001.js +331 -0
- package/dist/frameworks/nist.d.ts +62 -0
- package/dist/frameworks/nist.d.ts.map +1 -0
- package/dist/frameworks/nist.js +424 -0
- package/dist/frameworks/pci.d.ts +6 -0
- package/dist/frameworks/pci.d.ts.map +1 -0
- package/dist/frameworks/pci.js +201 -0
- package/dist/frameworks/soc2.d.ts +7 -0
- package/dist/frameworks/soc2.d.ts.map +1 -0
- package/dist/frameworks/soc2.js +248 -0
- package/dist/iac/drift-detector.d.ts +64 -0
- package/dist/iac/drift-detector.d.ts.map +1 -0
- package/dist/iac/drift-detector.js +134 -0
- package/dist/iac/index.d.ts +4 -0
- package/dist/iac/index.d.ts.map +1 -0
- package/dist/iac/index.js +19 -0
- package/dist/iac/rules.d.ts +17 -0
- package/dist/iac/rules.d.ts.map +1 -0
- package/dist/iac/rules.js +385 -0
- package/dist/iac/scanner.d.ts +104 -0
- package/dist/iac/scanner.d.ts.map +1 -0
- package/dist/iac/scanner.js +343 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/pii/data-flow.d.ts +58 -0
- package/dist/pii/data-flow.d.ts.map +1 -0
- package/dist/pii/data-flow.js +154 -0
- package/dist/pii/detector.d.ts +60 -0
- package/dist/pii/detector.d.ts.map +1 -0
- package/dist/pii/detector.js +267 -0
- package/dist/pii/index.d.ts +4 -0
- package/dist/pii/index.d.ts.map +1 -0
- package/dist/pii/index.js +19 -0
- package/dist/pii/patterns.d.ts +36 -0
- package/dist/pii/patterns.d.ts.map +1 -0
- package/dist/pii/patterns.js +108 -0
- package/dist/policy/index.d.ts +5 -0
- package/dist/policy/index.d.ts.map +1 -0
- package/dist/policy/index.js +20 -0
- package/dist/policy/opa-engine.d.ts +121 -0
- package/dist/policy/opa-engine.d.ts.map +1 -0
- package/dist/policy/opa-engine.js +423 -0
- package/package.json +31 -0
- package/src/audit/emitter.ts +383 -0
- package/src/audit/events.ts +351 -0
- package/src/audit/index.ts +35 -0
- package/src/audit/storage.ts +394 -0
- package/src/automation/__tests__/compliance-scheduler.test.ts +183 -0
- package/src/automation/audit-logger.ts +629 -0
- package/src/automation/compliance-scheduler-fixed.ts +0 -0
- package/src/automation/compliance-scheduler.ts +516 -0
- package/src/automation/dashboard.ts +947 -0
- package/src/automation/email-service.ts +230 -0
- package/src/automation/evidence-collector.ts +866 -0
- package/src/automation/index.ts +8 -0
- package/src/automation/pdf-exporter.ts +434 -0
- package/src/automation/reporting-engine.ts +462 -0
- package/src/container/index.ts +3 -0
- package/src/container/kubernetes.ts +379 -0
- package/src/container/rules.ts +244 -0
- package/src/container/scanner.ts +202 -0
- package/src/frameworks/engine.ts +298 -0
- package/src/frameworks/gdpr.ts +204 -0
- package/src/frameworks/hipaa.ts +209 -0
- package/src/frameworks/index.ts +23 -0
- package/src/frameworks/iso27001.ts +398 -0
- package/src/frameworks/nist.ts +518 -0
- package/src/frameworks/pci.ts +226 -0
- package/src/frameworks/soc2.ts +281 -0
- package/src/iac/drift-detector.ts +197 -0
- package/src/iac/index.ts +3 -0
- package/src/iac/rules.ts +420 -0
- package/src/iac/scanner.ts +445 -0
- package/src/index.ts +17 -0
- package/src/pii/data-flow.ts +216 -0
- package/src/pii/detector.ts +327 -0
- package/src/pii/index.ts +3 -0
- package/src/pii/patterns.ts +128 -0
- package/src/policy/index.ts +5 -0
- package/src/policy/opa-engine.ts +504 -0
|
@@ -0,0 +1,473 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.auditLogger = exports.AuditLogger = void 0;
|
|
4
|
+
const database_1 = require("@guardrail/database");
|
|
5
|
+
const crypto_1 = require("crypto");
|
|
6
|
+
/**
|
|
7
|
+
* Comprehensive Audit Trail Logger
|
|
8
|
+
*
|
|
9
|
+
* Provides tamper-proof logging of all compliance-related activities
|
|
10
|
+
* with chain of custody verification and evidence preservation
|
|
11
|
+
*/
|
|
12
|
+
class AuditLogger {
|
|
13
|
+
sequenceCounters = new Map();
|
|
14
|
+
/**
|
|
15
|
+
* Log an audit event
|
|
16
|
+
*/
|
|
17
|
+
async logEvent(event) {
|
|
18
|
+
// Generate unique ID if not provided
|
|
19
|
+
if (!event.id) {
|
|
20
|
+
event.id = `audit_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
21
|
+
}
|
|
22
|
+
// Get sequence number for ordering
|
|
23
|
+
const sequenceKey = event.projectId || 'global';
|
|
24
|
+
const sequenceNumber = (this.sequenceCounters.get(sequenceKey) || 0) + 1;
|
|
25
|
+
this.sequenceCounters.set(sequenceKey, sequenceNumber);
|
|
26
|
+
// Get previous hash for chain integrity
|
|
27
|
+
let previousHash = '';
|
|
28
|
+
try {
|
|
29
|
+
const previousEvent = await database_1.prisma.auditEvent.findFirst({
|
|
30
|
+
where: event.projectId ? { projectId: event.projectId } : {},
|
|
31
|
+
orderBy: { timestamp: 'desc' }
|
|
32
|
+
});
|
|
33
|
+
previousHash = previousEvent?.hash || '';
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
console.warn('Could not get previous audit event:', error);
|
|
37
|
+
}
|
|
38
|
+
// Calculate current hash
|
|
39
|
+
const currentHash = this.calculateHash({
|
|
40
|
+
...event,
|
|
41
|
+
sequenceNumber,
|
|
42
|
+
previousHash
|
|
43
|
+
});
|
|
44
|
+
// Store in database
|
|
45
|
+
await this.storeEvent({
|
|
46
|
+
...event,
|
|
47
|
+
sequenceNumber,
|
|
48
|
+
hash: currentHash,
|
|
49
|
+
previousHash: previousHash || null
|
|
50
|
+
});
|
|
51
|
+
// Also log to external systems for redundancy
|
|
52
|
+
await this.logToExternalSystems(event);
|
|
53
|
+
return event.id || '';
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Log compliance check start
|
|
57
|
+
*/
|
|
58
|
+
async logComplianceCheckStart(projectId, frameworkId, executionId, metadata) {
|
|
59
|
+
return this.logEvent({
|
|
60
|
+
type: 'compliance_check_started',
|
|
61
|
+
category: 'compliance',
|
|
62
|
+
projectId,
|
|
63
|
+
frameworkId,
|
|
64
|
+
timestamp: new Date(),
|
|
65
|
+
severity: 'low',
|
|
66
|
+
source: 'compliance-engine',
|
|
67
|
+
correlationId: executionId,
|
|
68
|
+
metadata: {
|
|
69
|
+
executionId,
|
|
70
|
+
...metadata
|
|
71
|
+
},
|
|
72
|
+
details: {
|
|
73
|
+
action: 'Compliance assessment initiated',
|
|
74
|
+
framework: frameworkId,
|
|
75
|
+
project: projectId
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Log compliance check completion
|
|
81
|
+
*/
|
|
82
|
+
async logComplianceCheckComplete(projectId, frameworkId, executionId, result, metadata) {
|
|
83
|
+
const severity = this.determineSeverity(result);
|
|
84
|
+
return this.logEvent({
|
|
85
|
+
type: 'compliance_check_completed',
|
|
86
|
+
category: 'compliance',
|
|
87
|
+
projectId,
|
|
88
|
+
frameworkId,
|
|
89
|
+
timestamp: new Date(),
|
|
90
|
+
severity,
|
|
91
|
+
source: 'compliance-engine',
|
|
92
|
+
correlationId: executionId,
|
|
93
|
+
metadata: {
|
|
94
|
+
executionId,
|
|
95
|
+
score: result.summary?.score,
|
|
96
|
+
compliant: result.summary?.compliant,
|
|
97
|
+
nonCompliant: result.summary?.nonCompliant,
|
|
98
|
+
...metadata
|
|
99
|
+
},
|
|
100
|
+
details: {
|
|
101
|
+
action: 'Compliance assessment completed',
|
|
102
|
+
framework: frameworkId,
|
|
103
|
+
project: projectId,
|
|
104
|
+
result: {
|
|
105
|
+
totalControls: result.summary?.totalControls,
|
|
106
|
+
score: result.summary?.score,
|
|
107
|
+
status: result.summary?.score >= 70 ? 'PASS' : 'FAIL'
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Log evidence collection
|
|
114
|
+
*/
|
|
115
|
+
async logEvidenceCollection(projectId, frameworkId, collectionId, artifactCount, metadata) {
|
|
116
|
+
return this.logEvent({
|
|
117
|
+
type: 'evidence_collected',
|
|
118
|
+
category: 'compliance',
|
|
119
|
+
projectId,
|
|
120
|
+
frameworkId,
|
|
121
|
+
timestamp: new Date(),
|
|
122
|
+
severity: 'low',
|
|
123
|
+
source: 'evidence-collector',
|
|
124
|
+
correlationId: collectionId,
|
|
125
|
+
metadata: {
|
|
126
|
+
collectionId,
|
|
127
|
+
artifactCount,
|
|
128
|
+
...metadata
|
|
129
|
+
},
|
|
130
|
+
details: {
|
|
131
|
+
action: 'Evidence artifacts collected',
|
|
132
|
+
artifactCount,
|
|
133
|
+
collectionId
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Log compliance violation
|
|
139
|
+
*/
|
|
140
|
+
async logViolation(projectId, frameworkId, controlId, violation, severity = 'high') {
|
|
141
|
+
return this.logEvent({
|
|
142
|
+
type: 'compliance_violation',
|
|
143
|
+
category: 'compliance',
|
|
144
|
+
projectId,
|
|
145
|
+
frameworkId,
|
|
146
|
+
timestamp: new Date(),
|
|
147
|
+
severity,
|
|
148
|
+
source: 'compliance-monitor',
|
|
149
|
+
metadata: {
|
|
150
|
+
controlId,
|
|
151
|
+
violation: violation.description,
|
|
152
|
+
recommendation: violation.recommendation
|
|
153
|
+
},
|
|
154
|
+
details: {
|
|
155
|
+
action: 'Compliance violation detected',
|
|
156
|
+
controlId,
|
|
157
|
+
violation: violation.description,
|
|
158
|
+
impact: violation.impact,
|
|
159
|
+
recommendation: violation.recommendation
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Log remediation action
|
|
165
|
+
*/
|
|
166
|
+
async logRemediation(projectId, frameworkId, controlId, action, userId) {
|
|
167
|
+
return this.logEvent({
|
|
168
|
+
type: 'remediation_performed',
|
|
169
|
+
category: 'compliance',
|
|
170
|
+
projectId,
|
|
171
|
+
frameworkId,
|
|
172
|
+
userId,
|
|
173
|
+
timestamp: new Date(),
|
|
174
|
+
severity: 'medium',
|
|
175
|
+
source: 'remediation-system',
|
|
176
|
+
metadata: {
|
|
177
|
+
controlId,
|
|
178
|
+
action
|
|
179
|
+
},
|
|
180
|
+
details: {
|
|
181
|
+
action: 'Compliance remediation performed',
|
|
182
|
+
controlId,
|
|
183
|
+
remediation: action,
|
|
184
|
+
performedBy: userId || 'system'
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Log access to compliance data
|
|
190
|
+
*/
|
|
191
|
+
async logAccess(projectId, userId, action, resource, metadata) {
|
|
192
|
+
return this.logEvent({
|
|
193
|
+
type: 'compliance_access',
|
|
194
|
+
category: 'access',
|
|
195
|
+
projectId,
|
|
196
|
+
userId,
|
|
197
|
+
timestamp: new Date(),
|
|
198
|
+
severity: 'low',
|
|
199
|
+
source: 'access-control',
|
|
200
|
+
metadata: {
|
|
201
|
+
action,
|
|
202
|
+
resource,
|
|
203
|
+
...metadata
|
|
204
|
+
},
|
|
205
|
+
details: {
|
|
206
|
+
action: 'Compliance data accessed',
|
|
207
|
+
resource,
|
|
208
|
+
performedBy: userId
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Query audit trail
|
|
214
|
+
*/
|
|
215
|
+
async query(query) {
|
|
216
|
+
// Build where clause
|
|
217
|
+
const where = {};
|
|
218
|
+
if (query.projectId)
|
|
219
|
+
where.projectId = query.projectId;
|
|
220
|
+
if (query.frameworkId)
|
|
221
|
+
where.frameworkId = query.frameworkId;
|
|
222
|
+
if (query.userId)
|
|
223
|
+
where.userId = query.userId;
|
|
224
|
+
if (query.type)
|
|
225
|
+
where.type = query.type;
|
|
226
|
+
if (query.category)
|
|
227
|
+
where.category = query.category;
|
|
228
|
+
if (query.severity)
|
|
229
|
+
where.severity = query.severity.toUpperCase();
|
|
230
|
+
if (query.startDate || query.endDate) {
|
|
231
|
+
where.timestamp = {};
|
|
232
|
+
if (query.startDate)
|
|
233
|
+
where.timestamp.gte = query.startDate;
|
|
234
|
+
if (query.endDate)
|
|
235
|
+
where.timestamp.lte = query.endDate;
|
|
236
|
+
}
|
|
237
|
+
// Get total count
|
|
238
|
+
let totalCount = 0;
|
|
239
|
+
try {
|
|
240
|
+
totalCount = await database_1.prisma.auditEvent.count({ where });
|
|
241
|
+
}
|
|
242
|
+
catch (error) {
|
|
243
|
+
console.warn('Could not count audit events:', error);
|
|
244
|
+
}
|
|
245
|
+
// Get events
|
|
246
|
+
let events = [];
|
|
247
|
+
try {
|
|
248
|
+
events = await database_1.prisma.auditEvent.findMany({
|
|
249
|
+
where,
|
|
250
|
+
orderBy: {
|
|
251
|
+
[query.orderBy || 'timestamp']: query.orderDirection || 'desc'
|
|
252
|
+
},
|
|
253
|
+
take: query.limit || 100,
|
|
254
|
+
skip: query.offset || 0
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
catch (error) {
|
|
258
|
+
console.warn('Could not fetch audit events:', error);
|
|
259
|
+
}
|
|
260
|
+
// Transform events
|
|
261
|
+
const auditEvents = events.map(e => ({
|
|
262
|
+
id: e.id,
|
|
263
|
+
type: e.type,
|
|
264
|
+
category: e.category.toLowerCase(),
|
|
265
|
+
projectId: e.projectId || undefined,
|
|
266
|
+
frameworkId: e.frameworkId || undefined,
|
|
267
|
+
userId: e.userId || undefined,
|
|
268
|
+
sessionId: e.sessionId || undefined,
|
|
269
|
+
timestamp: e.timestamp,
|
|
270
|
+
metadata: e.metadata,
|
|
271
|
+
details: e.details,
|
|
272
|
+
severity: e.severity.toLowerCase(),
|
|
273
|
+
source: e.source,
|
|
274
|
+
correlationId: e.correlationId || undefined,
|
|
275
|
+
ipAddress: e.ipAddress || undefined,
|
|
276
|
+
userAgent: e.userAgent || undefined
|
|
277
|
+
}));
|
|
278
|
+
// Generate summary
|
|
279
|
+
const summary = this.generateSummary(auditEvents);
|
|
280
|
+
return {
|
|
281
|
+
events: auditEvents,
|
|
282
|
+
summary,
|
|
283
|
+
metadata: {
|
|
284
|
+
hasMore: (query.offset || 0) + auditEvents.length < totalCount,
|
|
285
|
+
totalCount,
|
|
286
|
+
query
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Get audit trail for a specific time period
|
|
292
|
+
*/
|
|
293
|
+
async getAuditTrail(projectId, startDate, endDate) {
|
|
294
|
+
return this.query({
|
|
295
|
+
projectId,
|
|
296
|
+
startDate,
|
|
297
|
+
endDate,
|
|
298
|
+
orderBy: 'timestamp',
|
|
299
|
+
orderDirection: 'asc'
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Verify audit trail integrity
|
|
304
|
+
*/
|
|
305
|
+
async verifyIntegrity(projectId) {
|
|
306
|
+
let events = [];
|
|
307
|
+
try {
|
|
308
|
+
events = await database_1.prisma.auditEvent.findMany({
|
|
309
|
+
where: projectId ? { projectId } : {},
|
|
310
|
+
orderBy: { timestamp: 'asc' }
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
catch (error) {
|
|
314
|
+
console.warn('Could not verify integrity - audit events table not available:', error);
|
|
315
|
+
return {
|
|
316
|
+
valid: false,
|
|
317
|
+
totalEvents: 0,
|
|
318
|
+
violations: [{
|
|
319
|
+
eventId: 'N/A',
|
|
320
|
+
sequenceNumber: 0,
|
|
321
|
+
issue: 'Audit events table not available'
|
|
322
|
+
}]
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
const violations = [];
|
|
326
|
+
for (let i = 0; i < events.length; i++) {
|
|
327
|
+
const event = events[i];
|
|
328
|
+
// Check sequence continuity
|
|
329
|
+
if (i > 0 && (event.sequenceNumber || 0) !== (events[i - 1].sequenceNumber || 0) + 1) {
|
|
330
|
+
violations.push({
|
|
331
|
+
eventId: event.id,
|
|
332
|
+
sequenceNumber: event.sequenceNumber || 0,
|
|
333
|
+
issue: 'Sequence number gap'
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
// Check hash chain
|
|
337
|
+
if (i > 0) {
|
|
338
|
+
const expectedPreviousHash = events[i - 1].hash;
|
|
339
|
+
if (event.previousHash !== expectedPreviousHash) {
|
|
340
|
+
violations.push({
|
|
341
|
+
eventId: event.id,
|
|
342
|
+
sequenceNumber: event.sequenceNumber || 0,
|
|
343
|
+
issue: 'Hash chain broken'
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
// Verify hash integrity
|
|
348
|
+
const recalculatedHash = this.calculateHash({
|
|
349
|
+
id: event.id,
|
|
350
|
+
type: event.type,
|
|
351
|
+
category: event.category,
|
|
352
|
+
timestamp: event.timestamp,
|
|
353
|
+
sequenceNumber: event.sequenceNumber || 0,
|
|
354
|
+
previousHash: event.previousHash,
|
|
355
|
+
metadata: event.metadata,
|
|
356
|
+
details: event.details
|
|
357
|
+
});
|
|
358
|
+
if (recalculatedHash !== (event.hash || '')) {
|
|
359
|
+
violations.push({
|
|
360
|
+
eventId: event.id,
|
|
361
|
+
sequenceNumber: event.sequenceNumber || 0,
|
|
362
|
+
issue: 'Hash mismatch - possible tampering'
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
return {
|
|
367
|
+
valid: violations.length === 0,
|
|
368
|
+
totalEvents: events.length,
|
|
369
|
+
violations
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Store audit event in database
|
|
374
|
+
*/
|
|
375
|
+
async storeEvent(event) {
|
|
376
|
+
try {
|
|
377
|
+
await database_1.prisma.auditEvent.create({
|
|
378
|
+
data: {
|
|
379
|
+
id: event.id || '',
|
|
380
|
+
type: event.type,
|
|
381
|
+
category: event.category,
|
|
382
|
+
projectId: event.projectId,
|
|
383
|
+
// frameworkId not in schema
|
|
384
|
+
// frameworkId: event.frameworkId,
|
|
385
|
+
timestamp: event.timestamp,
|
|
386
|
+
// severity not in schema
|
|
387
|
+
// severity: event.severity,
|
|
388
|
+
// source not in schema
|
|
389
|
+
// source: event.source,
|
|
390
|
+
userId: event.userId,
|
|
391
|
+
metadata: event.metadata,
|
|
392
|
+
// recipients not in schema
|
|
393
|
+
// recipients: config.recipients as any,
|
|
394
|
+
// sequenceNumber not in schema
|
|
395
|
+
// sequenceNumber: event.sequenceNumber,
|
|
396
|
+
// hash not in schema
|
|
397
|
+
// hash: event.hash,
|
|
398
|
+
// previousHash not in schema
|
|
399
|
+
// previousHash: event.previousHash
|
|
400
|
+
}
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
catch (error) {
|
|
404
|
+
console.warn('Could not store audit event in database:', error);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* Calculate hash for event
|
|
409
|
+
*/
|
|
410
|
+
calculateHash(event) {
|
|
411
|
+
const hashInput = JSON.stringify({
|
|
412
|
+
id: event.id,
|
|
413
|
+
type: event.type,
|
|
414
|
+
category: event.category,
|
|
415
|
+
timestamp: event.timestamp,
|
|
416
|
+
sequenceNumber: event.sequenceNumber,
|
|
417
|
+
previousHash: event.previousHash,
|
|
418
|
+
metadata: event.metadata,
|
|
419
|
+
details: event.details
|
|
420
|
+
});
|
|
421
|
+
return (0, crypto_1.createHash)('sha256').update(hashInput).digest('hex');
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Determine severity based on compliance result
|
|
425
|
+
*/
|
|
426
|
+
determineSeverity(result) {
|
|
427
|
+
const score = result.summary?.score || 0;
|
|
428
|
+
if (score >= 90)
|
|
429
|
+
return 'low';
|
|
430
|
+
if (score >= 70)
|
|
431
|
+
return 'medium';
|
|
432
|
+
if (score >= 50)
|
|
433
|
+
return 'high';
|
|
434
|
+
return 'critical';
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* Log to external systems for redundancy
|
|
438
|
+
*/
|
|
439
|
+
async logToExternalSystems(event) {
|
|
440
|
+
// In production, integrate with:
|
|
441
|
+
// - SIEM systems (Splunk, ELK, etc.)
|
|
442
|
+
// - Cloud audit logs (AWS CloudTrail, Azure Monitor, etc.)
|
|
443
|
+
// - Immutable storage (WORM storage, blockchain)
|
|
444
|
+
// - External log aggregators
|
|
445
|
+
console.log(`[AUDIT] ${event.type}: ${event.category} - ${event.timestamp.toISOString()}`);
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Generate summary statistics
|
|
449
|
+
*/
|
|
450
|
+
generateSummary(events) {
|
|
451
|
+
const byType = {};
|
|
452
|
+
const byCategory = {};
|
|
453
|
+
const bySeverity = {};
|
|
454
|
+
for (const event of events) {
|
|
455
|
+
byType[event.type] = (byType[event.type] || 0) + 1;
|
|
456
|
+
byCategory[event.category] = (byCategory[event.category] || 0) + 1;
|
|
457
|
+
bySeverity[event.severity] = (bySeverity[event.severity] || 0) + 1;
|
|
458
|
+
}
|
|
459
|
+
return {
|
|
460
|
+
totalEvents: events.length,
|
|
461
|
+
byType,
|
|
462
|
+
byCategory,
|
|
463
|
+
bySeverity,
|
|
464
|
+
timeRange: {
|
|
465
|
+
start: events.length > 0 ? events[events.length - 1]?.timestamp || new Date() : new Date(),
|
|
466
|
+
end: events.length > 0 ? events[0]?.timestamp || new Date() : new Date()
|
|
467
|
+
}
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
exports.AuditLogger = AuditLogger;
|
|
472
|
+
// Export singleton instance
|
|
473
|
+
exports.auditLogger = new AuditLogger();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=compliance-scheduler-fixed.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compliance-scheduler-fixed.d.ts","sourceRoot":"","sources":["../../src/automation/compliance-scheduler-fixed.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
interface ComplianceSchedule {
|
|
2
|
+
id: string;
|
|
3
|
+
projectId: string;
|
|
4
|
+
frameworkId: string;
|
|
5
|
+
frequency: string;
|
|
6
|
+
enabled: boolean;
|
|
7
|
+
lastRun?: Date;
|
|
8
|
+
nextRun?: Date;
|
|
9
|
+
notifications?: {
|
|
10
|
+
email?: string[];
|
|
11
|
+
slack?: string;
|
|
12
|
+
webhook?: string;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
interface ComplianceExecutionResult {
|
|
16
|
+
scheduleId: string;
|
|
17
|
+
executionId: string;
|
|
18
|
+
startTime: Date;
|
|
19
|
+
endTime: Date;
|
|
20
|
+
status: "running" | "completed" | "failed";
|
|
21
|
+
result?: {
|
|
22
|
+
assessment?: any;
|
|
23
|
+
evidence?: any;
|
|
24
|
+
report?: any;
|
|
25
|
+
};
|
|
26
|
+
error?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Compliance Scheduler
|
|
30
|
+
*
|
|
31
|
+
* Manages scheduled compliance checks and notifications
|
|
32
|
+
*/
|
|
33
|
+
export declare class ComplianceScheduler {
|
|
34
|
+
private jobs;
|
|
35
|
+
private executions;
|
|
36
|
+
/**
|
|
37
|
+
* Initialize scheduler and load existing schedules
|
|
38
|
+
*/
|
|
39
|
+
initialize(): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Create or update a schedule
|
|
42
|
+
*/
|
|
43
|
+
upsertSchedule(schedule: Omit<ComplianceSchedule, "id" | "lastRun" | "nextRun">): Promise<string>;
|
|
44
|
+
/**
|
|
45
|
+
* Remove a schedule
|
|
46
|
+
*/
|
|
47
|
+
removeSchedule(projectId: string, frameworkId: string): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Run a compliance check
|
|
50
|
+
*/
|
|
51
|
+
runCheck(projectId: string, frameworkId: string, options?: {
|
|
52
|
+
collectEvidence?: boolean;
|
|
53
|
+
generateReport?: boolean;
|
|
54
|
+
notifyOnCompletion?: boolean;
|
|
55
|
+
}): Promise<ComplianceExecutionResult>;
|
|
56
|
+
/**
|
|
57
|
+
* Get execution status
|
|
58
|
+
*/
|
|
59
|
+
getExecutionStatus(executionId: string): ComplianceExecutionResult | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* Get all schedules
|
|
62
|
+
*/
|
|
63
|
+
getSchedules(projectId?: string): Promise<ComplianceSchedule[]>;
|
|
64
|
+
/**
|
|
65
|
+
* Schedule a job
|
|
66
|
+
*/
|
|
67
|
+
private scheduleJob;
|
|
68
|
+
/**
|
|
69
|
+
* Send notifications for completed checks
|
|
70
|
+
*/
|
|
71
|
+
private sendNotifications;
|
|
72
|
+
/**
|
|
73
|
+
* Validate cron expression
|
|
74
|
+
*/
|
|
75
|
+
private isValidCron;
|
|
76
|
+
/**
|
|
77
|
+
* Stop all jobs
|
|
78
|
+
*/
|
|
79
|
+
stopAll(): void;
|
|
80
|
+
}
|
|
81
|
+
export declare const complianceScheduler: ComplianceScheduler;
|
|
82
|
+
export {};
|
|
83
|
+
//# sourceMappingURL=compliance-scheduler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compliance-scheduler.d.ts","sourceRoot":"","sources":["../../src/automation/compliance-scheduler.ts"],"names":[],"mappings":"AAQA,UAAU,kBAAkB;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,IAAI,CAAC;IACf,OAAO,CAAC,EAAE,IAAI,CAAC;IACf,aAAa,CAAC,EAAE;QACd,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;QACjB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;CACH;AAED,UAAU,yBAAyB;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,IAAI,CAAC;IAChB,OAAO,EAAE,IAAI,CAAC;IACd,MAAM,EAAE,SAAS,GAAG,WAAW,GAAG,QAAQ,CAAC;IAC3C,MAAM,CAAC,EAAE;QACP,UAAU,CAAC,EAAE,GAAG,CAAC;QACjB,QAAQ,CAAC,EAAE,GAAG,CAAC;QACf,MAAM,CAAC,EAAE,GAAG,CAAC;KACd,CAAC;IACF,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;GAIG;AACH,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,IAAI,CAA0B;IACtC,OAAO,CAAC,UAAU,CAAgD;IAElE;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAUjC;;OAEG;IACG,cAAc,CAClB,QAAQ,EAAE,IAAI,CAAC,kBAAkB,EAAE,IAAI,GAAG,SAAS,GAAG,SAAS,CAAC,GAC/D,OAAO,CAAC,MAAM,CAAC;IA0ClB;;OAEG;IACG,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAoB3E;;OAEG;IACG,QAAQ,CACZ,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE;QACR,eAAe,CAAC,EAAE,OAAO,CAAC;QAC1B,cAAc,CAAC,EAAE,OAAO,CAAC;QACzB,kBAAkB,CAAC,EAAE,OAAO,CAAC;KAC9B,GACA,OAAO,CAAC,yBAAyB,CAAC;IA8ErC;;OAEG;IACH,kBAAkB,CAChB,WAAW,EAAE,MAAM,GAClB,yBAAyB,GAAG,SAAS;IAIxC;;OAEG;IACG,YAAY,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC;IAkBrE;;OAEG;YACW,WAAW;IA8DzB;;OAEG;YACW,iBAAiB;IAkL/B;;OAEG;IACH,OAAO,CAAC,WAAW;IAMnB;;OAEG;IACH,OAAO,IAAI,IAAI;CAMhB;AAGD,eAAO,MAAM,mBAAmB,qBAA4B,CAAC"}
|