@xdev-asia/xdev-knowledge-mcp 1.0.39 → 1.0.41
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/content/series/architecture/xay-dung-he-thong-y-te-microservices/chapters/01-phan-1-kien-truc-nen-tang/lessons/04-bai-4-threat-modeling-stride-dread.md +41 -52
- package/content/series/architecture/xay-dung-he-thong-y-te-microservices/chapters/02-phan-2-iam-keycloak/lessons/01-bai-5-setup-keycloak-realm-benh-vien.md +33 -84
- package/content/series/architecture/xay-dung-he-thong-y-te-microservices/chapters/02-phan-2-iam-keycloak/lessons/02-bai-6-phan-quyen-rbac-abac.md +6 -23
- package/content/series/architecture/xay-dung-he-thong-y-te-microservices/chapters/02-phan-2-iam-keycloak/lessons/03-bai-7-smart-on-fhir-oauth2-oidc.md +25 -36
- package/content/series/architecture/xay-dung-he-thong-y-te-microservices/chapters/02-phan-2-iam-keycloak/lessons/04-bai-8-mfa-passkeys-emergency-access.md +7 -23
- package/content/series/architecture/xay-dung-he-thong-y-te-microservices/chapters/03-phan-3-data-layer-postgresql/lessons/01-bai-9-postgresql-security-hardening.md +23 -69
- package/content/series/architecture/xay-dung-he-thong-y-te-microservices/chapters/03-phan-3-data-layer-postgresql/lessons/02-bai-10-ma-hoa-du-lieu-postgresql.md +25 -80
- package/content/series/architecture/xay-dung-he-thong-y-te-microservices/chapters/03-phan-3-data-layer-postgresql/lessons/03-bai-11-row-level-security-column-encryption.md +26 -55
- package/content/series/architecture/xay-dung-he-thong-y-te-microservices/chapters/03-phan-3-data-layer-postgresql/lessons/04-bai-12-audit-logging-cdc-pgaudit.md +51 -87
- package/content/series/architecture/xay-dung-he-thong-y-te-microservices/chapters/04-phan-4-microservices-quarkus/lessons/03-bai-15-ma-hoa-end-to-end-microservices.md +18 -63
- package/content/series/architecture/xay-dung-he-thong-y-te-microservices/chapters/04-phan-4-microservices-quarkus/lessons/04-bai-16-mtls-service-mesh.md +26 -88
- package/content/series/architecture/xay-dung-he-thong-y-te-microservices/chapters/05-phan-5-compliance-audit/lessons/01-bai-17-hipaa-technical-safeguards.md +50 -61
- package/content/series/architecture/xay-dung-he-thong-y-te-microservices/chapters/05-phan-5-compliance-audit/lessons/02-bai-18-audit-trail-opentelemetry-elk.md +11 -34
- package/content/series/architecture/xay-dung-he-thong-y-te-microservices/chapters/05-phan-5-compliance-audit/lessons/03-bai-19-data-masking-anonymization.md +113 -223
- package/content/series/architecture/xay-dung-he-thong-y-te-microservices/chapters/05-phan-5-compliance-audit/lessons/04-bai-20-backup-disaster-recovery.md +92 -149
- package/content/series/architecture/xay-dung-he-thong-y-te-microservices/chapters/06-phan-6-production-van-hanh/lessons/01-bai-21-zero-trust-architecture.md +126 -271
- package/content/series/architecture/xay-dung-he-thong-y-te-microservices/chapters/06-phan-6-production-van-hanh/lessons/02-bai-22-container-kubernetes-security.md +10 -52
- package/content/series/architecture/xay-dung-he-thong-y-te-microservices/chapters/06-phan-6-production-van-hanh/lessons/03-bai-23-penetration-testing.md +51 -90
- package/content/series/architecture/xay-dung-he-thong-y-te-microservices/chapters/06-phan-6-production-van-hanh/lessons/04-bai-24-capstone-deploy-production.md +137 -232
- package/data/settings.json +2 -1
- package/package.json +1 -1
|
@@ -23,37 +23,18 @@ course:
|
|
|
23
23
|
|
|
24
24
|

|
|
25
25
|
|
|
26
|
-
|
|
27
26
|
Dữ liệu y tế (PHI) yêu cầu mã hóa ở **hai trạng thái**: at-rest (khi lưu trữ) và in-transit (khi truyền). HIPAA Security Rule §164.312(a)(2)(iv) và §164.312(e)(2)(ii) quy định cụ thể về encryption requirements.
|
|
28
27
|
|
|
29
28
|
### 1.1. Encryption Layers
|
|
30
29
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
│ │ At-Rest Encryption │ │
|
|
40
|
-
│ │ │ │
|
|
41
|
-
│ │ Level 1: Full Disk Encryption (LUKS/dm-crypt) │ │
|
|
42
|
-
│ │ └── Bảo vệ khi disk bị đánh cắp │ │
|
|
43
|
-
│ │ │ │
|
|
44
|
-
│ │ Level 2: Transparent Data Encryption (TDE) │ │
|
|
45
|
-
│ │ └── Encrypt data files, WAL, temp files │ │
|
|
46
|
-
│ │ │ │
|
|
47
|
-
│ │ Level 3: Column-Level Encryption (pgcrypto) │ │
|
|
48
|
-
│ │ └── Encrypt từng field PHI riêng biệt │ │
|
|
49
|
-
│ │ │ │
|
|
50
|
-
│ │ Level 4: Application-Level Encryption │ │
|
|
51
|
-
│ │ └── Encrypt trước khi gửi tới database │ │
|
|
52
|
-
│ └─────────────────────────────────────────────────┘ │
|
|
53
|
-
│ │
|
|
54
|
-
│ Backup ──── Encrypted Backup ────► S3 (SSE-KMS) │
|
|
55
|
-
└─────────────────────────────────────────────────────────┘
|
|
56
|
-
```
|
|
30
|
+

|
|
31
|
+
|
|
32
|
+
- **In-Transit**: TLS 1.3 giữa Application và Database
|
|
33
|
+
- **At-Rest Level 1**: Full Disk Encryption (LUKS/dm-crypt) — bảo vệ khi disk bị đánh cắp
|
|
34
|
+
- **At-Rest Level 2**: Transparent Data Encryption (TDE) — encrypt data files, WAL, temp files
|
|
35
|
+
- **At-Rest Level 3**: Column-Level Encryption (pgcrypto) — encrypt từng field PHI riêng biệt
|
|
36
|
+
- **At-Rest Level 4**: Application-Level Encryption — encrypt trước khi gửi tới database
|
|
37
|
+
- **Backup**: Encrypted Backup → S3 (SSE-KMS)
|
|
57
38
|
|
|
58
39
|
### 1.2. So sánh các phương pháp mã hóa
|
|
59
40
|
|
|
@@ -490,35 +471,15 @@ public class SslVerificationService {
|
|
|
490
471
|
|
|
491
472
|
### 5.1. Vault Transit Secrets Engine
|
|
492
473
|
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
│ 1. Generate DEK │ │ │
|
|
503
|
-
│ (Data Encryption Key) │ │ │
|
|
504
|
-
│ │ │ │ │
|
|
505
|
-
│ 2. Encrypt data │ │ │
|
|
506
|
-
│ with DEK │ │ │
|
|
507
|
-
│ │ │ │ │
|
|
508
|
-
│ 3. ─── Encrypt DEK ──►│ │ │
|
|
509
|
-
│ │ │ 4. Wrap DEK │ │
|
|
510
|
-
│ │ │ with KEK ────►│ │
|
|
511
|
-
│ │ ◄── Wrapped ───│ │ │
|
|
512
|
-
│ │ DEK │ │ │
|
|
513
|
-
│ │ │ │ │
|
|
514
|
-
│ 5. Store encrypted │ │ │
|
|
515
|
-
│ data + wrapped DEK │ │ │
|
|
516
|
-
│ in PostgreSQL │ │ │
|
|
517
|
-
│ │
|
|
518
|
-
│ DEK = Data Encryption Key (per-record hoặc per-table) │
|
|
519
|
-
│ KEK = Key Encryption Key (master key trong Vault) │
|
|
520
|
-
└─────────────────────────────────────────────────────────┘
|
|
521
|
-
```
|
|
474
|
+

|
|
475
|
+
|
|
476
|
+
**Quy trình Envelope Encryption:**
|
|
477
|
+
|
|
478
|
+
1. Generate DEK (Data Encryption Key) — per-record hoặc per-table
|
|
479
|
+
2. Encrypt data with DEK
|
|
480
|
+
3. Gửi DEK tới Vault Transit để wrap
|
|
481
|
+
4. Vault wrap DEK với KEK (Key Encryption Key) qua HSM/KMS
|
|
482
|
+
5. Lưu encrypted data + wrapped DEK trong PostgreSQL
|
|
522
483
|
|
|
523
484
|
### 5.2. Vault Configuration
|
|
524
485
|
|
|
@@ -895,30 +856,13 @@ echo "Restore completed from: ${BACKUP_FILE}"
|
|
|
895
856
|
|
|
896
857
|
### 8.1. Quy trình Key Rotation
|
|
897
858
|
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
│ │ (active) │ (active) │ (active) │
|
|
906
|
-
│ │ │ │ │
|
|
907
|
-
│ │ Encrypt │ RE-encrypt │ RE-encrypt │
|
|
908
|
-
│ │ new data │ old data │ old data │
|
|
909
|
-
│ │ with v1 │ with v2 │ with v3 │
|
|
910
|
-
│ │ │ │ │
|
|
911
|
-
│ │ │ v1 still │ v1 retired │
|
|
912
|
-
│ │ │ can decrypt │ v2 can decrypt │
|
|
913
|
-
│ └──────────────┴──────────────┴─────────────────────│
|
|
914
|
-
│ │
|
|
915
|
-
│ Vault tự động: │
|
|
916
|
-
│ - Rotate KEK mỗi 90 ngày │
|
|
917
|
-
│ - OLD versions vẫn decrypt được │
|
|
918
|
-
│ - NEW data encrypt bằng latest version │
|
|
919
|
-
│ - Rewrap: re-encrypt DEK với new KEK version │
|
|
920
|
-
└─────────────────────────────────────────────────────┘
|
|
921
|
-
```
|
|
859
|
+

|
|
860
|
+
|
|
861
|
+
- **Day 0–90**: Key v1 active — encrypt new data
|
|
862
|
+
- **Day 90–180**: Key v2 active — re-encrypt old data, v1 vẫn decrypt được
|
|
863
|
+
- **Day 180+**: Key v3 active — v1 retired, v2 vẫn decrypt được
|
|
864
|
+
- Vault tự động rotate KEK, OLD versions vẫn decrypt, NEW data encrypt bằng latest
|
|
865
|
+
- **Rewrap**: re-encrypt DEK với new KEK version
|
|
922
866
|
|
|
923
867
|
### 8.2. Batch Re-encryption Script
|
|
924
868
|
|
|
@@ -1004,6 +948,7 @@ Trong bài học này, chúng ta đã triển khai **mã hóa toàn diện** cho
|
|
|
1004
948
|
9. **Key Rotation**: Automated DEK rewrapping khi KEK rotate
|
|
1005
949
|
|
|
1006
950
|
Nguyên tắc quan trọng:
|
|
951
|
+
|
|
1007
952
|
- **Never store encryption keys cùng với encrypted data**
|
|
1008
953
|
- **Always use authenticated encryption** (AES-GCM)
|
|
1009
954
|
- **Implement key rotation** với zero-downtime
|
|
@@ -23,7 +23,6 @@ course:
|
|
|
23
23
|
|
|
24
24
|

|
|
25
25
|
|
|
26
|
-
|
|
27
26
|
Row-Level Security (RLS) cho phép PostgreSQL kiểm soát **hàng nào** trong bảng mà user có thể nhìn thấy hoặc thao tác. Đây là tính năng critical cho healthcare vì:
|
|
28
27
|
|
|
29
28
|
- **Bác sĩ A** chỉ thấy bệnh nhân của mình
|
|
@@ -33,63 +32,35 @@ Row-Level Security (RLS) cho phép PostgreSQL kiểm soát **hàng nào** trong
|
|
|
33
32
|
|
|
34
33
|
### 1.1. RLS vs Application-Level Filtering
|
|
35
34
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
│ │
|
|
54
|
-
│ Ưu điểm: │
|
|
55
|
-
│ - Database enforce, không bypass được │
|
|
56
|
-
│ - Transparent cho application │
|
|
57
|
-
│ - Works với mọi tool (psql, reporting, BI) │
|
|
58
|
-
│ - Defense in depth layer │
|
|
59
|
-
└─────────────────────────────────────────────────────────┘
|
|
60
|
-
```
|
|
35
|
+

|
|
36
|
+
|
|
37
|
+
**Application-Level Filtering (KHÔNG AN TOÀN):**
|
|
38
|
+
|
|
39
|
+
- `SELECT * FROM patients WHERE doctor_id = :currentDoctor`
|
|
40
|
+
- Developer quên WHERE clause → data leak
|
|
41
|
+
- SQL injection bypass WHERE clause
|
|
42
|
+
- Direct DB access bypass application logic
|
|
43
|
+
- Reporting tools bypass application
|
|
44
|
+
|
|
45
|
+
**Row-Level Security (AN TOÀN):**
|
|
46
|
+
|
|
47
|
+
- `SELECT * FROM patients;` — Trả về CHỈ rows allowed
|
|
48
|
+
- Database enforce, không bypass được
|
|
49
|
+
- Transparent cho application
|
|
50
|
+
- Works với mọi tool (psql, reporting, BI)
|
|
51
|
+
- Defense in depth layer
|
|
61
52
|
|
|
62
53
|
### 1.2. RLS Architecture cho Healthcare
|
|
63
54
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
│ │ 2. SET LOCAL session variables │
|
|
74
|
-
│ │ SET LOCAL app.current_user_id = 'uuid'; │
|
|
75
|
-
│ │ SET LOCAL app.current_role = 'doctor'; │
|
|
76
|
-
│ │ SET LOCAL app.current_dept = 'cardiology'; │
|
|
77
|
-
│ │ SET LOCAL app.hospital_id = 'uuid'; │
|
|
78
|
-
│ │ │
|
|
79
|
-
│ │ 3. Execute query │
|
|
80
|
-
│ │ SELECT * FROM patients; │
|
|
81
|
-
│ ▼ │
|
|
82
|
-
│ PostgreSQL │
|
|
83
|
-
│ │ │
|
|
84
|
-
│ │ 4. RLS Policy evaluates │
|
|
85
|
-
│ │ current_setting('app.current_role') │
|
|
86
|
-
│ │ current_setting('app.current_dept') │
|
|
87
|
-
│ │ │
|
|
88
|
-
│ │ 5. Return ONLY allowed rows │
|
|
89
|
-
│ ▼ │
|
|
90
|
-
│ Results (filtered by RLS) │
|
|
91
|
-
└─────────────────────────────────────────────────────────┘
|
|
92
|
-
```
|
|
55
|
+

|
|
56
|
+
|
|
57
|
+
**Request Flow:**
|
|
58
|
+
|
|
59
|
+
1. **Quarkus App** — Extract JWT claims (user_id, role, department, hospital_id)
|
|
60
|
+
2. **SET LOCAL** session variables (`app.current_user_id`, `app.current_role`, `app.current_dept`, `app.hospital_id`)
|
|
61
|
+
3. **Execute query** — `SELECT * FROM patients;`
|
|
62
|
+
4. **PostgreSQL RLS Policy** evaluates `current_setting('app.current_role')`, `current_setting('app.current_dept')`
|
|
63
|
+
5. **Return ONLY allowed rows** — Results filtered by RLS
|
|
93
64
|
|
|
94
65
|
## 2. Thiết lập RLS cơ bản
|
|
95
66
|
|
|
@@ -23,61 +23,43 @@ course:
|
|
|
23
23
|
|
|
24
24
|

|
|
25
25
|
|
|
26
|
-
|
|
27
26
|
HIPAA Security Rule §164.312(b) yêu cầu **hardware, software, and/or procedural mechanisms that record and examine activity** trong hệ thống chứa ePHI. Audit logging không chỉ là compliance requirement mà còn là công cụ **phát hiện intrusion, forensics, và accountability**.
|
|
28
27
|
|
|
29
28
|
### 1.1. Audit Requirements cho Y Tế
|
|
30
29
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
│ - 6-year retention (HIPAA minimum) │
|
|
49
|
-
└─────────────────────────────────────────────────────────┘
|
|
50
|
-
```
|
|
30
|
+
| Yêu cầu | Mô tả |
|
|
31
|
+
|---------|--------|
|
|
32
|
+
| **WHO?** | User identity (Keycloak subject) |
|
|
33
|
+
| **WHAT?** | Action performed (SELECT, INSERT, UPDATE) |
|
|
34
|
+
| **WHEN?** | Timestamp (with timezone) |
|
|
35
|
+
| **WHERE?** | Source IP, application, service |
|
|
36
|
+
| **WHICH?** | Object accessed (table, column, row) |
|
|
37
|
+
| **HOW?** | Query text, parameters |
|
|
38
|
+
| **RESULT?** | Success/failure, rows affected |
|
|
39
|
+
|
|
40
|
+
**Yêu cầu bổ sung cho Healthcare:**
|
|
41
|
+
|
|
42
|
+
- PHI access tracking
|
|
43
|
+
- Break-the-glass audit
|
|
44
|
+
- Before/After values cho data changes
|
|
45
|
+
- Immutable audit trail (no tampering)
|
|
46
|
+
- 6-year retention (HIPAA minimum)
|
|
51
47
|
|
|
52
48
|
### 1.2. Audit Architecture
|
|
53
49
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
│ ┌────▼─────┐ │
|
|
68
|
-
│ │ Fluent │ │
|
|
69
|
-
│ │ Bit │ │
|
|
70
|
-
│ └────┬─────┘ │
|
|
71
|
-
│ │ │
|
|
72
|
-
│ ┌─────────┼─────────┐ │
|
|
73
|
-
│ │ │ │ │
|
|
74
|
-
│ ┌────▼───┐ ┌───▼────┐ ┌──▼──────┐ │
|
|
75
|
-
│ │OpenSear│ │ S3 │ │PostgreSQ│ │
|
|
76
|
-
│ │ch/ELK │ │Archive │ │L Audit │ │
|
|
77
|
-
│ │(Query) │ │(7 yrs) │ │DB │ │
|
|
78
|
-
│ └────────┘ └────────┘ └─────────┘ │
|
|
79
|
-
└─────────────────────────────────────────────────────────┘
|
|
80
|
-
```
|
|
50
|
+

|
|
51
|
+
|
|
52
|
+
**Audit Sources:**
|
|
53
|
+
|
|
54
|
+
- **Quarkus App Logs** → JSON logs
|
|
55
|
+
- **PostgreSQL pgAudit** → CSV/syslog
|
|
56
|
+
- **Debezium CDC** → Kafka events
|
|
57
|
+
|
|
58
|
+
**Pipeline:** Tất cả → **FluentBit** → phân phối tới:
|
|
59
|
+
|
|
60
|
+
- **OpenSearch/ELK** — Query & visualization
|
|
61
|
+
- **S3 Archive** — Lưu trữ 7 năm
|
|
62
|
+
- **PostgreSQL Audit DB** — Structured query
|
|
81
63
|
|
|
82
64
|
## 2. pgAudit - Installation & Configuration
|
|
83
65
|
|
|
@@ -179,6 +161,7 @@ SELECT * FROM patient_schema.patients;
|
|
|
179
161
|
```
|
|
180
162
|
|
|
181
163
|
Audit log output (CSV format):
|
|
164
|
+
|
|
182
165
|
```
|
|
183
166
|
2025-01-15 10:30:45.123 ICT [12345] user=app_patient_svc,db=healthcare_db,app=patient-service,client=10.0.1.10
|
|
184
167
|
AUDIT: SESSION,1,1,WRITE,INSERT,,patient_schema.patients,
|
|
@@ -240,6 +223,7 @@ ORDER BY relname;
|
|
|
240
223
|
## 4. Custom Audit Trigger Functions
|
|
241
224
|
|
|
242
225
|
pgAudit ghi lại **SQL statements**, nhưng không capture:
|
|
226
|
+
|
|
243
227
|
- **Before/After values** (old vs new data)
|
|
244
228
|
- **Application-level context** (JWT user, IP)
|
|
245
229
|
- **Business-level events** (who viewed which patient record)
|
|
@@ -524,38 +508,20 @@ $$ LANGUAGE plpgsql SECURITY DEFINER;
|
|
|
524
508
|
|
|
525
509
|
### 5.1. CDC Architecture
|
|
526
510
|
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
│ └────┬─────┘ │
|
|
542
|
-
│ │ JSON change events │
|
|
543
|
-
│ ▼ │
|
|
544
|
-
│ ┌──────────────────────────────────────────┐ │
|
|
545
|
-
│ │ Apache Kafka │ │
|
|
546
|
-
│ │ Topics: │ │
|
|
547
|
-
│ │ ├── healthcare.patient_schema.patients │ │
|
|
548
|
-
│ │ ├── healthcare.patient_schema.records │ │
|
|
549
|
-
│ │ └── healthcare.audit_schema.changes │ │
|
|
550
|
-
│ └────┬─────────────┬───────────┬───────────┘ │
|
|
551
|
-
│ │ │ │ │
|
|
552
|
-
│ ┌────▼───┐ ┌─────▼──┐ ┌────▼────┐ │
|
|
553
|
-
│ │OpenSear│ │ Audit │ │ Alert │ │
|
|
554
|
-
│ │ch Sink │ │ S3 │ │ Engine │ │
|
|
555
|
-
│ │Connect │ │Archive │ │(KSQL) │ │
|
|
556
|
-
│ └────────┘ └────────┘ └─────────┘ │
|
|
557
|
-
└─────────────────────────────────────────────────────────┘
|
|
558
|
-
```
|
|
511
|
+

|
|
512
|
+
|
|
513
|
+
**CDC Flow:**
|
|
514
|
+
|
|
515
|
+
1. **PostgreSQL WAL** — Write-Ahead Log (logical replication)
|
|
516
|
+
2. **Logical Decoding** → **Debezium Connector** (Kafka Connect Source)
|
|
517
|
+
3. **JSON change events** → **Apache Kafka** Topics:
|
|
518
|
+
- `healthcare.patient_schema.patients`
|
|
519
|
+
- `healthcare.patient_schema.records`
|
|
520
|
+
- `healthcare.audit_schema.changes`
|
|
521
|
+
4. **Consumers:**
|
|
522
|
+
- **OpenSearch Sink Connect** — Full-text search
|
|
523
|
+
- **Audit S3 Archive** — Long-term retention
|
|
524
|
+
- **Alert Engine (KSQL)** — Real-time anomaly detection
|
|
559
525
|
|
|
560
526
|
### 5.2. PostgreSQL Configuration cho CDC
|
|
561
527
|
|
|
@@ -1200,13 +1166,11 @@ Trong bài học này, chúng ta đã xây dựng **hệ thống Audit Logging t
|
|
|
1200
1166
|
9. **Monitoring**: Prometheus alerting cho replication lag, trigger health, access anomalies
|
|
1201
1167
|
|
|
1202
1168
|
Architecture tổng thể:
|
|
1203
|
-
|
|
1204
|
-
App Audit (Quarkus)
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
CDC (Debezium) ──► Kafka ──► KSQL (anomaly detection)
|
|
1209
|
-
```
|
|
1169
|
+
|
|
1170
|
+
- **App Audit (Quarkus)** → Kafka → OpenSearch (real-time query) + S3 (archive 7+ years)
|
|
1171
|
+
- **DB Audit (pgAudit)** → CSV → Fluent Bit → OpenSearch
|
|
1172
|
+
- **Custom Triggers** → `audit_schema` tables → Compliance Reports
|
|
1173
|
+
- **CDC (Debezium)** → Kafka → KSQL (anomaly detection)
|
|
1210
1174
|
|
|
1211
1175
|
## Bài tập
|
|
1212
1176
|
|
|
@@ -26,42 +26,14 @@ Trong hệ thống microservices y tế, dữ liệu PHI di chuyển qua **nhi
|
|
|
26
26
|
|
|
27
27
|
### 1.1. Encryption Architecture
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
│ │ JWT token validation │
|
|
38
|
-
│ ▼ │
|
|
39
|
-
│ Patient Service │
|
|
40
|
-
│ │ Field-level encryption (SSN, diagnosis) │
|
|
41
|
-
│ │ ┌─────────────────────┐ │
|
|
42
|
-
│ │ │ Vault Transit Engine │ ◄── Key Management │
|
|
43
|
-
│ │ │ (envelope encryption)│ Key Rotation │
|
|
44
|
-
│ │ └─────────────────────┘ │
|
|
45
|
-
│ │ │
|
|
46
|
-
│ ├──► PostgreSQL (encrypted columns stored) │
|
|
47
|
-
│ │ AES-256-GCM encrypted fields │
|
|
48
|
-
│ │ │
|
|
49
|
-
│ ├──► Kafka (encrypted messages) │
|
|
50
|
-
│ │ JWE (JSON Web Encryption) │
|
|
51
|
-
│ │ Custom Serializer/Deserializer │
|
|
52
|
-
│ │ │
|
|
53
|
-
│ └──► Lab Service (JWE payload) │
|
|
54
|
-
│ Decrypt with shared transit key │
|
|
55
|
-
│ │
|
|
56
|
-
│ ┌──────────────────────────────────────────────────────┐ │
|
|
57
|
-
│ │ HashiCorp Vault │ │
|
|
58
|
-
│ │ Transit Engine ──► Encryption keys │ │
|
|
59
|
-
│ │ KV Engine ──► Database credentials │ │
|
|
60
|
-
│ │ PKI Engine ──► TLS certificates │ │
|
|
61
|
-
│ │ Auto-unseal ──► Cloud KMS │ │
|
|
62
|
-
│ └──────────────────────────────────────────────────────┘ │
|
|
63
|
-
└─────────────────────────────────────────────────────────────┘
|
|
64
|
-
```
|
|
29
|
+

|
|
30
|
+
|
|
31
|
+
**Encryption Flow:**
|
|
32
|
+
|
|
33
|
+
- **Client** → **API Gateway**: TLS 1.3 (transport encryption) + JWT validation
|
|
34
|
+
- **Patient Service**: Field-level encryption (SSN, diagnosis) với Vault Transit Engine
|
|
35
|
+
- **Outputs**: PostgreSQL (AES-256-GCM encrypted columns), Kafka (JWE messages), Lab Service (JWE payload)
|
|
36
|
+
- **HashiCorp Vault**: Transit Engine (encryption keys), KV Engine (credentials), PKI Engine (TLS certs), Auto-unseal (Cloud KMS)
|
|
65
37
|
|
|
66
38
|
### 1.2. Encryption Layers
|
|
67
39
|
|
|
@@ -231,33 +203,15 @@ CREATE INDEX idx_blind_hash ON healthcare.patients_blind_index(field_name, blind
|
|
|
231
203
|
|
|
232
204
|
### 3.1. Envelope Encryption Pattern
|
|
233
205
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
│ │
|
|
244
|
-
│ ┌──────────┐ ┌───────────────┐ ┌──────────┐ │
|
|
245
|
-
│ │ Plaintext│ │ Vault Transit │ │ Database │ │
|
|
246
|
-
│ │ "SSN: │ │ │ │ │ │
|
|
247
|
-
│ │ 123..." │ │ KEK (master) │ │ encrypted│ │
|
|
248
|
-
│ └────┬─────┘ │ │ │ _data + │ │
|
|
249
|
-
│ │ │ wrap(DEK)→ │ │ wrapped │ │
|
|
250
|
-
│ ▼ │ wrapped_DEK │ │ _DEK │ │
|
|
251
|
-
│ DEK(random) │ │ │ │ │
|
|
252
|
-
│ │ │ unwrap( │ │ │ │
|
|
253
|
-
│ ▼ │ wrapped_DEK) │ │ │ │
|
|
254
|
-
│ AES-256-GCM │ → DEK │ │ │ │
|
|
255
|
-
│ encrypt │ │ │ │ │
|
|
256
|
-
│ │ └───────────────┘ └──────────┘ │
|
|
257
|
-
│ ▼ │
|
|
258
|
-
│ encrypted_data │
|
|
259
|
-
└─────────────────────────────────────────────────────────┘
|
|
260
|
-
```
|
|
206
|
+

|
|
207
|
+
|
|
208
|
+
**Quy trình:**
|
|
209
|
+
|
|
210
|
+
1. App generates random Data Encryption Key (DEK)
|
|
211
|
+
2. App encrypts plaintext with DEK (AES-256-GCM)
|
|
212
|
+
3. App sends DEK to Vault Transit for wrapping
|
|
213
|
+
4. Vault encrypts DEK with Key Encryption Key (KEK)
|
|
214
|
+
5. App stores: `encrypted_data` + `wrapped_DEK` trong database
|
|
261
215
|
|
|
262
216
|
### 3.2. Vault Transit Engine Setup
|
|
263
217
|
|
|
@@ -1200,6 +1154,7 @@ Trong bài học này, chúng ta đã xây dựng **End-to-End Encryption** toà
|
|
|
1200
1154
|
7. **PHI Masking**: Logging filter ngăn PHI leak vào logs, exception sanitization
|
|
1201
1155
|
|
|
1202
1156
|
Encryption landscape:
|
|
1157
|
+
|
|
1203
1158
|
```
|
|
1204
1159
|
Client ──[TLS 1.3]──► Gateway ──[TLS]──► Service
|
|
1205
1160
|
│
|