3.2 · cu-central-api Deep Dive
cu-central-api เป็น service ที่ vtrc-api เรียกผ่าน END_POINT_CENTRALIZE / END_POINT_CENTRALIZE_AUTH — เป็นเจ้าของ LDAP/AD authentication จริง และเป็นเจ้าของ HR data ที่กระจายอยู่หลาย MSSQL shard ตามที่ document ไว้ใน 3.1.4 centralize-bridge
โครงสร้างคล้าย vtrc-api (Apollo GraphQL + Express + Sequelize) แต่ขนาดเล็กกว่า และมีจุดเด่นเฉพาะตัวที่ vtrc-api ไม่มี — LDAP/AD 2-stage bind และ SourceDB multi-tenant sharding
Volume นี้เจาะลึกในระดับ code trace ทุก claim มี file:line อ้างอิงถึงโค้ดจริง ทุก vulnerability มี source code ประกอบพร้อมวิเคราะห์ impact และ fix ที่ควรทำ
ทำไมต้องมี Volume นี้
cu-central-api ถูก label เป็น "Legacy CU Auth/HR Satellite" ใน audit เก่าหลายฉบับ — แต่ label นั้นขาดรายละเอียดสำคัญ
- 6 MSSQL connections (ไม่ใช่ 2 ตามที่ audit บางฉบับบอก) กระจายไป 5 schemas ที่ใช้จริง + dead
dbHRMI_testconnection ที่เปิด pool 100 session เปล่าทุก boot (cu-central-api/main-api/src/connector.js:117-142) - Multi-tenant
SourceDBsharding ที่ทุก association ต้อง scope ด้วยWHERE Employee.SourceDB = X.SourceDB— pattern ที่ไม่มีในvtrc-api(cu-central-api/main-api/src/models/hrmi/employee/employee.js:254-264) - LDAP/AD auth ผ่าน
ldapjs 2.2.0(archived ตั้งแต่ 2023) ในรูปแบบ 2-stage bind (service account + user bind) ที่vtrc-apiforward มา (cu-central-api/main-api/src/lib/auth/activeDirectory.model.js:16-42) - External integrations 6 ตัว ที่
cu-central-apiเป็น service เดียวใน topology ที่เรียก — SSO, Conicle SFTP, HIS heal-card, HRMI HTTP API, SMS gateway, SMTP
ถ้า debug เรื่อง "ทำไม employee ของ org X login ไม่ได้" หรือ "ทำไมข้อมูล HR ของ shard Y หาย" ต้องเริ่มที่นี่ ไม่ใช่ที่ vtrc-api
บทบาทใน topology
vtrc-web ──┐
vtrc-rc-backoffice ──┤
vtrc-backoffice(-new) ──┤
vtrc-mobile ──┤
│ GraphQL (apiKey + JWT)
▼
vtrc-api Volume 3.1
│
│ END_POINT_CENTRALIZE (+ _AUTH)
▼
cu-central-api Volume 3.2 ◀── บทนี้ (live bridge)
│
├──▶ MSSQL (6 connections, 5 schema จริง + 1 dead)
├──▶ LDAP / AD (Chula directory)
├──▶ Redis (session + cache) — key `sess:{userUid}_{sessionId}`
├──▶ SSO (with committed certs)
├──▶ Conicle SFTP
├──▶ HIS heal-card API
├──▶ HRMI HTTP API
├──▶ SMS gateway
└──▶ SMTP
centralize-api (Volume 3.3) — NestJS REST คนละ service
caller จาก vtrc-api ในโค้ดชุดนี้ยังไม่ยืนยันcu-central-api ไม่ได้คุยกับ frontend โดยตรง — เป็น upstream ของ vtrc-api เท่านั้น (ตาม workspace rule "Both frontends talk to vtrc-api only")
ใครควรอ่านบทไหน
| ถ้าเป็น | อ่านบท |
|---|---|
| Dev ที่ debug login ผ่าน AD | 3.2.3, 3.2.4 |
| Dev ที่แก้ HR data query | 3.2.5, 3.2.6 |
| DevOps ที่ดูแล deploy | 3.2.2, 3.2.8 |
| คนที่จะ modernize auth | 3.2.3, 3.2.4, 3.2.9 |
| คนที่ทำ SSO integration | 3.2.7 |
| คนที่เจอ "finanace" typo | 3.2.1, 3.2.6 |
| คนที่ review security | 3.2.4, 3.2.8 |
ตัวเลขที่ควรจำ (verify กับโค้ดปัจจุบัน 2026-07-13)
| ตัวเลข | ค่า | ที่มา |
|---|---|---|
| MSSQL connections | 6 (ไม่ใช่ 2 อย่างที่บาง audit เก่าระบุ) | cu-central-api/main-api/src/connector.js:195 |
| Schema จริงที่ใช้ | 5 (schema ที่ 6 คือ dbHRMI_test ตายแล้ว) | cu-central-api/main-api/src/connector.js:8-170 |
| typeDefs (SDL) | 32 ไฟล์เนื้อหา + index.js aggregator | cu-central-api/main-api/src/typeDefs/ |
| resolvers | 28 ไฟล์เนื้อหา + index.js | cu-central-api/main-api/src/resolvers/ |
lib/ subdirectories | 31 | cu-central-api/main-api/src/lib/ |
index.js (bootstrap) | 118 บรรทัด | cu-central-api/main-api/src/index.js |
connector.js | 196 บรรทัด (6 Sequelize instances) | cu-central-api/main-api/src/connector.js |
routes.js | 64 บรรทัด (5 REST endpoints) | cu-central-api/main-api/src/routes.js |
| Node runtime | 12.18.3 (EOL เม.ย. 2022) | cu-central-api/main-api/Dockerfile:1 |
สารบัญ
| บท | หัวข้อ |
|---|---|
| 3.2.1 | Repository map + typos + dead files |
| 3.2.2 | Bootstrap + 6 DB connections + cron jobs |
| 3.2.3 | Authentication + LDAP/AD 2-stage bind flow |
| 3.2.4 | @auth directive + ignoreAuth bypass + hardcoded apiKeys |
| 3.2.5 | Multi-tenant SourceDB sharding |
| 3.2.6 | TypeDefs + resolvers catalog (32 SDL + 28 resolvers) |
| 3.2.7 | External integrations (SSO + Conicle + HIS + HRMI + SMS + SMTP) |
| 3.2.8 | Security + dependency debt |
| 3.2.9 | Scorecard + comparison กับ vtrc-api + modernization |
สไตล์ที่ใช้ใน Volume นี้
เหมือน Volume อื่น — น้ำเสียง senior engineer ที่ทำจริง, ภาษาไทย + ทับศัพท์ dev (login, fetch, deploy, cache miss, query, mutation, token, session, resolve), ไม่ใช้ emoji/mermaid/callout boxes, ใช้ ASCII tree + table + code block แทน
ทุก claim ต้องมี file:line reference — รูปแบบ cu-central-api/main-api/src/...:LINE
Severity legend
- 🔴 Critical = active security/data-loss/availability risk
- 🟡 High = correctness/maintainability hazard, real impact
- 🟢 Medium = friction/hygiene, not yet dangerous
สิ่งที่ Volume นี้ไม่ครอบคลุม
- รายละเอียด secret values ใน
.env.develop-test— cover ใน Volume 12 Security (cu-central-api.env.develop-testcommitted) - Generic LDAP/AD concepts — เน้นเฉพาะที่ implement ใน codebase
- การ migrate ไป Go service — cover ใน Volume 19 Roadmap
การเปลี่ยนแปลงจาก v1
เนื้อหาพอร์ตมาจาก docs-v1-archive/volume-04-cu-central-api/ (9 บท + index) — ทุก citation หลักถูกเปิดไฟล์จริงยืนยันใหม่ (2026-07-13) โค้ดของ cu-central-api ไม่เปลี่ยนแปลงในระดับที่มีผลต่อเนื้อหา
การแก้ไขที่พบ
| รายการ | v1 เขียนไว้ | ค่าที่ verify ใหม่ | เหตุผล |
|---|---|---|---|
| typeDefs count (prose ใน v1 index.md) | "31 (29 root + 3 hr/)" | 32 ไฟล์เนื้อหา + index.js | ตัวเลขในตาราง per-file ของ v1 เอง (บท 4.6) นับได้ 32 แถวอยู่แล้ว — prose ใน index.md บวกเลขผิด ไม่ใช่โค้ดเปลี่ยน |
| resolvers count | ตรงกับตาราง per-file | 28 ไฟล์ + index.js | ยืนยันตรงกับตารางในบท 4.6 ของ v1 |
| syncModels array | "12 models" | 12 models (ลิสต์ที่แท้จริงใน lib/model.js:4-6) | v1 ลิสต์ถูก แต่นับเป็น 12 ใช่ได้ |
ไม่พบ finding เชิง behavior (security bug, debt item, severity) ที่ผิดจาก v1 — ทุกอย่างใน 3.2.9 scorecard ยังตรงกับโค้ดปัจจุบัน
อ่านต่อ → 3.2.1 Repository map