Разрешить Engine авторизацию в AI Workspace Hub

This commit is contained in:
Codex 2026-05-30 13:44:31 +03:00
parent 469657d526
commit c10aa7c301
2 changed files with 9 additions and 4 deletions

View File

@ -113,6 +113,7 @@ services:
NODE_ENV: production NODE_ENV: production
PORT: 18081 PORT: 18081
AI_WORKSPACE_HUB_TOKEN: ${AI_WORKSPACE_HUB_TOKEN:?ai workspace hub token required} AI_WORKSPACE_HUB_TOKEN: ${AI_WORKSPACE_HUB_TOKEN:?ai workspace hub token required}
NODEDC_INTERNAL_ACCESS_TOKEN: ${NODEDC_INTERNAL_ACCESS_TOKEN:-}
AI_WORKSPACE_HUB_WS_PATH: /api/ai-workspace/hub AI_WORKSPACE_HUB_WS_PATH: /api/ai-workspace/hub
expose: expose:
- "18081" - "18081"

View File

@ -23,7 +23,7 @@ app.get("/healthz", (_req, res) => {
service: "nodedc-ai-workspace-hub", service: "nodedc-ai-workspace-hub",
wsPath: config.wsPath, wsPath: config.wsPath,
agentsOnline: Array.from(agentsByCode.values()).filter(isAgentOnline).length, agentsOnline: Array.from(agentsByCode.values()).filter(isAgentOnline).length,
internalApiConfigured: Boolean(config.internalAccessToken), internalApiConfigured: config.internalAccessTokens.length > 0,
}); });
}); });
@ -352,13 +352,13 @@ function asyncRoute(handler) {
} }
function requireInternalApi(req, res, next) { function requireInternalApi(req, res, next) {
if (!config.internalAccessToken) { if (!config.internalAccessTokens.length) {
res.status(503).json({ ok: false, error: "ai_workspace_hub_token_not_configured" }); res.status(503).json({ ok: false, error: "ai_workspace_hub_token_not_configured" });
return; return;
} }
const header = String(req.headers.authorization || ""); const header = String(req.headers.authorization || "");
const token = header.startsWith("Bearer ") ? header.slice(7) : ""; const token = header.startsWith("Bearer ") ? header.slice(7) : "";
if (!token || !safeEqual(token, config.internalAccessToken)) { if (!token || !config.internalAccessTokens.some((candidate) => safeEqual(token, candidate))) {
res.status(401).json({ ok: false, error: "ai_workspace_hub_unauthorized" }); res.status(401).json({ ok: false, error: "ai_workspace_hub_unauthorized" });
return; return;
} }
@ -372,10 +372,14 @@ function safeEqual(left, right) {
} }
function readConfig() { function readConfig() {
const internalAccessTokens = Array.from(new Set([
process.env.AI_WORKSPACE_HUB_TOKEN,
process.env.NODEDC_INTERNAL_ACCESS_TOKEN,
].map((value) => cleanString(value, 1000)).filter(Boolean)));
return { return {
port: Number(process.env.PORT || 18081), port: Number(process.env.PORT || 18081),
wsPath: process.env.AI_WORKSPACE_HUB_WS_PATH || DEFAULT_WS_PATH, wsPath: process.env.AI_WORKSPACE_HUB_WS_PATH || DEFAULT_WS_PATH,
internalAccessToken: process.env.AI_WORKSPACE_HUB_TOKEN || process.env.NODEDC_INTERNAL_ACCESS_TOKEN || "", internalAccessTokens,
}; };
} }