Add per-enterprise custom HTTP headers and cookies

Some Seal tenants sit behind a gateway that only forwards requests
carrying its own session cookie. Corp configs can now set
seal.headers/seal.cookies, which the client merges into every request;
cookies are rendered into one Cookie header and the session bearer
token still wins over any configured Authorization.

corps add-seal accepts both fields and applies them when verifying the
tenant, so a gated enterprise can be registered in one step.
This commit is contained in:
gitea committed 2026-09-10 16:25:11 +08:00
1 parent fc06434813
commit bb8b5edec6
6 files changed
+203 -6

No files matched your search

+22 -3
View File
@@ -10,12 +10,14 @@ import {
} from "../../core/auth/hose.js";
import { clearCorpTokenCache } from "../../core/auth/token-store.js";
import { createSealClientForUrl } from "../../core/http/factory.js";
import { resolveSealCustomHeaders } from "../../core/http/request-headers.js";
import {
loadCorpConfigs,
loadGlobalConfig,
resolveWritableEnterprisesDir,
saveGlobalConfig
} from "../../core/config/loader.js";
import { SealCookieMapSchema, SealHeaderMapSchema } from "../../core/config/types.js";
import type { CorpConfig } from "../../core/config/types.js";
import { getMe } from "../../domains/seal/api.js";
import { resolveLiveSealEnterpriseConfig } from "../../domains/seal/source.js";
@@ -374,8 +376,20 @@ async function addSealCorp(input: Record<string, unknown>) {
const expiresIn = optionalNumber(input, "expiresIn") ?? 30 * 24 * 60 * 60;
const verify = input.force === true || input.verify === false ? false : true;
const remote = verify ? await resolveSealWhoami(sealUrl, token) : undefined;
writeSealCorpConfig(input, { token, sealUrl, expiresIn, verify, remote });
const custom = sealCustomHeadersFromInput(input);
const remote = verify
? await resolveSealWhoami(sealUrl, token, resolveSealCustomHeaders(custom))
: undefined;
writeSealCorpConfig(input, { token, sealUrl, expiresIn, verify, remote, custom });
}
// Validates extra headers/cookies up front so a malformed name fails here
// rather than on the next config load.
function sealCustomHeadersFromInput(input: Record<string, unknown>) {
return {
headers: SealHeaderMapSchema.parse(input.headers),
cookies: SealCookieMapSchema.parse(input.cookies)
};
}
async function addLinkCorp(link: string, name: string | undefined, overwrite: boolean) {
@@ -419,9 +433,11 @@ function writeSealCorpConfig(
expiresIn: number;
verify: boolean;
remote?: RemoteSealIdentity;
custom?: { headers?: Record<string, string>; cookies?: Record<string, string> };
}
) {
const { token, sealUrl, expiresIn, verify, remote } = auth;
const custom = auth.custom ?? sealCustomHeadersFromInput(input);
const remoteUser = remote?.user;
const remoteTenant = remote?.tenant;
const tenantSlug = optionalString(input, "tenantSlug") ?? stringValue(remoteTenant?.tenantSlug);
@@ -447,6 +463,8 @@ function writeSealCorpConfig(
seal: {
url: sealUrl,
tenantSlug,
headers: custom.headers,
cookies: custom.cookies,
endpoints: {
approvalStylePreferences: "api/v1/agent/ai-approval/config"
}
@@ -522,8 +540,9 @@ async function resolveHoseCorporation(domain: string, appKey: string, appSecurit
: undefined;
}
async function resolveSealWhoami(sealUrl: string, token: string) {
async function resolveSealWhoami(sealUrl: string, token: string, customHeaders: Record<string, string> = {}) {
const json = await getJson(`${sealUrl}/api/v1/auth/me`, {
...customHeaders,
authorization: `Bearer ${token}`
});
const data = objectValue(json.data);