feat: support split Dashboard and API origins (ADR 0045)
CI / verify (pull_request) Successful in 51s
CI / infrastructure-smoke (pull_request) Successful in 20s
CI / migration-smoke (pull_request) Successful in 1m49s
CI / image-build (pull_request) Successful in 17s
CI / deploy-smoke (same-origin) (pull_request) Successful in 48s
CI / deploy-smoke (split) (pull_request) Successful in 55s
CI / verify (pull_request) Successful in 51s
CI / infrastructure-smoke (pull_request) Successful in 20s
CI / migration-smoke (pull_request) Successful in 1m49s
CI / image-build (pull_request) Successful in 17s
CI / deploy-smoke (same-origin) (pull_request) Successful in 48s
CI / deploy-smoke (split) (pull_request) Successful in 55s
An installation can now serve the Dashboard and the API on sibling hostnames (dash./api.) beside the default same-origin topology, from one image and with configuration alone. - The Dashboard learns its API origin at run time: the built page carries one empty <meta name="ekklesia-api-origin">, which the API fills with its identity base URL's origin at startup, before computing the page's ETag. The shell accepts only a canonical http(s) origin and otherwise fails closed without making a request. The build-time EKKLESIA_API_BASE_URL is gone from the bundle; the development server injects the same element. - The display host stays on the API's origin, so its device cookies, requests, and offline cache are unchanged. - The API trusts its own origin (trusted origins plus the identity base URL), as Better Auth already does, so the display page's mutations pass the origin check without operators listing it. - Doctor validates EKKLESIA_DASHBOARD_ORIGIN exactly as the API's startup does (it previously skipped it), reports the topology without printing hostnames, and warns when split hostnames are not siblings. - The module UI contract states the CORS header limit (safelisted headers plus Content-Type, safelisted response headers only). - Reference deployment: Caddyfile.split.example (Dashboard hostname serves / and its script; API hostname serves /api/*, /display/*, and the display script; each refuses the other's paths) and EKKLESIA_DASHBOARD_HOSTNAME in the proxy overlay and env examples. - The deploy smoke test runs either topology (CI runs both). The split run installs the module template as a test-only module, checks per-hostname routing and exact CORS, then drives a digest-pinned headless Chromium over the DevTools protocol, with no added dependency: sign-in on the Dashboard hostname, the session cookie host-only on the API hostname, the module UI imported cross-origin and its credentialed request succeeding, the display and its service worker on the API hostname, and sign-out. ADR 0045 is marked Accepted. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
55accd0e65
commit
65908ac97c
@@ -757,6 +757,35 @@ function identitySchemaSummary(): string {
|
||||
return `Core identity schema defines ${tableNames.length} ${plural(tableNames.length, "table")} (${tableNames.join(", ")}).`;
|
||||
}
|
||||
|
||||
/**
|
||||
* A heuristic for "same site" between two canonical origins, for a warning only (ADR 0045).
|
||||
*
|
||||
* The same hostname on another port is the same site. Otherwise the two hostnames must be siblings:
|
||||
* identical after their first label, with that parent itself holding at least one dot
|
||||
* (`dash.example.org` and `api.example.org`). Without the Public Suffix List this can be wrong in
|
||||
* both directions for unusual names, which is why its result is a warning and never a failure.
|
||||
*/
|
||||
function plausiblySameSite(dashboardOrigin: string, apiOrigin: string): boolean {
|
||||
const dashboard = new URL(dashboardOrigin).hostname;
|
||||
const api = new URL(apiOrigin).hostname;
|
||||
if (dashboard === api) {
|
||||
return true;
|
||||
}
|
||||
// An IP address is a site of its own; two different ones never share one.
|
||||
const isIpAddress = (hostname: string): boolean =>
|
||||
hostname.startsWith("[") || /^[0-9]+(\.[0-9]+){3}$/u.test(hostname);
|
||||
if (isIpAddress(dashboard) || isIpAddress(api)) {
|
||||
return false;
|
||||
}
|
||||
const parent = (hostname: string): string => hostname.slice(hostname.indexOf(".") + 1);
|
||||
return (
|
||||
dashboard.includes(".") &&
|
||||
api.includes(".") &&
|
||||
parent(dashboard) === parent(api) &&
|
||||
parent(dashboard).includes(".")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pure configuration validation only: never constructs Better Auth, never opens a database
|
||||
* connection, and never prints the configured secret, base URL, or trusted origins. Missing
|
||||
@@ -769,6 +798,7 @@ function identityConfigurationCheck(
|
||||
const hasAnyValue =
|
||||
input?.secret !== undefined ||
|
||||
input?.baseUrl !== undefined ||
|
||||
(input?.dashboardOrigin ?? "") !== "" ||
|
||||
input?.publicSignupEnabled !== undefined ||
|
||||
(input?.trustedOrigins?.length ?? 0) > 0;
|
||||
|
||||
@@ -783,17 +813,43 @@ function identityConfigurationCheck(
|
||||
const config = createIdentityConfig(
|
||||
{
|
||||
baseUrl: input?.baseUrl,
|
||||
// Validated exactly as the API validates it at startup, so a Dashboard origin the API would
|
||||
// refuse (untrusted, insecure, malformed) fails here first.
|
||||
dashboardOrigin: input?.dashboardOrigin,
|
||||
publicSignupEnabled: input?.publicSignupEnabled,
|
||||
secret: input?.secret,
|
||||
trustedOrigins: input?.trustedOrigins,
|
||||
},
|
||||
{ environment: input?.environment ?? "production" },
|
||||
);
|
||||
const signupDetail = config.publicSignupEnabled
|
||||
? "Public signup is explicitly ENABLED."
|
||||
: "Public signup is disabled (safe default).";
|
||||
if (config.dashboardOrigin === config.baseUrl) {
|
||||
return freezeCheck("identity.configuration", "pass", "Identity configuration valid", [
|
||||
schemaDetail,
|
||||
signupDetail,
|
||||
"Topology: same-origin (the Dashboard is served from the API's origin).",
|
||||
]);
|
||||
}
|
||||
const topologyDetail = "Topology: split (the Dashboard and the API are on separate origins).";
|
||||
if (!plausiblySameSite(config.dashboardOrigin, config.baseUrl)) {
|
||||
return freezeCheck(
|
||||
"identity.configuration",
|
||||
"warning",
|
||||
"Identity configuration valid; split origins may not share a site",
|
||||
[
|
||||
schemaDetail,
|
||||
signupDetail,
|
||||
topologyDetail,
|
||||
"The Dashboard and API hostnames are not siblings under one parent domain. Browsers send the session cookie across split origins only within one registrable domain (ADR 0045); Doctor cannot check the Public Suffix List, so confirm it.",
|
||||
],
|
||||
);
|
||||
}
|
||||
return freezeCheck("identity.configuration", "pass", "Identity configuration valid", [
|
||||
schemaDetail,
|
||||
config.publicSignupEnabled
|
||||
? "Public signup is explicitly ENABLED."
|
||||
: "Public signup is disabled (safe default).",
|
||||
signupDetail,
|
||||
topologyDetail,
|
||||
]);
|
||||
} catch (error) {
|
||||
const code =
|
||||
|
||||
@@ -705,6 +705,88 @@ describe("Ekklesia Doctor diagnostics", () => {
|
||||
expect(report.result).toBe("ready-with-warnings"); // PostgreSQL is still skipped in this fixture
|
||||
});
|
||||
|
||||
describe("Dashboard and API topology (ADR 0045)", () => {
|
||||
const secret = "correct-horse-battery-staple-0123456789";
|
||||
async function identityCheck(identity: {
|
||||
readonly baseUrl: string;
|
||||
readonly dashboardOrigin?: string;
|
||||
readonly environment?: "development" | "production";
|
||||
readonly trustedOrigins: readonly string[];
|
||||
}) {
|
||||
const report = await diagnoseEkklesia(
|
||||
{
|
||||
...options(),
|
||||
identityConfiguration: { environment: "production", secret, ...identity },
|
||||
},
|
||||
dependencies(),
|
||||
);
|
||||
return { check: check(report, "identity.configuration"), report };
|
||||
}
|
||||
|
||||
it("reports the same-origin topology when no Dashboard origin is set", async () => {
|
||||
const { check: identity } = await identityCheck({
|
||||
baseUrl: "https://ekklesia.example.test",
|
||||
trustedOrigins: ["https://ekklesia.example.test"],
|
||||
});
|
||||
expect(identity.status).toBe("pass");
|
||||
expect(identity.details).toContain(
|
||||
"Topology: same-origin (the Dashboard is served from the API's origin).",
|
||||
);
|
||||
});
|
||||
|
||||
it("reports the split topology for sibling hostnames without printing either", async () => {
|
||||
const { check: identity, report } = await identityCheck({
|
||||
baseUrl: "https://api.example.test",
|
||||
dashboardOrigin: "https://dash.example.test",
|
||||
trustedOrigins: ["https://dash.example.test"],
|
||||
});
|
||||
expect(identity.status).toBe("pass");
|
||||
expect(identity.details).toContain(
|
||||
"Topology: split (the Dashboard and the API are on separate origins).",
|
||||
);
|
||||
expect(JSON.stringify(report)).not.toContain("dash.example.test");
|
||||
expect(JSON.stringify(report)).not.toContain("api.example.test");
|
||||
});
|
||||
|
||||
it.each([
|
||||
["different registrable domains", "https://dash.example.test", "https://api.example.org"],
|
||||
["two IP addresses", "https://10.0.0.2", "https://10.0.0.1"],
|
||||
["a parent that is only a top-level domain", "https://dash.test", "https://api.test"],
|
||||
])("warns, without failing, when split hostnames may not share a site: %s", async (_case, dashboardOrigin, baseUrl) => {
|
||||
const { check: identity, report } = await identityCheck({
|
||||
baseUrl,
|
||||
dashboardOrigin,
|
||||
trustedOrigins: [dashboardOrigin],
|
||||
});
|
||||
expect(identity.status).toBe("warning");
|
||||
expect(identity.details.join("\n")).toContain("not siblings under one parent domain");
|
||||
expect(doctorExitCode(report)).toBe(0);
|
||||
});
|
||||
|
||||
it("treats another port on the same host as the same site (split development)", async () => {
|
||||
const { check: identity } = await identityCheck({
|
||||
baseUrl: "http://localhost:3000",
|
||||
dashboardOrigin: "http://localhost:5173",
|
||||
environment: "development",
|
||||
trustedOrigins: ["http://localhost:5173"],
|
||||
});
|
||||
expect(identity.status).toBe("pass");
|
||||
});
|
||||
|
||||
it("fails, as the API's startup would, for a Dashboard origin the API does not trust", async () => {
|
||||
const { check: identity, report } = await identityCheck({
|
||||
baseUrl: "https://api.example.test",
|
||||
dashboardOrigin: "https://dash.example.test",
|
||||
trustedOrigins: ["https://other.example.test"],
|
||||
});
|
||||
expect(identity.status).toBe("failure");
|
||||
expect(identity.details.some((detail) => detail.includes("DASHBOARD_ORIGIN_UNTRUSTED"))).toBe(
|
||||
true,
|
||||
);
|
||||
expect(doctorExitCode(report)).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
it("fails identity configuration for an invalid secret without leaking it", async () => {
|
||||
const hostileSecret = "s3cr3t-do-not-log";
|
||||
const report = await diagnoseEkklesia(
|
||||
|
||||
Reference in New Issue
Block a user