Skip to content

Vận hành

1. Triển khai

Thuộc tínhGiá trị
Imageregistry/nx-seller-identity:<tag>
Container Port3000
External Port31010
Snowflake ID1
Replicas (mặc định)1 (dev) / 2+ (staging+)
Resources (req/lim)200m / 1 CPU, 512Mi / 1Gi memory
Migration modeJob RUN_MODE=migrate trước rollout
Live probeGET /v1/api/identity/healthz
Ready probeGET /v1/api/identity/readyz
JWKS endpointGET /jw-certs (công khai, BẮT BUỘC truy cập được từ mọi sister service)

Nhãn routing Traefik

yaml
labels:
  - "traefik.enable=true"
  - "traefik.http.routers.identity.rule=PathPrefix(`/v1/api/identity`) || Path(`/jw-certs`)"
  - "traefik.http.services.identity.loadbalancer.server.port=3000"

Đường dẫn /jw-certs cố tình đặt ngoài /v1/api/identity/ để sister có thể gọi trực tiếp mà không cần base path API.

Hạ tầng yêu cầu

Phụ thuộcLý do
PostgreSQLDatastore chính (schema identity + public.Configuration dùng chung)
RedisTrạng thái OTP + auth cache + BullMQ cho queue mail
SMTPChuyển email — service vẫn khởi động khi thiếu nhưng flow mail sẽ thất bại
VN Pay SMSChuyển SMS — tương tự
JWKS keypair (env / secret)Service từ chối khởi động nếu thiếu

2. Observability

Tín hiệuNguồnTìm ở đâu
Logsstdout (IGNIS structured logger)kubectl logs deploy/identity / Loki
Health/healthz, /readyzGateway portal
OpenAPI live specGET /v1/api/identity/doc/openapi.jsonGateway portal
MetricsTraefik gatewayGrafana
JWKS checkGET /jw-certsManual / synthetic monitor (mỗi 1m)

Trường log quan trọng

TrườngNguồnGhi chú
requestIdheader X-Request-IdLiên kết xuyên-service
userIdJWT subjectPer-request
identifier.schemeflow đăng nhậpEmail vs phone vs username
otp.namespaceOTP serviceverify-email / phone-auth / forgot-password
kidheader JWTTheo dõi xoay key

3. Bảo mật

Vấn đềGiảm thiểu
Xoay JWKSkid mới được publish; key cũ vẫn hợp lệ đến khi hết hạn; sister fetch khi miss
Private signing keyK8s Secret, đường dẫn file mount; không bao giờ dạng env-text
Lưu trữ mật khẩuBun.password hash (kiểu argon2)
OTP brute-forceMã đã hash + tối đa 5 lần thử + lockout 10–15 phút + cooldown gửi lại 60s + hạn ngạch hàng ngày
Identifier enumerationYêu cầu OTP trả cùng response shape bất kể identifier có tồn tại hay không
AuthNBASIC chỉ trên endpoint nội bộ; flow /auth/* công khai có rate limit (gateway)
AuthZCasbin qua PolicyDefinition
TLSKết thúc tại Nginx → Traefik → service ở plaintext
Network policyCilium — cho phép gateway + sister service + SMTP + Redis + Postgres
Mail/SMS providersCredential mã hoá (AES-256-GCM) trong Configuration.credential

4. Runbook

4.1 Lớp cảnh báo

Cảnh báoTriggerKiểm traKhắc phụcEscalate
IdentityHighErrorRate5xx >5% trên 5mkubectl logs ... | grep level=errorxác định endpoint lỗion-call backend
IdentityJWKSDown/jw-certs trả về non-200curl JWKSrestart pod; kiểm tra mount signing keyon-call SRE — ƯU TIÊN CAO (lan ra mọi sister)
IdentityMailFailurestăng vọt error rate gửi maillỗi Nodemailerxác minh SMTP creds; kiểm tra provideron-call backend
IdentitySMSFailurestăng vọt error rate gửi SMSlỗi MQSMSComponentxác minh VN Pay creds; kiểm tra provideron-call backend
IdentityOTPSpikerate yêu cầu OTP >Nx baselineapplication logkiểm tra credential-stuffing; siết rate limiton-call security
IdentitySignInFailuresrate fail đăng nhập >5%logxác định IP bad-actor; kiểm tra mẫu user hợp lệon-call backend

4.2 Thao tác phổ biến

Thao tácLệnh
Tail logskubectl logs -n <ns> -f deploy/identity
Chạy migrationkubectl exec -it deploy/identity -- bun run migrate
Xác minh JWKScurl -s <base>/jw-certs | jq .keys[0]
Inspect một userSELECT * FROM "User" WHERE id = '...';
Kiểm tra policy definition của userSELECT * FROM "PolicyDefinition" WHERE subject_id = '<userId>' AND subject_type = 'User';
Reset OTP lockout cho userXoá Redis key <namespace>:lock:<identifier>

4.3 Kịch bản phục hồi

Kịch bảnPhục hồi
Service crashMọi request đang xử lý sẽ thất bại; trạng thái OTP trong Redis vẫn còn
Provider Mail/SMS gián đoạnTrạng thái OTP queue trong Redis; user yêu cầu lại sau khi provider hồi phục
Redis gián đoạnFlow OTP thất bại (fail open: HTTP 503); auth cache tắt nhưng JWT verify vẫn hoạt động
Postgres gián đoạnMọi endpoint thất bại; user vẫn có thể xác minh JWT HIỆN HỮU (sister cache JWKS)
Mất signing keyThảm hoạ — mọi JWT hiện tại không thể xác minh; xoay keypair + buộc mọi user đăng nhập lại

5. Runbook xuyên-service

6. Trang liên quan

Proprietary and Confidential. Unauthorized copying, distribution, or use of this software is strictly prohibited.