fix: connect L1 Workbench to AgentRun v0.2
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
import { backendPerformanceRouteTemplate, currentBackendPerformanceContext } from "./backend-performance.ts";
|
||||
import { truthyFlag } from "./server-http-utils.ts";
|
||||
import { isIP } from "node:net";
|
||||
|
||||
export const DEFAULT_AGENTRUN_MGR_URL = "http://agentrun-mgr.agentrun-v01.svc.cluster.local:8080";
|
||||
|
||||
@@ -65,7 +66,8 @@ export function resolveAgentRunManagerUrl(env = process.env, override = null) {
|
||||
const url = new URL(raw);
|
||||
const host = url.hostname.toLowerCase();
|
||||
const allowedByTest = truthyFlag(env.HWLAB_CODE_AGENT_AGENTRUN_ALLOW_NON_K3S_URL) && ["127.0.0.1", "localhost"].includes(host);
|
||||
if (url.protocol !== "http:" || (!isAgentRunManagerInternalServiceHost(host) && !allowedByTest)) {
|
||||
const allowedByNative = env.WORKBENCH_MODE === "agentrun-native" && truthyFlag(env.HWLAB_CODE_AGENT_AGENTRUN_ALLOW_PRIVATE_URL) && isPrivateIp(host);
|
||||
if (url.protocol !== "http:" || (!isAgentRunManagerInternalServiceHost(host) && !allowedByTest && !allowedByNative)) {
|
||||
throw Object.assign(new Error(`AGENTRUN_MGR_URL must use internal k3s Service DNS agentrun-mgr.<namespace>.svc.cluster.local; got ${redactUrl(raw)}`), {
|
||||
code: "agentrun_internal_url_required",
|
||||
statusCode: 500
|
||||
@@ -77,6 +79,12 @@ export function resolveAgentRunManagerUrl(env = process.env, override = null) {
|
||||
return url.toString().replace(/\/+$/u, "");
|
||||
}
|
||||
|
||||
function isPrivateIp(host: string) {
|
||||
if (isIP(host) !== 4) return false;
|
||||
const [a, b] = host.split(".").map(Number);
|
||||
return a === 10 || a === 127 || (a === 172 && b >= 16 && b <= 31) || (a === 192 && b === 168);
|
||||
}
|
||||
|
||||
export function isAgentRunManagerInternalServiceHost(host) {
|
||||
return AGENTRUN_MANAGER_HOST_PATTERN.test(String(host ?? "").trim().toLowerCase());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user