@xdev-asia/xdev-knowledge-mcp 1.0.38 → 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 +79 -114
  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
@@ -27,19 +27,7 @@ course:
27
27
 
28
28
  ### 1.1. Quy trình Threat Modeling
29
29
 
30
- ```
31
- ┌──────────────────────────────────────────────────────────┐
32
- │ Threat Modeling Process │
33
- │ │
34
- │ 1. Define Scope ──▶ 2. Decompose ──▶ 3. Identify │
35
- │ & Objectives Application Threats │
36
- │ │ │ │
37
- │ │ ┌─────────────────────┘ │
38
- │ │ ▼ │
39
- │ └──────── 6. Validate ◀── 5. Rate ◀── 4. Mitigate │
40
- │ & Iterate Threats Threats │
41
- └──────────────────────────────────────────────────────────┘
42
- ```
30
+ ![Quy trình Threat Modeling 6 bước — từ Define Scope đến Validate & Iterate](/storage/uploads/2026/04/healthcare-threat-modeling-process.png)
43
31
 
44
32
  ### 1.2. Khi nào cần Threat Modeling?
45
33
 
@@ -68,58 +56,46 @@ STRIDE là framework phân loại threats do Microsoft phát triển:
68
56
 
69
57
  #### S - Spoofing (Giả mạo danh tính)
70
58
 
71
- ```
72
- Threat: Attacker giả mạo JWT token để truy cập Patient API
73
- ───────────────────────────────────────────────────────────
74
- Attack Vector:
75
- 1. Steal JWT từ browser localStorage
76
- 2. Forge JWT với modified claims (role: "admin")
77
- 3. Replay expired token
78
-
79
- Affected Components:
80
- - API Gateway
81
- - Patient Service
82
- - Clinical Service
83
-
84
- Mitigations:
85
- ┌────────────────────────────────────────────┐
86
- M1: Keycloak OIDC token validation │
87
- │ → quarkus-oidc auto-verifies signature
88
- │ │
89
- M2: Short-lived access tokens (5 min) │
90
- │ → Reduce token theft window │
91
- │ │
92
- │ M3: DPoP (Proof-of-Possession) │
93
- │ → Token bound to client certificate │
94
- │ │
95
- │ M4: Refresh token rotation │
96
- │ → One-time use refresh tokens │
97
- │ │
98
- │ M5: mTLS between services │
99
- │ → Service identity verification │
100
- └────────────────────────────────────────────┘
101
- ```
59
+ ![Spoofing Attack — giả mạo JWT token để truy cập Patient API và các biện pháp phòng chống](/storage/uploads/2026/04/healthcare-stride-spoofing-attack.png)
60
+
61
+ **Threat:** Attacker giả mạo JWT token để truy cập Patient API
62
+
63
+ **Attack Vector:**
64
+
65
+ 1. Steal JWT từ browser localStorage
66
+ 2. Forge JWT với modified claims (role: "admin")
67
+ 3. Replay expired token
68
+
69
+ **Affected Components:** API Gateway, Patient Service, Clinical Service
70
+
71
+ **Mitigations:**
72
+
73
+ - **M1:** Keycloak OIDC token validation — quarkus-oidc auto-verifies signature
74
+ - **M2:** Short-lived access tokens (5 min) — giảm token theft window
75
+ - **M3:** DPoP (Proof-of-Possession) token bound to client certificate
76
+ - **M4:** Refresh token rotation — one-time use refresh tokens
77
+ - **M5:** mTLS between services service identity verification
102
78
 
103
79
  #### T - Tampering (Giả mạo dữ liệu)
104
80
 
105
- ```
106
- Threat: Insider sửa đổi kết quả xét nghiệm trong lab_db
107
- ───────────────────────────────────────────────────────────
108
- Attack Vector:
109
- 1. DBA trực tiếp UPDATE lab_results table
110
- 2. Khai thác SQL injection để sửa dữ liệu
111
- 3. Intercept modify API response
112
-
113
- Mitigations:
114
- ┌────────────────────────────────────────────┐
115
- │ M1: pgAudit logging (log all DML) │
116
- │ M2: Database triggers cho change tracking │
117
- M3: Digital signatures cho lab results │
118
- M4: Immutable audit log (append-only) │
119
- M5: Dual control cho critical changes │
120
- M6: Row versioning with checksums │
121
- └────────────────────────────────────────────┘
122
- ```
81
+ ![Tampering Attack — insider sửa đổi kết quả xét nghiệm và các biện pháp bảo vệ tính toàn vẹn dữ liệu](/storage/uploads/2026/04/healthcare-stride-tampering-integrity.png)
82
+
83
+ **Threat:** Insider sửa đổi kết quả xét nghiệm trong lab_db
84
+
85
+ **Attack Vector:**
86
+
87
+ 1. DBA trực tiếp UPDATE lab_results table
88
+ 2. Khai thác SQL injection để sửa dữ liệu
89
+ 3. Intercept và modify API response
90
+
91
+ **Mitigations:**
92
+
93
+ - **M1:** pgAudit logging (log all DML)
94
+ - **M2:** Database triggers cho change tracking
95
+ - **M3:** Digital signatures cho lab results
96
+ - **M4:** Immutable audit log (append-only)
97
+ - **M5:** Dual control cho critical changes
98
+ - **M6:** Row versioning with checksums
123
99
 
124
100
  ```sql
125
101
  -- Integrity protection: Row versioning with checksum
@@ -227,25 +203,25 @@ public PatientSummaryDTO getPatient(@PathParam("id") UUID id) {
227
203
 
228
204
  #### D - Denial of Service
229
205
 
230
- ```
231
- Threat: Tấn công DDoS khiến hệ thống cấp cứu ngừng hoạt động
232
- ───────────────────────────────────────────────────────────
233
- Impact trong Y Tế:
234
- - Không thể tra cứu dị ứng thuốc → kê đơn sai → nguy hiểm
235
- - Không truy cập được lab results → chẩn đoán chậm
236
- - Hệ thống đặt lịch downbệnh nhân không thể đến khám
237
-
238
- Mitigations:
239
- ┌────────────────────────────────────────────┐
240
- │ M1: Rate limiting at API Gateway │
241
- │ M2: Circuit breaker (Quarkus Fault Toler.) │
242
- M3: Auto-scaling Kubernetes pods │
243
- M4: CDN/WAF (Cloudflare, AWS Shield)
244
- M5: Database connection pooling │
245
- M6: Fallback mode / offline capability │
246
- M7: Priority queuing for ER requests │
247
- └────────────────────────────────────────────┘
248
- ```
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
249
225
 
250
226
  #### E - Elevation of Privilege
251
227
 
@@ -349,39 +325,28 @@ public class PrescriptionResource {
349
325
 
350
326
  ### 5.1. Attack Tree: Steal Patient Medical Records
351
327
 
352
- ```
353
- Goal: Steal Patient Medical Records
354
-
355
- ├── 1. External Attack
356
- │ ├── 1.1 Exploit Web Application
357
- │ │ ├── 1.1.1 SQL Injection [DREAD: 8.6] ★
358
- │ │ ├── 1.1.2 XSS to steal session [DREAD: 7.2]
359
- │ │ └── 1.1.3 IDOR to access other patients [DREAD: 7.0]
360
- │ │
361
- │ ├── 1.2 Compromise Authentication
362
- │ │ ├── 1.2.1 Credential stuffing [DREAD: 5.4]
363
- │ │ ├── 1.2.2 Phishing doctor credentials [DREAD: 6.8]
364
- │ │ └── 1.2.3 Brute force Keycloak [DREAD: 3.2]
365
- │ │
366
- │ └── 1.3 Network Attack
367
- │ ├── 1.3.1 MITM on API calls [DREAD: 4.6]
368
- │ └── 1.3.2 DNS spoofing [DREAD: 4.2]
369
-
370
- ├── 2. Internal Attack (Insider Threat)
371
- │ ├── 2.1 Privileged User Abuse
372
- │ │ ├── 2.1.1 DBA exports database [DREAD: 6.8]
373
- │ │ ├── 2.1.2 Admin disables audit [DREAD: 5.6]
374
- │ │ └── 2.1.3 Doctor accesses non-patient [DREAD: 6.0]
375
- │ │
376
- │ └── 2.2 Stolen Credentials
377
- │ ├── 2.2.1 Shared workstation session [DREAD: 6.2]
378
- │ └── 2.2.2 Post-it password [DREAD: 5.0]
379
-
380
- └── 3. Supply Chain Attack
381
- ├── 3.1 Compromised dependency [DREAD: 7.8]
382
- ├── 3.2 Malicious Docker image [DREAD: 6.4]
383
- └── 3.3 Compromised CI/CD pipeline [DREAD: 7.0]
384
- ```
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 |
385
350
 
386
351
  ## 6. Từ Threat Model đến Security Requirements
387
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