mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 03:31:23 +00:00
feat(gateway): add trusted-proxy auth mode (#15940)
Merged via /review-pr -> /prepare-pr -> /merge-pr.
Prepared head SHA: 279d4b304f
Co-authored-by: nickytonline <833231+nickytonline@users.noreply.github.com>
Co-authored-by: steipete <58493+steipete@users.noreply.github.com>
Reviewed-by: @steipete
This commit is contained in:
@@ -14,7 +14,7 @@ import {
|
||||
import { promptCustomApiConfig } from "./onboard-custom.js";
|
||||
import { randomToken } from "./onboard-helpers.js";
|
||||
|
||||
type GatewayAuthChoice = "token" | "password";
|
||||
type GatewayAuthChoice = "token" | "password" | "trusted-proxy";
|
||||
|
||||
/** Reject undefined, empty, and common JS string-coercion artifacts for token auth. */
|
||||
function sanitizeTokenValue(value: string | undefined): string | undefined {
|
||||
@@ -40,6 +40,11 @@ export function buildGatewayAuthConfig(params: {
|
||||
mode: GatewayAuthChoice;
|
||||
token?: string;
|
||||
password?: string;
|
||||
trustedProxy?: {
|
||||
userHeader: string;
|
||||
requiredHeaders?: string[];
|
||||
allowUsers?: string[];
|
||||
};
|
||||
}): GatewayAuthConfig | undefined {
|
||||
const allowTailscale = params.existing?.allowTailscale;
|
||||
const base: GatewayAuthConfig = {};
|
||||
@@ -52,8 +57,17 @@ export function buildGatewayAuthConfig(params: {
|
||||
const token = sanitizeTokenValue(params.token) ?? randomToken();
|
||||
return { ...base, mode: "token", token };
|
||||
}
|
||||
const password = params.password?.trim();
|
||||
return { ...base, mode: "password", ...(password && { password }) };
|
||||
if (params.mode === "password") {
|
||||
const password = params.password?.trim();
|
||||
return { ...base, mode: "password", ...(password && { password }) };
|
||||
}
|
||||
if (params.mode === "trusted-proxy") {
|
||||
if (!params.trustedProxy) {
|
||||
throw new Error("trustedProxy config is required when mode is trusted-proxy");
|
||||
}
|
||||
return { ...base, mode: "trusted-proxy", trustedProxy: params.trustedProxy };
|
||||
}
|
||||
return base;
|
||||
}
|
||||
|
||||
export async function promptAuthConfig(
|
||||
|
||||
Reference in New Issue
Block a user