Files
tailscale-custom/.agent/workflows/ins-develop.md
T
huanld 2fb067ecbf
checklocks / checklocks (push) Has been cancelled
CodeQL / Analyze (go) (push) Has been cancelled
natlab-integrationtest / natlab-integrationtest (push) Has been cancelled
CI / gomod-cache (push) Has been cancelled
CI / race-root-integration (1/4) (push) Has been cancelled
CI / race-root-integration (2/4) (push) Has been cancelled
CI / race-root-integration (3/4) (push) Has been cancelled
CI / race-root-integration (4/4) (push) Has been cancelled
CI / test (-race, amd64, 1/3) (push) Has been cancelled
CI / test (-race, amd64, 2/3) (push) Has been cancelled
CI / test (-race, amd64, 3/3) (push) Has been cancelled
CI / test (386) (push) Has been cancelled
CI / test (amd64) (push) Has been cancelled
CI / Windows (benchmarks) (push) Has been cancelled
CI / Windows (1/2) (push) Has been cancelled
CI / Windows (2/2) (push) Has been cancelled
CI / macos (push) Has been cancelled
CI / privileged (push) Has been cancelled
CI / vm (push) Has been cancelled
CI / cross (386, linux) (push) Has been cancelled
CI / cross (amd64, darwin) (push) Has been cancelled
CI / cross (amd64, freebsd) (push) Has been cancelled
CI / cross (amd64, openbsd) (push) Has been cancelled
CI / cross (amd64, windows) (push) Has been cancelled
CI / cross (arm, 5, linux) (push) Has been cancelled
CI / cross (arm, 7, linux) (push) Has been cancelled
CI / cross (arm64, darwin) (push) Has been cancelled
CI / cross (arm64, linux) (push) Has been cancelled
CI / cross (arm64, windows) (push) Has been cancelled
CI / cross (loong64, linux) (push) Has been cancelled
CI / ios (push) Has been cancelled
CI / crossmin (amd64, illumos) (push) Has been cancelled
CI / crossmin (amd64, plan9) (push) Has been cancelled
CI / crossmin (amd64, solaris) (push) Has been cancelled
CI / crossmin (ppc64, aix) (push) Has been cancelled
CI / android (push) Has been cancelled
CI / wasm (push) Has been cancelled
CI / tailscale_go (push) Has been cancelled
CI / fuzz (push) Has been cancelled
CI / depaware (push) Has been cancelled
CI / go_generate (push) Has been cancelled
CI / make_tidy (push) Has been cancelled
CI / licenses (push) Has been cancelled
CI / staticcheck (macOS) (push) Has been cancelled
CI / staticcheck (Linux) (push) Has been cancelled
CI / staticcheck (Windows) (push) Has been cancelled
CI / staticcheck (Portable (1/4)) (push) Has been cancelled
CI / staticcheck (Portable (2/4)) (push) Has been cancelled
CI / staticcheck (Portable (3/4)) (push) Has been cancelled
CI / staticcheck (Portable (4/4)) (push) Has been cancelled
CI / notify_slack (push) Has been cancelled
CI / merge_blocker (push) Has been cancelled
CI / check_mergeability_strict (push) Has been cancelled
CI / check_mergeability (push) Has been cancelled
Dockerfile build / deploy (push) Has been cancelled
test installer.sh / test (curl, alpine:3.21) (push) Has been cancelled
test installer.sh / test (curl, alpine:edge) (push) Has been cancelled
test installer.sh / test (curl, alpine:latest) (push) Has been cancelled
test installer.sh / test (curl, amazonlinux:latest) (push) Has been cancelled
test installer.sh / test (curl, archlinux:latest) (push) Has been cancelled
test installer.sh / test (curl, debian:oldstable-slim) (push) Has been cancelled
test installer.sh / test (curl, debian:sid-slim) (push) Has been cancelled
test installer.sh / test (curl, debian:stable-slim, 1.80.0) (push) Has been cancelled
test installer.sh / test (curl, debian:testing-slim) (push) Has been cancelled
test installer.sh / test (curl, elementary/docker:stable) (push) Has been cancelled
test installer.sh / test (curl, elementary/docker:unstable) (push) Has been cancelled
test installer.sh / test (curl, fedora:latest, 1.80.0) (push) Has been cancelled
test installer.sh / test (curl, kalilinux/kali-dev) (push) Has been cancelled
test installer.sh / test (curl, kalilinux/kali-rolling) (push) Has been cancelled
test installer.sh / test (curl, opensuse/leap:latest) (push) Has been cancelled
test installer.sh / test (curl, opensuse/tumbleweed:latest) (push) Has been cancelled
test installer.sh / test (curl, oraclelinux:8) (push) Has been cancelled
test installer.sh / test (curl, oraclelinux:9) (push) Has been cancelled
test installer.sh / test (curl, parrotsec/core:latest) (push) Has been cancelled
test installer.sh / test (curl, rockylinux:8.7) (push) Has been cancelled
test installer.sh / test (curl, rockylinux:9) (push) Has been cancelled
test installer.sh / test (curl, ubuntu:20.04) (push) Has been cancelled
test installer.sh / test (curl, ubuntu:22.04) (push) Has been cancelled
test installer.sh / test (curl, ubuntu:24.04, 1.80.0) (push) Has been cancelled
test installer.sh / test (wget, debian:oldstable-slim) (push) Has been cancelled
test installer.sh / test (wget, debian:sid-slim) (push) Has been cancelled
update-flake / update-flake (push) Has been cancelled
tailscale.com/cmd/vet / vet (push) Has been cancelled
test installer.sh / notify-slack (push) Has been cancelled
feat: security hardening, production roadmap, admin panel v1
Client security fixes (cmd/tailscale-tray/main.go):
- SSRF protection in Add Server dialog (validateControlURL): reject
  private/loopback/link-local/cloud-metadata IPs via DNS resolution
- RCE gate on AuthURL/BrowseToURL exec paths (validateAuthURL)
- Sanitized URL logging (sanitizeURLForLog drops query auth tokens)
- Error handling on exec.Command with user-facing showError()

Admin panel security (web-admin):
- Bcrypt password hashing (replaces SHA256)
- Rate limiting: 5 failed logins → 15-min lockout
- Session + login attempt cleanup goroutine (hourly)
- url.QueryEscape / encodeURIComponent for all API params
- Fail-hard startup when no TLS and non-loopback bind
- ADMIN_PASSWORD required (no default), password min 12 chars
- Username regex whitelist

Installer hardening (Setup.wxs):
- util:PermissionEx restricts SCM access: only Administrators +
  SYSTEM can start/stop/reconfigure service. Authenticated Users
  limited to QueryStatus/QueryConfig/Interrogate
- Vital="yes" on ServiceInstall

Docs & roadmap:
- PRODUCTION_ROADMAP.md: 5-milestone plan (security + features +
  distribution + ops) with granular tasks, effort, done-when
- CLIENT_SECURITY_AUDIT.md, SECURITY_FIXES.md, DEPLOYMENT.md
- AI assistant rules (.cursorrules, .antigravityrules, etc.)

Build & distribution:
- build-msi.ps1, deploy-and-sign.ps1, sign-release.ps1
- redeploy.ps1, tray-deploy.ps1, test-msi.ps1
- installer/msi/ alternative WXS setup
- Restored .github/workflows/ removed in mirror cleanup

.gitignore hardened: *.pfx, *.p12, *.key, *.pem, .env*
2026-04-22 15:18:11 +07:00

226 lines
8.4 KiB
Markdown

---
description: INS Module feature development workflow. Full lifecycle from planning to verification. Standard for all INS modules (HRM, PRO, CDE, WJC, etc.)
---
# /ins-develop - INS Module Feature Development
$ARGUMENTS
---
## Architecture Context
All INS modules follow the same architecture:
```
┌──────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Browser │────▶│ INS.{MOD}.Backend│────▶│ sso-instratech │
│ (Blazor │ │ localhost:{PORT} │gRPC │ 10.0.0.1:8082 │
│ WASM) │ │ │ │ (Auth/SSO) │
└──────────────┘ └────────┬─────────┘ └─────────────────┘
┌─────────┴──────────┐
│ │
┌────▼─────┐ ┌──────▼──────┐
│ INS_{MOD}│ │ INS_SYS │
│ Module DB│ │ Auth DB │
└──────────┘ └─────────────┘
```
| Component | Description |
|-----------|-------------|
| **Frontend** | `src/INS.{MOD}.Frontend/` — Blazor WASM, AdminLTE sidebar |
| **Backend** | `src/INS.{MOD}.Backend/` — ASP.NET 8, Kestrel |
| **Auth DLL** | `INS.ModuleControllers.dll` — gRPC auth, SSO, navigation |
| **Module DB** | Business data (employees, projects, documents, etc.) |
| **Auth DB** | `INS_SYS` on `dev.instratech.net` — users, permissions, navigation |
| **gRPC** | `sso-instratech` container at `10.0.0.1:8082` |
---
## Phase 0: KNOWLEDGE DISCOVERY (🔴 BẮT BUỘC — Luôn chạy đầu tiên)
> **KHÔNG ĐƯỢC BỎ QUA.** Trước khi làm bất cứ gì, phải tìm kiếm knowledge base.
1. **Search knowledge base** — Tìm quy tắc dự án, patterns, conventions
```
mcp_knowledge_search_knowledge(query="{tên tính năng hoặc domain liên quan}")
mcp_knowledge_search_knowledge(query="INS component")
mcp_knowledge_search_knowledge(query="coding conventions")
```
2. **Read relevant KI artifacts** — Đọc chi tiết các KI tìm được (architecture, component usage rules, past implementations)
3. **Check module-specific knowledge** — Tìm theo module
```
mcp_knowledge_list_modules(solution="ins-pro") // hoặc module đang phát triển
mcp_knowledge_get_module_context(solution="...", moduleName="...")
```
4. **Check global standards** — Đọc coding standards chung
```
mcp_knowledge_get_global_standards()
```
5. **Result:** Ghi nhận tất cả rules/constraints phải tuân thủ trước khi code.
---
## Phase 1: RESEARCH (Bắt buộc)
// turbo-all
6. **Identify module** — Determine ModuleCode (e.g., `INS.HRM`, `INS.PRO`, `INS.CDE`)
7. **Check DB schema** — Connect to module DB and inspect tables
```powershell
# Query schema
$connStr = "<module connection string from appsettings.json>"
# SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
# SELECT COLUMN_NAME, DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '...'
```
8. **Check existing code** — Search for related `.razor`, `.cs` files, controllers
9. **Check permissions** — Query `[Auth].[ApplicationRules]` for existing FuncCodes of this module
10. **Check navigation** — Verify sidebar entries in module DB (e.g., `BranchInfo` table)
---
## Phase 2: PLAN
7. **Create implementation plan** — Break into:
- [ ] DB changes (tables, seed data, migrations)
- [ ] Backend (controllers, services, DTOs)
- [ ] Frontend (pages, components, sidebar entries)
- [ ] Permissions (new FuncCodes in `INS_SYS`)
- [ ] Navigation (sidebar menu items)
8. **Present plan to user** — Wait for approval before coding.
---
## Phase 3: IMPLEMENT
### 3a. Database First
9. **Create/modify tables** — EF Core migrations or raw SQL
10. **Seed reference data** — Insert into module DB
11. **Add permission rules** — Insert into `INS_SYS`
```sql
-- AuthDb connection: Server=dev.instratech.net;Database=INS_SYS;User Id=spm34d.ins;Password=SPM2025@#;...
-- 1. Add rule definition
INSERT INTO [Auth].[ApplicationRules] (ModuleCode, Category, FuncCode, Description, IsActive, CreatedAt, UpdatedAt)
VALUES ('INS.{MOD}', '{Category}', '{MOD}_{CAT}_{ACTION}', N'{Description}', 1, GETDATE(), GETDATE());
-- 2. Assign to root user
INSERT INTO [Auth].[UserApplicationRules] (UserId, RuleId, IsAllowed, AssignedBy, AssignedAt)
SELECT 'root', ar.Id, 1, 'system', GETDATE()
FROM [Auth].[ApplicationRules] ar
WHERE ar.FuncCode = '{MOD}_{CAT}_{ACTION}'
AND NOT EXISTS (SELECT 1 FROM [Auth].[UserApplicationRules] uar WHERE uar.UserId = 'root' AND uar.RuleId = ar.Id);
```
### 3b. Backend
12. **Create DTOs** in `Models/`
13. **Create Controller** — follow existing controller patterns in the module
14. **Register services** in `Program.cs` if needed
15. **Middleware check** — ensure new endpoints work with gRPC validation pipeline
### 3c. Frontend
16. **Create page** in `Pages/` — follow existing page patterns
17. **Add sidebar entry** — Insert navigation record (e.g., `BranchInfo`)
18. **Use INS components** — `INS_DataGrid`, `INS_Popup`, `INS_RuleInit` (check KB!)
19. **Wire API calls** — `HttpClient` with auth token from `IModuleAuthenticationService`
---
## Phase 4: BUILD & TEST
// turbo-all
20. **Stop server**
```powershell
Stop-Process -Name "INS.{MOD}.Backend" -Force -ErrorAction SilentlyContinue
```
21. **Build**
```powershell
dotnet build src/INS.{MOD}.Backend/INS.{MOD}.Backend.csproj
```
22. **Fix build errors** — Check `error CS` output, fix, rebuild
23. **Start server**
```powershell
dotnet run --project src/INS.{MOD}.Backend/INS.{MOD}.Backend.csproj
```
24. **Verify startup logs** — Must see:
- `Now listening on: http://localhost:{PORT}` ✅
- No gRPC connection errors ✅
- No DB errors ✅
---
## Phase 5: VERIFY
25. **API test** via PowerShell
```powershell
$login = Invoke-RestMethod -Method Post -Uri "http://localhost:{PORT}/api/auth/login" `
-Body (@{email="root@local.instratech";password="admin123"} | ConvertTo-Json) -ContentType "application/json"
$h = @{ "Authorization" = "Bearer $($login.token)" }
Invoke-RestMethod -Uri "http://localhost:{PORT}/{mod}/api/{endpoint}" -Headers $h
```
26. **Browser test** — Login, navigate, verify:
- All buttons visible (permissions loaded correctly)
- Data displays, CRUD works
- Popup/modal margins follow INS component guidelines
27. **Permission verify** — `api/applicationrule/user` returns new FuncCodes
---
## Phase 6: REVIEW
28. **Check logs** for warnings/errors
29. **Remove debug code**
30. **Report** to user with change summary
---
## Troubleshooting
| Symptom | Root Cause | Fix |
|---------|-----------|-----|
| gRPC connection refused | `sso-instratech` stopped | `ssh root@36.50.176.30 "docker start sso-instratech"` |
| 401 on data API | Token not validated by gRPC | Check `GrpcTokenValidationMiddleware` logs |
| 401 on `/api/applicationrule` | Path not bypassed | `UseWhen` must exclude `/api/applicationrule` |
| Buttons missing | FuncCode not in DB | Insert into `[Auth].[ApplicationRules]` + assign to user |
| DB already exists | `EnsureCreated()` | Wrap in try-catch |
| Build locked file | Previous process | `Stop-Process -Name "INS.{MOD}.Backend" -Force` |
| SSO register-session fail | gRPC server unreachable | Check `appsettings.json > GrpcClient.ServerUrl` |
| Popup margins wrong | Component misuse | Check knowledge base for INS component rules |
---
## Server Infrastructure
| Container | Host Port | Internal | Purpose |
|-----------|-----------|----------|---------|
| `sso-instratech` | **8082** | 8082 | SSO/Auth gRPC (ALL modules use this) |
| `ins-sys` | 8083/7001 | 8082/8080 | INS.SYS Backend |
| `epm-sqlserver` | 1434 | 1433 | SQL Server |
| `epm-gateway` | 5000 | 5000 | API Gateway |
SSH: `ssh root@36.50.176.30`
---
## Examples
```
/ins-develop thêm module quản lý hợp đồng
/ins-develop thêm chức năng export PDF cho báo cáo
/ins-develop thêm trang dashboard thống kê
/ins-develop thêm CRUD cho bảng mới
```