import { Gateway, type GatewayDependencies, type GatewayIo } from "../gateway/Gateway.js"; import { type GatewayConfig } from "../gateway/GatewayConfig.js"; import type { GatewaySelector } from "../http/GatewayHttpServer.js"; import { type TenantEntry } from "./TenantRegistry.js"; /** * What a tenant's gateway inherits from the host's environment: how to reach * the authority and how long to wait for it and for the upstream. Nothing * else crosses, and never a credential: each tenant's workspace key comes * from its own mounted file, and the host's own environment may hold keys * no tenant should ever run under. */ export declare const SHARED_ENVIRONMENT: readonly ["NODE_ENV", "DECIONIS_API_URL", "DECIONIS_TIMEOUT_MS", "DECIONIS_ALLOW_INSECURE_LOOPBACK", "AGENTSAFE_UPSTREAM_TIMEOUT_MS", "AGENTSAFE_FAILURE_POLICY", "AGENTSAFE_SHADOW_VERDICT_WAIT_MS"]; /** How long a replaced or removed tenant's gateway keeps finishing requests already in flight. */ export declare const DEFAULT_DRAIN_MS = 30000; /** The longest readiness waits for the tenants' first looks at their upstreams' proofs. */ export declare const PROOF_READY_CAP_MS = 30000; export interface TenantHostOptions { readonly registryPath: string; /** The host's environment; only `SHARED_ENVIRONMENT` reaches a tenant. */ readonly env: Readonly>; readonly io: GatewayIo; /** The registry's text, or null when there is no such file. */ readonly readFile: (path: string) => string | null; readonly version?: string; readonly drainMs?: number; /** * Every tenant's gateway forwards nothing until its upstream's origin * serves a token bound to the tenant (`--require-upstream-proof`). */ readonly requireUpstreamProof?: boolean; /** * The one tenant this host serves (`--tenant`), by its registry id: the * only kind of host an enforcing tenant runs on. A host without one serves * every tenant the registry names except those that enforce. */ readonly tenant?: string; readonly clock?: () => number; /** Assembles one tenant's gateway; `Gateway.create` unless a test says otherwise. */ readonly createGateway?: (config: GatewayConfig, dependencies: GatewayDependencies) => Promise; /** Handed to every tenant's gateway beside its own environment and output (transports, in tests). */ readonly dependencies?: Omit; } /** What one load of the registry did, as the host reports it. */ export interface TenantLoadReport { readonly event: "TENANT_REGISTRY_LOADED" | "TENANT_REGISTRY_REFUSED"; /** The code when the registry itself was refused; the tenants served are then unchanged. */ readonly code: string | null; /** The registry's text, as read, as a short digest; null when there was none to read. */ readonly revision: string | null; readonly served: number; readonly built: readonly string[]; readonly kept: number; /** Tenants whose gateway took new keys in place, without a rebuild. */ readonly rekeyed: readonly string[]; readonly retired: number; /** * Tenants that enforce, which a host shared by many tenants leaves to a * host of their own; never a failure, and empty on a host for one tenant. */ readonly dedicated: readonly string[]; /** * Tenants whose entry could not be applied, with the reason. Each keeps the * gateway it had, if it had one, admitting only keys its entry still lists; * when that is none, it is not served. */ readonly failed: readonly { readonly tenant: string; readonly code: string; }[]; } /** * Many tenants' gateways in one process, each at `{id}.{domain}`, built from * the registry the operator mounts. Every tenant gets an ordinary hosted * gateway (public-only upstream, operator-only status, host-only cookies, * its tenant key required) assembled from its entry and its own workspace * key file; nothing about one tenant is visible to another, because each * request is routed to one gateway by its host alone. A tenant shadows * unless its entry says it enforces, and an enforcing tenant is served only * by a host started for it alone (`tenant`), so no process another tenant * shares ever holds its upstream credential or its held requests. * * A reload rebuilds only the tenants whose entry changed, swaps the set at * once, and lets a replaced gateway drain before it is closed; the gateway * built in its place continues its chains, found by the tenant's id and not * its host, and takes over its upstream's proof at the swap, as it stands * then. A change to a tenant's keys alone rebuilds nothing: its gateway * takes them in place. A registry that cannot be read or is not valid * changes nothing: the tenants served stay served. */ export declare class TenantHost { private readonly options; private served; private readonly draining; private readonly timers; private queue; private closed; private refusal; private failing; private currentDomain; /** How the tenants' hosts are reached, once the listener is bound; null before. */ private scheme; /** When one load first served every tenant the registry names; null until then. */ private everyTenantServedAt; private readyLatched; /** The gateway for a request's host, or null (the listener answers 421). */ readonly select: GatewaySelector; private readonly clock; private constructor(); /** Loads the registry and builds every tenant; a registry that cannot be served refuses the start. */ static start(options: TenantHostOptions): Promise; /** * The tenants whose entry the last load could not apply: a reload with an * unchanged registry tries exactly these again, since every other tenant * is kept. A tenant whose key file had not arrived yet is one of them. */ failures(): readonly string[]; /** * Whether the process is ready for traffic: from the first load that served * every tenant its registry names, once each of their gateways has had its * first look at its upstream's proof, or 30 seconds have passed, and from * then on. A new process, in a rollout or after a restart, gets no traffic * while a tenant it should serve would be answered 421, or 503 only for * want of a first look; once ready, a tenant that cannot be built later * is reported, and never takes every other tenant out of service. */ ready(): boolean; /** The domain of the registry last loaded: the apex, and the parent of every tenant's host. */ domain(): string | null; /** The hostnames served, sorted. */ hostnames(): readonly string[]; /** * The listener is bound: every tenant's gateway starts, with its banner and * its chained start line, and so does each gateway built from now on as it * is swapped in. A started gateway reports its stop, and its shadow tally, * when it is replaced or the host stops. */ listening(scheme: "http" | "https"): void; /** Reads the registry again; reloads never overlap, and each is reported as one line. */ reload(): Promise; /** * Stops every gateway, the draining ones included, and closes them: the * draining ones first, so the head a journal persists last is the one the * live gateway links on. */ close(signal?: string): Promise; private load; /** * Makes a kept gateway admit exactly the keys its tenant's entry lists now, * in place and at once. Digests it refuses (malformed, repeated) leave it * only the keys it already admits that the entry still lists, and none of * those means it is not served: a key the registry dropped is never left * admitted because the rest of an entry could not be applied. */ private static rekey; /** The newest of a tenant's gateways still draining: the only one that may still persist its heads. */ private drainingFor; /** * One tenant's hosted gateway, from its entry, the shared environment and * its own key file; continuing the gateway it replaces, when there is one. */ private build; /** * The environment a tenant's gateway runs in: the shared settings, its own * entry, and the host's own settings for every tenant. An enforcing * tenant's gateway fails closed whatever the host's shared setting says, * and presents its upstream credential from the file its entry names; its * loader refuses it unless every other control hosted enforcement needs * is on as well. Any tenant's gateway sends the gateway token its entry * names. */ static tenantEnvironment(host: Readonly>, tenant: TenantEntry, settings?: { readonly upstreamProof?: boolean; readonly dedicated?: boolean; }): Record; /** * A tenant's key digests as its gateway's loader reads them: split at * commas, trimmed, and without empty values. A build and an in-place rekey * both start from these, so a reload of an entry the build admitted admits * the same keys, and never refuses them. */ private static keyDigests; /** * The tenant's own output: every line a tenant's gateway writes names its * tenant, so one process's stream can be read, retained and deleted per * tenant. A chained line already carries `tenant` in its envelope, covered * by its hash, and is passed through untouched: adding anything to it * would break the chain. Any other JSON line gets `tenant` first; anything * else is wrapped. */ static taggedIo(io: GatewayIo, tenant: string): GatewayIo; /** Why a tenant's gateway could not be built: a code and the setting, never a value. */ private static codeOf; /** * Lets a replaced or removed gateway finish what it has in flight, then * stops it, so its shadow report counts what settled while it drained. */ private drain; private report; } //# sourceMappingURL=TenantHost.d.ts.map