File size: 30,947 Bytes
92aef33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Rapid IT Health Audit - ER Diagram</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>
    <style>
        .mermaid {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }
        .entity-card {
            transition: all 0.3s ease;
        }
        .entity-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
        }
        .prose ol {
            counter-reset: list-counter;
        }
        .prose ol li {
            position: relative;
            padding-left: 1.75em;
        }
        .prose ol li:before {
            content: counter(list-counter) ".";
            counter-increment: list-counter;
            position: absolute;
            left: 0;
            font-weight: 600;
            color: #4f46e5;
        }
        @media (max-width: 768px) {
            .mermaid {
                zoom: 0.7;
            }
        }
    </style>
</head>
<body class="bg-gray-50 min-h-screen">
    <div class="container mx-auto px-4 py-8">
        <header class="mb-12 text-center">
            <h1 class="text-4xl font-bold text-indigo-800 mb-2">Rapid IT Health Audit</h1>
            <p class="text-xl text-gray-600">Data Pipeline Entity Relationship Diagram</p>
            <div class="mt-6">
                <span class="inline-block bg-indigo-100 text-indigo-800 px-4 py-2 rounded-full text-sm font-medium">
                    SaaS Architecture
                </span>
            </div>
        </header>

        <div class="bg-white rounded-xl shadow-lg overflow-hidden mb-12">
            <div class="p-6 border-b border-gray-200">
                <h2 class="text-2xl font-semibold text-gray-800">Entity Relationship Diagram</h2>
                <p class="text-gray-600 mt-2">Visual representation of the core data model</p>
            </div>
            <div class="p-6 bg-gray-50">
                <div class="mermaid">
                    erDiagram
                    ASSET ||--o{ CONTROL : "has"
                    CONTROL ||--o{ EVIDENCE : "requires"
                    CONTROL ||--o{ COST_ITEM : "incurs"
                    CONTROL ||--o{ RISK : "mitigates"
                    
                    ASSET {
                        string asset_id PK
                        string name
                        string type
                        string location
                        string owner
                        date purchase_date
                        boolean is_critical
                    }
                    
                    CONTROL {
                        string control_id PK
                        string name
                        string description
                        string standard
                        string implementation_status
                        date last_review_date
                    }
                    
                    EVIDENCE {
                        string evidence_id PK
                        string control_id FK
                        string type
                        string file_path
                        date collection_date
                        string collected_by
                        boolean is_valid
                    }
                    
                    COST_ITEM {
                        string cost_id PK
                        string control_id FK
                        decimal amount
                        string currency
                        string category
                        date incurred_date
                        string justification
                    }
                    
                    RISK {
                        string risk_id PK
                        string control_id FK
                        string description
                        string impact
                        string likelihood
                        string mitigation_strategy
                        date identified_date
                    }
                </div>
            </div>
        </div>

        <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6 mb-12">
            <div class="entity-card bg-white rounded-lg shadow-md overflow-hidden hover:shadow-lg">
                <div class="bg-indigo-600 p-4">
                    <h3 class="text-white text-lg font-semibold">Asset</h3>
                </div>
                <div class="p-4">
                    <p class="text-gray-700 mb-4">Represents IT infrastructure components (hardware, software, network devices) that need to be audited.</p>
                    <div class="bg-gray-100 p-3 rounded">
                        <p class="text-sm font-medium text-gray-800">Fields:</p>
                        <ul class="text-xs text-gray-600 mt-1 space-y-1">
                            <li>asset_id (PK): string</li>
                            <li>name: string</li>
                            <li>type: string</li>
                            <li>location: string</li>
                            <li>owner: string</li>
                            <li>purchase_date: date</li>
                            <li>is_critical: boolean</li>
                        </ul>
                    </div>
                </div>
            </div>

            <div class="entity-card bg-white rounded-lg shadow-md overflow-hidden hover:shadow-lg">
                <div class="bg-green-600 p-4">
                    <h3 class="text-white text-lg font-semibold">Control</h3>
                </div>
                <div class="p-4">
                    <p class="text-gray-700 mb-4">Security controls or compliance measures applied to assets to mitigate risks and meet standards.</p>
                    <div class="bg-gray-100 p-3 rounded">
                        <p class="text-sm font-medium text-gray-800">Fields:</p>
                        <ul class="text-xs text-gray-600 mt-1 space-y-1">
                            <li>control_id (PK): string</li>
                            <li>name: string</li>
                            <li>description: string</li>
                            <li>standard: string</li>
                            <li>implementation_status: string</li>
                            <li>last_review_date: date</li>
                        </ul>
                    </div>
                </div>
            </div>

            <div class="entity-card bg-white rounded-lg shadow-md overflow-hidden hover:shadow-lg">
                <div class="bg-purple-600 p-4">
                    <h3 class="text-white text-lg font-semibold">Evidence</h3>
                </div>
                <div class="p-4">
                    <p class="text-gray-700 mb-4">Documentation proving that controls are properly implemented (screenshots, logs, config files).</p>
                    <div class="bg-gray-100 p-3 rounded">
                        <p class="text-sm font-medium text-gray-800">Fields:</p>
                        <ul class="text-xs text-gray-600 mt-1 space-y-1">
                            <li>evidence_id (PK): string</li>
                            <li>control_id (FK): string</li>
                            <li>type: string</li>
                            <li>file_path: string</li>
                            <li>collection_date: date</li>
                            <li>collected_by: string</li>
                            <li>is_valid: boolean</li>
                        </ul>
                    </div>
                </div>
            </div>

            <div class="entity-card bg-white rounded-lg shadow-md overflow-hidden hover:shadow-lg">
                <div class="bg-yellow-600 p-4">
                    <h3 class="text-white text-lg font-semibold">CostItem</h3>
                </div>
                <div class="p-4">
                    <p class="text-gray-700 mb-4">Financial aspects associated with implementing and maintaining controls.</p>
                    <div class="bg-gray-100 p-3 rounded">
                        <p class="text-sm font-medium text-gray-800">Fields:</p>
                        <ul class="text-xs text-gray-600 mt-1 space-y-1">
                            <li>cost_id (PK): string</li>
                            <li>control_id (FK): string</li>
                            <li>amount: decimal</li>
                            <li>currency: string</li>
                            <li>category: string</li>
                            <li>incurred_date: date</li>
                            <li>justification: string</li>
                        </ul>
                    </div>
                </div>
            </div>

            <div class="entity-card bg-white rounded-lg shadow-md overflow-hidden hover:shadow-lg">
                <div class="bg-red-600 p-4">
                    <h3 class="text-white text-lg font-semibold">Risk</h3>
                </div>
                <div class="p-4">
                    <p class="text-gray-700 mb-4">Potential threats or vulnerabilities that controls aim to mitigate.</p>
                    <div class="bg-gray-100 p-3 rounded">
                        <p class="text-sm font-medium text-gray-800">Fields:</p>
                        <ul class="text-xs text-gray-600 mt-1 space-y-1">
                            <li>risk_id (PK): string</li>
                            <li>control_id (FK): string</li>
                            <li>description: string</li>
                            <li>impact: string</li>
                            <li>likelihood: string</li>
                            <li>mitigation_strategy: string</li>
                            <li>identified_date: date</li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>

        <div class="bg-white rounded-xl shadow-lg overflow-hidden">
            <div class="p-6 border-b border-gray-200">
                <h2 class="text-2xl font-semibold text-gray-800">Relationship Summary</h2>
            </div>
            <div class="p-6">
                <div class="space-y-4">
                    <div class="flex items-start">
                        <div class="flex-shrink-0 h-10 w-10 rounded-full bg-indigo-100 flex items-center justify-center">
                            <span class="text-indigo-600 font-bold">1</span>
                        </div>
                        <div class="ml-4">
                            <h3 class="text-lg font-medium text-gray-900">Asset to Control</h3>
                            <p class="text-gray-600 mt-1">One-to-many relationship where each asset can have multiple controls applied to it (e.g., a server might have access controls, patch management, and monitoring controls).</p>
                        </div>
                    </div>
                    
                    <div class="flex items-start">
                        <div class="flex-shrink-0 h-10 w-10 rounded-full bg-green-100 flex items-center justify-center">
                            <span class="text-green-600 font-bold">2</span>
                        </div>
                        <div class="ml-4">
                            <h3 class="text-lg font-medium text-gray-900">Control to Evidence</h3>
                            <p class="text-gray-600 mt-1">One-to-many relationship where each control requires multiple pieces of evidence to demonstrate its proper implementation (e.g., firewall rules, access logs).</p>
                        </div>
                    </div>
                    
                    <div class="flex items-start">
                        <div class="flex-shrink-0 h-10 w-10 rounded-full bg-purple-100 flex items-center justify-center">
                            <span class="text-purple-600 font-bold">3</span>
                        </div>
                        <div class="ml-4">
                            <h3 class="text-lg font-medium text-gray-900">Control to CostItem</h3>
                            <p class="text-gray-600 mt-1">One-to-many relationship tracking the financial investment in each control (e.g., license costs, implementation hours, maintenance expenses).</p>
                        </div>
                    </div>
                    
                    <div class="flex items-start">
                        <div class="flex-shrink-0 h-10 w-10 rounded-full bg-red-100 flex items-center justify-center">
                            <span class="text-red-600 font-bold">4</span>
                        </div>
                        <div class="ml-4">
                            <h3 class="text-lg font-medium text-gray-900">Control to Risk</h3>
                            <p class="text-gray-600 mt-1">One-to-many relationship showing which risks each control mitigates, allowing for risk-based prioritization of control implementation.</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="bg-white rounded-xl shadow-lg overflow-hidden mt-12">
            <div class="p-6 border-b border-gray-200">
                <h2 class="text-2xl font-semibold text-gray-800">Automated Workflow</h2>
                <p class="text-gray-600 mt-2">Containerized data pipeline execution flow</p>
            </div>
            <div class="p-6">
                <div class="prose max-w-none">
                    <ol class="list-decimal pl-5 space-y-3">
                        <li><strong>Container Initialization</strong>: Docker container starts with temporary read-only credentials passed as environment variables</li>
                        <li><strong>Credential Validation</strong>: Verify all supplied credentials can establish basic API connections</li>
                        <li><strong>Parallel API Harvesting</strong>: Simultaneously collect data from all connected systems using their respective APIs</li>
                        <li><strong>JSON Normalization</strong>: Transform all collected data into standardized JSON format matching our data model</li>
                        <li><strong>Database Population</strong>: Upsert normalized data into Postgres tables (Asset, Control, Evidence, CostItem, Risk)</li>
                        <li><strong>Evidence Manifest Generation</strong>: Create CSV mapping each JSON evidence file to its associated Control record</li>
                        <li><strong>Log Finalization</strong>: Write execution summary and any errors to timestamped log file</li>
                    </ol>
                </div>

                <div class="mt-8 mermaid">
                    sequenceDiagram
                        participant Docker as Docker Container
                        participant Cloud as Cloud/SaaS APIs
                        participant Postgres as Postgres DB
                        
                        Docker->>Docker: Initialize with ENV credentials
                        Docker->>Cloud: Validate credentials
                        par Parallel Execution
                            Docker->>Cloud: Harvest API Data (Asset)
                            Docker->>Cloud: Harvest API Data (Control)
                            Docker->>Cloud: Harvest API Data (Evidence)
                        end
                        Docker->>Docker: Normalize JSON data
                        Docker->>Postgres: Upsert Asset records
                        Docker->>Postgres: Upsert Control records
                        Docker->>Postgres: Upsert related entities
                        Docker->>Docker: Generate evidence manifest (CSV)
                        Docker->>Docker: Write execution logs
                </div>
            </div>
        </div>

        <div class="bg-white rounded-xl shadow-lg overflow-hidden mt-12">
            <div class="p-6 border-b border-gray-200">
                <h2 class="text-2xl font-semibold text-gray-800">Compliance Data Serializers</h2>
                <p class="text-gray-600 mt-2">Transformations for standards and tool integrations</p>
            </div>
            <div class="p-6">
                <div class="prose max-w-none">
                    <h3 class="text-lg font-medium text-gray-900">OSCAL SSP JSON</h3>
                    <p>Mappings from core tables to NIST SP 800-53 controls:</p>
                    <pre class="bg-gray-100 p-4 rounded-md"><code>{
  "mappings": {
    "Control": {
      "control_id β†’ implemented-requirements/uuid",
      "name β†’ implemented-requirements/description",
      "standard β†’ implemented-requirements/control-id"
    },
    "Evidence": {
      "file_path β†’ implemented-requirements/links/href",
      "collection_date β†’ implemented-requirements/props/value"
    }
  },
  "required_namespaces": [
    "http://csrc.nist.gov/ns/oscal/1.0",
    "http://csrc.nist.gov/ns/oscal/metaschema/1.0"
  ],
  "example": {
    "system-security-plan": {
      "uuid": "a0e48328-...",
      "implemented-requirements": [{
        "uuid": "CTL-2024-001",
        "control-id": "AC-2",
        "description": "Server Access Control"
      }]
    }
  }
}</code></pre>

                    <h3 class="mt-6 text-lg font-medium text-gray-900">OpenControl YAML</h3>
                    <pre class="bg-gray-100 p-4 rounded-md"><code>mappings:
  Control:
    control_id: id
    name: name
    description: narrative
  Evidence:
    file_path: documentation
    collected_by: referenced_by
    collection_date: date

namespaces:
  - opencontrol/schemas/1.0.0

example: |
  standards:
    - name: NIST-800-53
      controls:
        - id: CTL-2024-001
          name: Patch Management
          narrative: "Ensures timely..."</code></pre>

                    <h3 class="mt-6 text-lg font-medium text-gray-900">CSV Bundles</h3>
                    <pre class="bg-gray-100 p-4 rounded-md"><code>Vanta/Drata CSV Mappings:
Asset:
  asset_id β†’ Device ID
  name β†’ Asset Name
  is_critical β†’ Critical (true/false)

Control:
  control_id β†’ Control ID
  implementation_status β†’ Status
  last_review_date β†’ Last Tested

Example:
Device ID,Asset Name,Critical
ASSET-001,Web Server,true</code></pre>

                    <h3 class="mt-6 text-lg font-medium text-gray-900">XBRL Cost Data</h3>
                    <pre class="bg-gray-100 p-4 rounded-md"><code>Mappings:
CostItem:
  amount β†’ xbrli:monetaryItemType
  currency β†’ iso4217:currency
  category β†’ audit:costCategory

Namespaces:
  - http://www.xbrl.org/2003/instance
  - http://www.xbrl.org/dtr/type/numeric

Example:
&lt;xbrl&gt;
  &lt;cost:cybersecurityCost 
    contextRef="current" 
    unitRef="USD" 
    decimals="2"&gt;45000&lt;/cost:cybersecurityCost&gt;
&lt;/xbrl&gt;</code></pre>
                </div>
            </div>
        </div>

        <div class="bg-white rounded-xl shadow-lg overflow-hidden mt-12">
            <div class="p-6 border-b border-gray-200">
                <h2 class="text-2xl font-semibold text-gray-800">Evidence Storage Automation</h2>
                <p class="text-gray-600 mt-2">Secure S3 bucket configuration with presigned URLs for auditor access</p>
            </div>
            <div class="p-6">
                <div class="prose max-w-none">
                    <h3 class="text-lg font-medium text-gray-900">Terraform S3 Configuration</h3>
                    <pre class="bg-gray-100 p-4 rounded-md"><code>resource "aws_s3_bucket" "evidence_store" {
  bucket = "audit-evidence-${var.account_id}"
  
  object_lock_configuration {
    object_lock_enabled = "Enabled"
  }

  lifecycle_rule {
    id      = "auto-expire"
    enabled = true
    expiration {
      days = 90
    }
  }
}

resource "aws_s3_bucket_policy" "read_only" {
  bucket = aws_s3_bucket.evidence_store.id
  policy = jsonencode({
    Version = "2012-10-17"
    Statement = [{
      Effect    = "Allow"
      Principal = {"AWS": "arn:aws:iam::${var.auditor_account_id}:root"}
      Action    = ["s3:GetObject"]
      Resource  = "${aws_s3_bucket.evidence_store.arn}/*"
    }]
  })
}</code></pre>

                    <h3 class="mt-6 text-lg font-medium text-gray-900">Python Upload Script</h3>
                    <pre class="bg-gray-100 p-4 rounded-md"><code>import boto3
from datetime import datetime, timedelta

def upload_evidence(file_path, control_id):
    s3 = boto3.client('s3')
    bucket = 'audit-evidence-123456789012'
    key = f"{control_id}/{datetime.now().isoformat()}_{file_path.split('/')[-1]}"
    
    # Upload file with object lock retention
    s3.upload_file(file_path, bucket, key, ExtraArgs={
        'ObjectLockMode': 'GOVERNANCE',
        'ObjectLockRetainUntilDate': datetime.now() + timedelta(days=90)
    })
    
    # Generate presigned URL
    url = s3.generate_presigned_url(
        'get_object',
        Params={'Bucket': bucket, 'Key': key},
        ExpiresIn=432000  # 5 days in seconds
    )
    return url</code></pre>

                    <h3 class="mt-6 text-lg font-medium text-gray-900">Auditor Access Process</h3>
                    <p>Auditors receive time-limited presigned URLs that:</p>
                    <ol class="list-decimal pl-5 space-y-2">
                        <li>Provide read-only access to specific evidence files</li>
                        <li>Automatically expire after 5 days to limit exposure</li>
                        <li>Don't require AWS credentials (works through URL signature)</li>
                        <li>Track which evidence was accessed via CloudTrail logs</li>
                    </ol>
                    <p class="mt-4 font-medium">Workflow:</p>
                    <ol class="list-decimal pl-5 space-y-2">
                        <li>System generates URL during evidence collection</li>
                        <li>URL gets embedded in compliance reports</li>
                        <li>Auditor clicks link to verify evidence directly</li>
                        <li>Access automatically revoked after expiration</li>
                    </ol>
                </div>
            </div>
        </div>

        <div class="bg-white rounded-xl shadow-lg overflow-hidden mt-12">
            <div class="p-6 border-b border-gray-200">
                <h2 class="text-2xl font-semibold text-gray-800">Serverless Data Collection Scheduler</h2>
                <p class="text-gray-600 mt-2">Automated 90-day refresh cycle with observability</p>
            </div>
            <div class="p-6">
                <div class="prose max-w-none">
                    <h3 class="text-lg font-medium text-gray-900">Terraform Configuration</h3>
                    <pre class="bg-gray-100 p-4 rounded-md"><code>resource "aws_cloudwatch_event_rule" "quarterly_audit" {
  name                = "quarterly-audit-data-collection"
  description         = "Triggers audit data collection every 90 days"
  schedule_expression = "rate(90 days)"
}

resource "aws_iam_role" "lambda_exec" {
  name = "audit-data-collector-lambda"

  assume_role_policy = jsonencode({
    Version = "2012-10-17"
    Statement = [{
      Action = "sts:AssumeRole"
      Effect = "Allow"
      Principal = {
        Service = "lambda.amazonaws.com"
      }
    }]
  })
}

resource "aws_iam_role_policy" "lambda_policy" {
  name = "least-privilege-audit-collector"
  role = aws_iam_role.lambda_exec.id

  policy = jsonencode({
    Version = "2012-10-17"
    Statement = [
      {
        Effect = "Allow"
        Action = [
          "logs:CreateLogGroup",
          "logs:CreateLogStream",
          "logs:PutLogEvents"
        ]
        Resource = "arn:aws:logs:*:*:*"
      },
      {
        Effect = "Allow"
        Action = [
          "cloudwatch:PutMetricData"
        ]
        Resource = "*"
      }
    ]
  })
}

resource "aws_lambda_function" "data_collector" {
  filename      = "data-collector.zip"
  function_name = "audit-data-collector"
  role          = aws_iam_role.lambda_exec.arn
  handler       = "lambda_function.lambda_handler"
  runtime       = "python3.9"
  timeout       = 900  # 15 minutes

  environment {
    variables = {
      DB_HOST     = var.database_host
      DB_PASSWORD = var.database_password
      OPENAI_KEY  = var.openai_key
    }
  }
}

resource "aws_cloudwatch_event_target" "trigger_lambda" {
  rule      = aws_cloudwatch_event_rule.quarterly_audit.name
  target_id = "TriggerLambda"
  arn       = aws_lambda_function.data_collector.arn
}

resource "aws_lambda_permission" "allow_cloudwatch" {
  statement_id  = "AllowExecutionFromCloudWatch"
  action        = "lambda:InvokeFunction"
  function_name = aws_lambda_function.data_collector.function_name
  principal     = "events.amazonaws.com"
  source_arn    = aws_cloudwatch_event_rule.quarterly_audit.arn
}</code></pre>

                    <h3 class="mt-6 text-lg font-medium text-gray-900">Python Lambda Function</h3>
                    <pre class="bg-gray-100 p-4 rounded-md"><code>import os
import boto3
from datetime import datetime
import psycopg2
import openai

cloudwatch = boto3.client('cloudwatch')

def lambda_handler(event, context):
    # Connect to database using env vars
    conn = psycopg2.connect(
        host=os.environ['DB_HOST'],
        database="audit",
        user="collector",
        password=os.environ['DB_PASSWORD']
    )
    
    try:
        start_time = datetime.now()
        
        # 1. Collect data from APIs
        collect_assets()
        collect_controls()
        
        # 2. Process with OpenAI for risk analysis
        analyze_risks()
        
        # 3. Publish metrics
        publish_metrics(
            duration=(datetime.now() - start_time).total_seconds(),
            assets_collected=100,  # example value
            controls_processed=50  # example value
        )
        
        return {"status": "success"}
    except Exception as e:
        publish_error_metric()
        raise e

def publish_metrics(duration, assets_collected, controls_processed):
    cloudwatch.put_metric_data(
        Namespace='AuditDataCollection',
        MetricData=[
            {
                'MetricName': 'ExecutionTime',
                'Value': duration,
                'Unit': 'Seconds'
            },
            {
                'MetricName': 'AssetsCollected',
                'Value': assets_collected,
                'Unit': 'Count'
            },
            {
                'MetricName': 'ControlsProcessed',
                'Value': controls_processed,
                'Unit': 'Count'
            }
        ]
    )

def publish_error_metric():
    cloudwatch.put_metric_data(
        Namespace='AuditDataCollection',
        MetricData=[{
            'MetricName': 'CollectionErrors',
            'Value': 1,
            'Unit': 'Count'
        }]
    )</code></pre>

                    <h3 class="mt-6 text-lg font-medium text-gray-900">Key CloudWatch Metrics</h3>
                    <ol class="list-decimal pl-5 space-y-2">
                        <li><strong>ExecutionTime</strong>: Duration of data collection in seconds</li>
                        <li><strong>AssetsCollected</strong>: Count of IT assets inventoried</li>
                        <li><strong>ControlsProcessed</strong>: Number of security controls evaluated</li>
                        <li><strong>CollectionErrors</strong>: Count of failed executions (alarm when >0)</li>
                        <li><strong>APICallLatency</strong>: Response times from external APIs</li>
                        <li><strong>RecordsProcessed</strong>: Total database records created/updated</li>
                    </ol>
                </div>
            </div>
        </div>

        <div class="bg-white rounded-xl shadow-lg overflow-hidden mt-12">
            <div class="p-6 border-b border-gray-200">
                <h2 class="text-2xl font-semibold text-gray-800">Control Failure Narrative Generator</h2>
                <p class="text-gray-600 mt-2">Template for converting failed controls into actionable insights</p>
            </div>
            <div class="p-6">
                <div class="prose max-w-none mb-6">
                    <h3 class="text-lg font-medium text-gray-900">Prompt Template:</h3>
                    <pre class="bg-gray-100 p-4 rounded-md"><code>Transform this failed control data into a concise risk narrative in JSON format:

1. Business Risk Summary: One sentence describing the business impact
2. Control Reference: Include the control_id
3. Actionable Fix: One practical recommendation (≀40 words)
4. Format: Strict JSON with keys summary, control_id, recommendation

Example Input:
{
  "control_name": "Server Patch Management",
  "control_id": "CTL-2024-001",
  "failure_details": "30% of servers missing critical security patches"
}

Required Output Format:
{
  "summary": "[business risk statement]",
  "control_id": "[control identifier]",
  "recommendation": "[concrete action item]"
}</code></pre>
                </div>

                <div class="prose max-w-none">
                    <h3 class="text-lg font-medium text-gray-900">Example Output:</h3>
                    <pre class="bg-gray-100 p-4 rounded-md"><code>{
  "summary": "Unpatched servers create vulnerabilities for ransomware attacks and data breaches",
  "control_id": "CTL-2024-001",
  "recommendation": "Deploy automated patching system with 72-hour SLA for critical updates"
}</code></pre>
                </div>
            </div>
        </div>

        <footer class="mt-12 text-center text-gray-500 text-sm">
            <p>Rapid IT Health Audit - Data Pipeline Model v1.0</p>
            <p class="mt-1">Β© 2023 SaaS Audit Solutions. All rights reserved.</p>
        </footer>
    </div>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            },
            er: {
                diagramPadding: 20,
                layoutDirection: 'TB',
                useMaxWidth: true
            }
        });
    </script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=clearpathit/clear-path-it" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>