@xdev-asia/xdev-knowledge-mcp 1.0.39 → 1.0.40

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.
Files changed (20) hide show
  1. 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
  2. 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
  3. 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
  4. 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
  5. 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
  6. 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
  7. 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
  8. 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
  9. 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
  10. 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
  11. 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
  12. 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
  13. 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
  14. 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
  15. 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
  16. 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
  17. 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
  18. 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
  19. 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
  20. package/package.json +1 -1
@@ -203,25 +203,25 @@ public PatientSummaryDTO getPatient(@PathParam("id") UUID id) {
203
203
 
204
204
  #### D - Denial of Service
205
205
 
206
- ```
207
- Threat: Tấn công DDoS khiến hệ thống cấp cứu ngừng hoạt động
208
- ───────────────────────────────────────────────────────────
209
- Impact trong Y Tế:
210
- - Không thể tra cứu dị ứng thuốc → kê đơn sai → nguy hiểm
211
- - Không truy cập được lab results → chẩn đoán chậm
212
- - Hệ thống đặt lịch downbệnh nhân không thể đến khám
213
-
214
- Mitigations:
215
- ┌────────────────────────────────────────────┐
216
- │ M1: Rate limiting at API Gateway │
217
- │ M2: Circuit breaker (Quarkus Fault Toler.) │
218
- M3: Auto-scaling Kubernetes pods │
219
- M4: CDN/WAF (Cloudflare, AWS Shield)
220
- M5: Database connection pooling │
221
- M6: Fallback mode / offline capability │
222
- M7: Priority queuing for ER requests │
223
- └────────────────────────────────────────────┘
224
- ```
206
+ ![DoS mitigation — 7 lớp bảo vệ chống DDoS cho hệ thống y tế](/storage/uploads/2026/04/healthcare-stride-dos-mitigation.png)
207
+
208
+ **Threat:** Tấn công DDoS khiến hệ thống cấp cứu ngừng hoạt động
209
+
210
+ **Impact trong Y Tế:**
211
+
212
+ - Không thể tra cứu dị ứng thuốc đơn sai nguy hiểm
213
+ - Không truy cập được lab results → chẩn đoán chậm
214
+ - Hệ thống đặt lịch down → bệnh nhân không thể đến khám
215
+
216
+ **Mitigations:**
217
+
218
+ - **M1:** Rate limiting at API Gateway
219
+ - **M2:** Circuit breaker (Quarkus Fault Tolerance)
220
+ - **M3:** Auto-scaling Kubernetes pods
221
+ - **M4:** CDN/WAF (Cloudflare, AWS Shield)
222
+ - **M5:** Database connection pooling
223
+ - **M6:** Fallback mode / offline capability
224
+ - **M7:** Priority queuing for ER requests
225
225
 
226
226
  #### E - Elevation of Privilege
227
227
 
@@ -325,39 +325,28 @@ public class PrescriptionResource {
325
325
 
326
326
  ### 5.1. Attack Tree: Steal Patient Medical Records
327
327
 
328
- ```
329
- Goal: Steal Patient Medical Records
330
-
331
- ├── 1. External Attack
332
- │ ├── 1.1 Exploit Web Application
333
- │ │ ├── 1.1.1 SQL Injection [DREAD: 8.6] ★
334
- │ │ ├── 1.1.2 XSS to steal session [DREAD: 7.2]
335
- │ │ └── 1.1.3 IDOR to access other patients [DREAD: 7.0]
336
- │ │
337
- │ ├── 1.2 Compromise Authentication
338
- │ │ ├── 1.2.1 Credential stuffing [DREAD: 5.4]
339
- │ │ ├── 1.2.2 Phishing doctor credentials [DREAD: 6.8]
340
- │ │ └── 1.2.3 Brute force Keycloak [DREAD: 3.2]
341
- │ │
342
- │ └── 1.3 Network Attack
343
- │ ├── 1.3.1 MITM on API calls [DREAD: 4.6]
344
- │ └── 1.3.2 DNS spoofing [DREAD: 4.2]
345
-
346
- ├── 2. Internal Attack (Insider Threat)
347
- │ ├── 2.1 Privileged User Abuse
348
- │ │ ├── 2.1.1 DBA exports database [DREAD: 6.8]
349
- │ │ ├── 2.1.2 Admin disables audit [DREAD: 5.6]
350
- │ │ └── 2.1.3 Doctor accesses non-patient [DREAD: 6.0]
351
- │ │
352
- │ └── 2.2 Stolen Credentials
353
- │ ├── 2.2.1 Shared workstation session [DREAD: 6.2]
354
- │ └── 2.2.2 Post-it password [DREAD: 5.0]
355
-
356
- └── 3. Supply Chain Attack
357
- ├── 3.1 Compromised dependency [DREAD: 7.8]
358
- ├── 3.2 Malicious Docker image [DREAD: 6.4]
359
- └── 3.3 Compromised CI/CD pipeline [DREAD: 7.0]
360
- ```
328
+ ![Attack Tree — các vector tấn công đánh cắp hồ sơ bệnh nhân với DREAD scoring](/storage/uploads/2026/04/healthcare-attack-tree.png)
329
+
330
+ **Goal: Steal Patient Medical Records**
331
+
332
+ | Attack Path | DREAD | Priority |
333
+ |---|---|---|
334
+ | 1.1.1 SQL Injection | 8.6 | CRITICAL |
335
+ | 1.1.2 XSS to steal session | 7.2 | HIGH |
336
+ | 1.1.3 IDOR to access other patients | 7.0 | HIGH |
337
+ | 1.2.1 Credential stuffing | 5.4 | MEDIUM |
338
+ | 1.2.2 Phishing doctor credentials | 6.8 | HIGH |
339
+ | 1.2.3 Brute force Keycloak | 3.2 | LOW |
340
+ | 1.3.1 MITM on API calls | 4.6 | MEDIUM |
341
+ | 1.3.2 DNS spoofing | 4.2 | MEDIUM |
342
+ | 2.1.1 DBA exports database | 6.8 | HIGH |
343
+ | 2.1.2 Admin disables audit | 5.6 | MEDIUM |
344
+ | 2.1.3 Doctor accesses non-patient | 6.0 | MEDIUM |
345
+ | 2.2.1 Shared workstation session | 6.2 | MEDIUM |
346
+ | 2.2.2 Post-it password | 5.0 | MEDIUM |
347
+ | 3.1 Compromised dependency | 7.8 | HIGH |
348
+ | 3.2 Malicious Docker image | 6.4 | HIGH |
349
+ | 3.3 Compromised CI/CD pipeline | 7.0 | HIGH |
361
350
 
362
351
  ## 6. Từ Threat Model đến Security Requirements
363
352
 
@@ -26,46 +26,13 @@ course:
26
26
 
27
27
  Khi xây dựng hệ thống y tế cho nhiều bệnh viện/phòng khám, có 3 chiến lược:
28
28
 
29
- ```
30
- Strategy A: Realm per Hospital (Isolation cao)
31
- ┌───────────────────────────────────────────┐
32
- │ Keycloak Instance │
33
- │ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
34
- │ │ BV Chợ │ BV Bình │ BV Nhân │ │
35
- │ │ Rẫy │ Dân │ Dân 115 │ │
36
- │ │ Realm │ │ Realm │ │ Realm │ │
37
- │ └──────────┘ └──────────┘ └──────────┘ │
38
- │ → Isolated users, roles, clients │
39
- │ → Best for: Independent hospitals │
40
- └───────────────────────────────────────────┘
41
-
42
- Strategy B: Shared Realm + Organizations (Keycloak 26+)
43
- ┌───────────────────────────────────────────┐
44
- │ Keycloak Instance │
45
- │ ┌──────────────────────────────────────┐ │
46
- │ │ Healthcare Realm │ │
47
- │ │ ┌─────────┐ ┌─────────┐ ┌────────┐ │ │
48
- │ │ │ Org: │ │ Org: │ │ Org: │ │ │
49
- │ │ │ BV CR │ │ BV BD │ │ BV ND │ │ │
50
- │ │ └─────────┘ └─────────┘ └────────┘ │ │
51
- │ │ → Shared identity + org isolation │ │
52
- │ │ → Best for: Hospital networks │ │
53
- │ └──────────────────────────────────────┘ │
54
- └───────────────────────────────────────────┘
55
-
56
- Strategy C: Shared Realm + Groups (Simple)
57
- ┌───────────────────────────────────────────┐
58
- │ Keycloak Instance │
59
- │ ┌──────────────────────────────────────┐ │
60
- │ │ Healthcare Realm │ │
61
- │ │ Groups: /hospitals/bv-cho-ray │ │
62
- │ │ /hospitals/bv-binh-dan │ │
63
- │ │ /hospitals/bv-nhan-dan │ │
64
- │ │ → Simple, less isolation │ │
65
- │ │ → Best for: Small clinic networks │ │
66
- │ └──────────────────────────────────────┘ │
67
- └───────────────────────────────────────────┘
68
- ```
29
+ ![3 chiến lược Keycloak Multi-tenancy cho hệ thống đa bệnh viện](/storage/uploads/2026/04/healthcare-keycloak-multitenancy.png)
30
+
31
+ | Strategy | Mô hình | Isolation | Phù hợp |
32
+ |----------|---------|-----------|----------|
33
+ | **A: Realm per Hospital** | Mỗi bệnh viện 1 Realm riêng | Cao nhất — isolated users, roles, clients | Bệnh viện độc lập |
34
+ | **B: Shared Realm + Organizations** | 1 Healthcare Realm, mỗi BV là 1 Organization | Trung bình — shared identity + org isolation | Chuỗi bệnh viện, Sở Y tế |
35
+ | **C: Shared Realm + Groups** | 1 Realm, phân chia bằng Groups | Thấp — simple, less isolation | Phòng khám nhỏ |
69
36
 
70
37
  ### 1.2. Khuyến nghị cho Y Tế Việt Nam
71
38
 
@@ -143,29 +110,23 @@ Strategy C: Shared Realm + Groups (Simple)
143
110
 
144
111
  ### 3.1. Clients Overview
145
112
 
146
- ```
147
- ┌─────────────────────────────────────────────────────┐
148
- │ Healthcare Keycloak Clients │
149
- ├─────────────────────┬───────────────────────────────┤
150
- Client │ Type │ Description │
151
- ├─────────────────────┼─────────────┼─────────────────┤
152
- his-web-app │ Public │ HIS Web Frontend
153
- emr-web-app │ Public │ EMR Web Frontend
154
- patient-portal │ Public │ Patient Portal │
155
- mobile-doctor-app │ Public │ Doctor Mobile App│
156
- patient-service Confidential Patient API
157
- clinical-service Confidential Clinical API
158
- lab-service Confidential Lab Results API │
159
- pharmacy-service Confidential Pharmacy API │
160
- scheduling-service │ Confidential Scheduling API │
161
- billing-service │ Confidential Billing API │
162
- notification-service│ Confidential Notifications │
163
- │ audit-service │ Confidential│ Audit/Logging │
164
- │ api-gateway │ Confidential│ Kong/APISIX │
165
- │ admin-cli │ Confidential│ Admin Operations │
166
- │ fhir-server │ Confidential│ HAPI FHIR Server │
167
- └─────────────────────┴─────────────┴─────────────────┘
168
- ```
113
+ | Client | Type | Description |
114
+ |--------|------|-------------|
115
+ | his-web-app | Public | HIS Web Frontend |
116
+ | emr-web-app | Public | EMR Web Frontend |
117
+ | patient-portal | Public | Patient Portal |
118
+ | mobile-doctor-app | Public | Doctor Mobile App |
119
+ | patient-service | Confidential | Patient API |
120
+ | clinical-service | Confidential | Clinical API |
121
+ | lab-service | Confidential | Lab Results API |
122
+ | pharmacy-service | Confidential | Pharmacy API |
123
+ | scheduling-service | Confidential | Scheduling API |
124
+ | billing-service | Confidential | Billing API |
125
+ | notification-service | Confidential | Notifications |
126
+ | audit-service | Confidential | Audit/Logging |
127
+ | api-gateway | Confidential | Kong/APISIX |
128
+ | admin-cli | Confidential | Admin Operations |
129
+ | fhir-server | Confidential | HAPI FHIR Server |
169
130
 
170
131
  ### 3.2. Patient Portal Client (Public)
171
132
 
@@ -400,27 +361,15 @@ Realm Roles:
400
361
 
401
362
  ### 6.2. Shared Workstation Support
402
363
 
403
- ```
404
- Bệnh viện thường có shared workstations — nhiều bác sĩ/y tá
405
- dùng chung 1 máy tính. Giải pháp:
406
-
407
- ┌──────────────────────────────────────────────┐
408
- │ Option 1: Fast User Switching │
409
- Keycloak short session + badge login
410
- Pro: Nhanh, tiện lợi │
411
- Con: Cần infrastructure (badge reader) │
412
- ├──────────────────────────────────────────────┤
413
- │ Option 2: Auto-logoff + Quick re-auth │
414
- │ → Session timeout 10-15 min + PIN │
415
- │ → Pro: Simple, no hardware needed │
416
- │ → Con: Slower than badge │
417
- ├──────────────────────────────────────────────┤
418
- │ Option 3: Virtual Desktop (VDI) │
419
- │ → Each user has own virtual desktop │
420
- │ → Pro: Full isolation │
421
- │ → Con: Expensive, higher latency │
422
- └──────────────────────────────────────────────┘
423
- ```
364
+ Bệnh viện thường có shared workstations — nhiều bác sĩ/y tá dùng chung 1 máy tính. Giải pháp:
365
+
366
+ ![3 phương án xác thực trên shared workstation bệnh viện](/storage/uploads/2026/04/healthcare-shared-workstation-auth.png)
367
+
368
+ | Option | Cơ chế | Ưu điểm | Hạn chế |
369
+ |--------|---------|---------|----------|
370
+ | **1. Fast User Switching** | Keycloak short session + badge login | Nhanh, tiện lợi | Cần infrastructure (badge reader) |
371
+ | **2. Auto-logoff + Quick re-auth** | Session timeout 10-15 min + PIN | Simple, no hardware needed | Chậm hơn badge |
372
+ | **3. Virtual Desktop (VDI)** | Mỗi user 1 virtual desktop riêng | Full isolation | Đắt, higher latency |
424
373
 
425
374
  ## 7. Realm Export/Import Automation
426
375
 
@@ -23,7 +23,6 @@ course:
23
23
 
24
24
  ![Kiến trúc 4 lớp kiểm soát truy cập: RBAC, ABAC, RLS, Patient Consent](/storage/uploads/2026/04/healthcare-rbac-abac-layers.png)
25
25
 
26
-
27
26
  ### 1.1. Role-Based Access Control (RBAC)
28
27
 
29
28
  RBAC gán quyền dựa trên **vai trò** của người dùng trong tổ chức:
@@ -58,28 +57,12 @@ Policy: ALLOW if
58
57
 
59
58
  ### 1.3. Kết hợp RBAC + ABAC cho Y Tế
60
59
 
61
- ```
62
- ┌──────────────────────────────────────────────────────┐
63
- │ Healthcare Access Decision │
64
- │ │
65
- Layer 1: RBAC (Keycloak Roles)
66
- │ ├── Is user a doctor? Can access clinical data │
67
- │ ├── Is user a nurse? → Can access vital signs │
68
- │ └── Is user a patient? → Can access own records │
69
- │ │
70
- │ Layer 2: ABAC (Keycloak Authorization Services) │
71
- │ ├── Department match? → Only own department data │
72
- │ ├── Treatment relationship? → Assigned patients only │
73
- │ ├── Time-based? → After-hours requires MFA │
74
- │ └── Location-based? → External requires VPN │
75
- │ │
76
- │ Layer 3: RLS (PostgreSQL Row-Level Security) │
77
- │ └── Database enforces per-row access based on JWT │
78
- │ │
79
- │ Layer 4: Consent (Patient consent check) │
80
- │ └── Patient has granted access for this purpose? │
81
- └──────────────────────────────────────────────────────┘
82
- ```
60
+ | Layer | Tên | Cơ chế | Ví dụ |
61
+ |-------|-----|---------|--------|
62
+ | **Layer 1** | RBAC (Keycloak Roles) | Is user a doctor? → Can access clinical data. Is user a nurse? → Can access vital signs. Is user a patient? → Can access own records. | `@RolesAllowed("doctor")` |
63
+ | **Layer 2** | ABAC (Keycloak Authorization Services) | Department match? → Only own department data. Treatment relationship? → Assigned patients only. Time-based? → After-hours requires MFA. Location-based? → External requires VPN. | Custom policies |
64
+ | **Layer 3** | RLS (PostgreSQL Row-Level Security) | Database enforces per-row access based on JWT claims | `CREATE POLICY` |
65
+ | **Layer 4** | Consent (Patient consent check) | Patient has granted access for this purpose? | FHIR Consent resource |
83
66
 
84
67
  ## 2. Keycloak Authorization Services
85
68
 
@@ -23,7 +23,6 @@ course:
23
23
 
24
24
  ![SMART on FHIR Launch Flow — OAuth2/OIDC qua Keycloak cho EHR](/storage/uploads/2026/04/healthcare-smart-fhir-launch-flow.png)
25
25
 
26
-
27
26
  ### 1.1. SMART là gì?
28
27
 
29
28
  **SMART (Substitutable Medical Applications, Reusable Technologies)** on FHIR là một tiêu chuẩn mở cho phép các ứng dụng third-party truy cập dữ liệu y tế một cách an toàn thông qua FHIR APIs. SMART định nghĩa:
@@ -35,41 +34,31 @@ course:
35
34
 
36
35
  ### 1.2. SMART App Launch Flows
37
36
 
38
- ```
39
- ┌──────────────────────────────────────────────────────┐
40
- │ EHR Launch Flow │
41
- │ │
42
- │ 1. User clicks "Launch App" in EHR │
43
- │ 2. EHR sends launch request with context │
44
- │ (patient ID, encounter ID) │
45
- │ 3. App redirects to Authorization Server (Keycloak) │
46
- │ 4. User authenticates (or SSO) │
47
- 5. Keycloak issues access token with SMART scopes │
48
- │ 6. App uses token to access FHIR resources │
49
- └──────────────────────────────────────────────────────┘
50
-
51
- ┌──────────────────────────────────────────────────────┐
52
- │ Standalone Launch Flow │
53
- │ │
54
- │ 1. User opens app directly (e.g., mobile app) │
55
- │ 2. App redirects to Keycloak for authentication │
56
- │ 3. User authenticates with credentials + MFA │
57
- 4. App requests SMART scopes │
58
- │ 5. If patient context needed → patient picker │
59
- │ 6. Keycloak issues access token │
60
- │ 7. App accesses FHIR resources │
61
- └──────────────────────────────────────────────────────┘
62
-
63
- ┌──────────────────────────────────────────────────────┐
64
- │ Backend Services Authorization │
65
- │ │
66
- │ 1. Service authenticates with signed JWT assertion │
67
- │ 2. Keycloak validates JWT and issues access token │
68
- │ 3. Service accesses FHIR resources │
69
- │ → No user interaction required │
70
- │ → Used for: data sync, analytics, reporting │
71
- └──────────────────────────────────────────────────────┘
72
- ```
37
+ **EHR Launch Flow:**
38
+
39
+ 1. User clicks "Launch App" in EHR
40
+ 2. EHR sends launch request with context (patient ID, encounter ID)
41
+ 3. App redirects to Authorization Server (Keycloak)
42
+ 4. User authenticates (or SSO)
43
+ 5. Keycloak issues access token with SMART scopes
44
+ 6. App uses token to access FHIR resources
45
+
46
+ **Standalone Launch Flow:**
47
+
48
+ 1. User opens app directly (e.g., mobile app)
49
+ 2. App redirects to Keycloak for authentication
50
+ 3. User authenticates with credentials + MFA
51
+ 4. App requests SMART scopes
52
+ 5. If patient context needed → patient picker
53
+ 6. Keycloak issues access token
54
+ 7. App accesses FHIR resources
55
+
56
+ **Backend Services Authorization:**
57
+
58
+ 1. Service authenticates with signed JWT assertion
59
+ 2. Keycloak validates JWT and issues access token
60
+ 3. Service accesses FHIR resources
61
+ → No user interaction required. Used for: data sync, analytics, reporting.
73
62
 
74
63
  ## 2. SMART Scopes
75
64
 
@@ -23,7 +23,6 @@ course:
23
23
 
24
24
  ![Ma trận MFA cho nhân viên y tế — Passkeys, TOTP, Emergency Access](/storage/uploads/2026/04/healthcare-mfa-decision-matrix.png)
25
25
 
26
-
27
26
  ### 1.1. Thách thức MFA trong Bệnh viện
28
27
 
29
28
  Bệnh viện có môi trường vận hành đặc biệt so với doanh nghiệp thông thường:
@@ -38,28 +37,13 @@ Bệnh viện có môi trường vận hành đặc biệt so với doanh nghi
38
37
 
39
38
  ### 1.2. MFA Factor Matrix
40
39
 
41
- ```
42
- ┌──────────────────────────────────────────────────────────┐
43
- │ Healthcare MFA Decision Matrix │
44
- ├──────────────┬───────────┬────────────┬──────────────────┤
45
- User Type │ Primary │ Secondary │ Fallback │
46
- ├──────────────┼───────────┼────────────┼──────────────────┤
47
- Doctor │ Passkey/ │ TOTP App │ Recovery codes │
48
- │ │ WebAuthn │ │ │
49
- ├──────────────┼───────────┼────────────┼──────────────────┤
50
- │ Nurse │ Proximity │ PIN (6 │ TOTP App │
51
- │ │ Badge │ digits) │ │
52
- ├──────────────┼───────────┼────────────┼──────────────────┤
53
- │ Lab Tech │ TOTP App │ Security │ Recovery codes │
54
- │ │ │ Key │ │
55
- ├──────────────┼───────────┼────────────┼──────────────────┤
56
- │ Admin │ Security │ TOTP App │ Admin recovery │
57
- │ │ Key │ │ procedure │
58
- ├──────────────┼───────────┼────────────┼──────────────────┤
59
- │ Patient │ SMS OTP │ Email OTP │ Support call │
60
- │ Portal │ │ │ │
61
- └──────────────┴───────────┴────────────┴──────────────────┘
62
- ```
40
+ | User Type | Primary | Secondary | Fallback |
41
+ |-----------|---------|-----------|----------|
42
+ | **Doctor** | Passkey / WebAuthn | TOTP App | Recovery codes |
43
+ | **Nurse** | Proximity Badge | PIN (6 digits) | TOTP App |
44
+ | **Lab Tech** | TOTP App | Security Key | Recovery codes |
45
+ | **Admin** | Security Key | TOTP App | Admin recovery procedure |
46
+ | **Patient Portal** | SMS OTP | Email OTP | Support call |
63
47
 
64
48
  ## 2. Keycloak Authentication Flow cho Y Tế
65
49
 
@@ -26,30 +26,17 @@ PostgreSQL là lựa chọn phổ biến cho hệ thống y tế nhờ tính lin
26
26
 
27
27
  ### 1.1. Các lớp bảo mật PostgreSQL
28
28
 
29
- ```
30
- ┌─────────────────────────────────────────────────────┐
31
- │ Application Layer
32
- │ Quarkus / Spring Boot + Connection Pool │
33
- ├─────────────────────────────────────────────────────┤
34
- Network Layer │
35
- │ Firewall Rules + VPN/Private Network │
36
- ├─────────────────────────────────────────────────────┤
37
- │ Authentication Layer │
38
- │ pg_hba.conf + SSL/TLS + Client Certificates │
39
- ├─────────────────────────────────────────────────────┤
40
- │ Authorization Layer │
41
- │ Roles + Privileges + Row-Level Security │
42
- ├─────────────────────────────────────────────────────┤
43
- │ Encryption Layer │
44
- │ TDE + Column Encryption + Backup Encryption │
45
- ├─────────────────────────────────────────────────────┤
46
- │ Audit Layer │
47
- │ pgAudit + Custom Triggers + Log Shipping │
48
- ├─────────────────────────────────────────────────────┤
49
- │ Operating System Layer │
50
- │ File Permissions + SELinux/AppArmor │
51
- └─────────────────────────────────────────────────────┘
52
- ```
29
+ ![7 lớp bảo mật PostgreSQL — từ Application đến OS Layer](/storage/uploads/2026/04/healthcare-postgresql-security-layers.png)
30
+
31
+ | Layer | Tên | Thành phần |
32
+ |-------|-----|------------|
33
+ | 7 | Application | Quarkus / Spring Boot + Connection Pool |
34
+ | 6 | Network | Firewall Rules + VPN/Private Network |
35
+ | 5 | Authentication | pg_hba.conf + SSL/TLS + Client Certificates |
36
+ | 4 | Authorization | Roles + Privileges + Row-Level Security |
37
+ | 3 | Encryption | TDE + Column Encryption + Backup Encryption |
38
+ | 2 | Audit | pgAudit + Custom Triggers + Log Shipping |
39
+ | 1 | Operating System | File Permissions + SELinux/AppArmor |
53
40
 
54
41
  ### 1.2. Checklist bảo mật cần hoàn thành
55
42
 
@@ -145,7 +132,8 @@ hostssl all all 0.0.0.0/0 reject
145
132
  sudo -u postgres psql
146
133
  ```
147
134
 
148
- **Rule 4 - `hostssl` + `scram-sha-256`**:
135
+ **Rule 4 - `hostssl` + `scram-sha-256`**:
136
+
149
137
  - `hostssl` = bắt buộc SSL/TLS
150
138
  - `scram-sha-256` = password hashing mạnh nhất PostgreSQL hỗ trợ
151
139
 
@@ -273,28 +261,13 @@ WHERE usename IS NOT NULL;
273
261
 
274
262
  ### 4.1. Nguyên tắc Least Privilege cho Healthcare
275
263
 
276
- ```
277
- ┌──────────────────────────────────────────────────────┐
278
- │ PostgreSQL Role Hierarchy │
279
- │ │
280
- postgres (superuser) CHỈ dùng cho maintenance │
281
- │ │ │
282
- │ ├── dba_admin (CREATEDB, CREATEROLE)
283
- │ │ └── Quản lý schema, backup, monitoring │
284
- │ │ │
285
- │ ├── app_roles (LOGIN, limited privileges) │
286
- │ │ ├── app_patient_svc │
287
- │ │ ├── app_lab_svc │
288
- │ │ ├── app_pharmacy_svc │
289
- │ │ └── app_gateway_svc │
290
- │ │ │
291
- │ ├── readonly_role (SELECT only) │
292
- │ │ ├── readonly_analytics │
293
- │ │ └── readonly_reporting │
294
- │ │ │
295
- │ └── monitoring_user (pg_monitor) │
296
- └──────────────────────────────────────────────────────┘
297
- ```
264
+ ![PostgreSQL Role Hierarchy cho hệ thống y tế](/storage/uploads/2026/04/healthcare-postgresql-role-hierarchy.png)
265
+
266
+ - **postgres** (superuser) ← CHỈ dùng cho maintenance
267
+ - **dba_admin** (CREATEDB, CREATEROLE) — Quản lý schema, backup, monitoring
268
+ - **app_roles** (LOGIN, limited privileges) app_patient_svc, app_lab_svc, app_pharmacy_svc, app_gateway_svc
269
+ - **readonly_role** (SELECT only) — readonly_analytics, readonly_reporting
270
+ - **monitoring_user** (pg_monitor)
298
271
 
299
272
  ### 4.2. Tạo Role Hierarchy
300
273
 
@@ -570,33 +543,13 @@ WHERE rolcanlogin = true
570
543
  ### 6.1. Tại sao cần PgBouncer
571
544
 
572
545
  Trong hệ thống microservices, mỗi service instance tạo connection pool riêng. PgBouncer giúp:
546
+
573
547
  - Giảm tổng số connections tới PostgreSQL
574
548
  - Thêm một lớp authentication
575
549
  - Rate limiting
576
550
  - Connection routing
577
551
 
578
- ```
579
- ┌─────────────────────────────────────────────────────┐
580
- │ Microservices (mỗi cái 20 connections) │
581
- │ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
582
- │ │ Patient │ │ Lab │ │ Pharmacy │ │
583
- │ │ Service │ │ Service │ │ Service │ │
584
- │ │ x3 pods │ │ x2 pods │ │ x2 pods │ │
585
- │ └────┬─────┘ └────┬─────┘ └────┬─────┘ │
586
- │ │ 60 conn │ 40 conn │ 40 conn │
587
- │ └─────────────┼────────────┘ │
588
- │ │ 140 total │
589
- │ ┌──────┴───────┐ │
590
- │ │ PgBouncer │ │
591
- │ │ Pool: 50 │ ← Giảm từ 140 → 50 │
592
- │ └──────┬───────┘ │
593
- │ │ 50 conn │
594
- │ ┌──────┴───────┐ │
595
- │ │ PostgreSQL │ │
596
- │ │ max: 200 │ │
597
- │ └──────────────┘ │
598
- └─────────────────────────────────────────────────────┘
599
- ```
552
+ ![PgBouncer connection pooling — giảm 140 connections xuống 50](/storage/uploads/2026/04/healthcare-pgbouncer-connection-pooling.png)
600
553
 
601
554
  ### 6.2. PgBouncer Configuration
602
555
 
@@ -1011,6 +964,7 @@ Trong bài học này, chúng ta đã triển khai **PostgreSQL Security Hardeni
1011
964
  8. **OS-Level** - File permissions và systemd hardening
1012
965
 
1013
966
  Các nguyên tắc cốt lõi:
967
+
1014
968
  - **Defense in Depth**: Nhiều lớp bảo mật chồng chéo
1015
969
  - **Least Privilege**: Mỗi role chỉ có quyền tối thiểu cần thiết
1016
970
  - **Encrypt Everything**: SSL/TLS cho mọi connection