配置分层 - 新增 src/server/config.ts:环境变量集中读取 + 启动期校验。 删除公开兜底密钥 ln-bi-default-secret:SSO 模式下 JWT_SECRET 缺失或 短于 32 字符时 assertRuntimeConfig() 直接拒绝启动(已实测)。 - index.ts 不再自己读端口/环境;auth/config.ts 与 auth/login.ts 改为引用集中配置。 权限守卫 - energy / scheduling / hydrogen-heatmap 的守卫由 “user 存在才校验” 改为 “无角色即拒绝”:user 缺失时按无权限处理,不再静默放行(fail-closed)。 - /api/ele/* 此前完全无鉴权,任何已登录用户都能写入电费表;现按能源域 (BI-LEADER-ENERGY) 守卫。 接口契约 - 未匹配的 /api/* 由 200 text/html(SPA) 改为 404 application/json; 未认证时仍是 401,避免向未授权调用方暴露路由是否存在。 - 新增全局 onError 返回 JSON 500。 凭据治理(此前均为 git 跟踪文件中的明文) - Dockerfile 删除烧进镜像的 JWT_SECRET,改为必须运行时注入。 - docker-compose.yml 删除生产库口令/JWT 密钥/失效的 MILEAGE_DB_*, 改为强制注入写法;补齐 OSS_* 与 NODE_ENV/DEV_BYPASS_AUTH/BI_AUTH_*。 - woodpecker.yml 删除 Harbor base64 凭据改用 secret,pull_request 不再推镜像。 - 删除 scripts-tmp/(含生产库 root 口令)与已跟踪的 .DS_Store;.gitignore 补全。 - 文档中残留的里程库口令改为占位符。 lint / test(128) / build 全绿。
24 lines
843 B
TypeScript
24 lines
843 B
TypeScript
import { Hono } from 'hono';
|
|
import suggestionsRouter from './suggestions.js';
|
|
import notifyRouter from './notify.js';
|
|
import type { AuthUser } from '../../auth/types.js';
|
|
import { canAccessScheduling } from '../../auth/types.js';
|
|
|
|
const app = new Hono();
|
|
|
|
// Module-level access guard (fail-closed): requires BI-SCHEDULE-OPT.
|
|
// Auth middleware runs before this router, so a missing `user` is an anomaly and
|
|
// must be treated as "no permission" rather than silently allowed.
|
|
app.use('*', async (c, next) => {
|
|
const user = (c as any).get('user') as AuthUser | undefined;
|
|
if (!canAccessScheduling(user?.roles)) {
|
|
return c.json({ error: 'Forbidden: 智能调度访问需要 BI-SCHEDULE-OPT 角色' }, 403);
|
|
}
|
|
return next();
|
|
});
|
|
|
|
app.route('/suggestions', suggestionsRouter);
|
|
app.route('/notify', notifyRouter);
|
|
|
|
export default app;
|