import { type AddressResolver } from "../egress/GuardedFetch.js"; import type { FetchLike } from "../handlers/HandlerRegistration.js"; import { type SecurityEvent } from "../incident/SecurityEvents.js"; /** * Where an upstream's origin serves its proof: one fixed path, so a token is * never part of a URL and an origin that echoes its URL cannot serve one. */ export declare const UPSTREAM_PROOF_PATH = "/.well-known/agentsafe-upstream"; /** The label a TXT proof is published under, in front of the upstream's host name. */ export declare const UPSTREAM_PROOF_TXT_LABEL = "_agentsafe-challenge"; /** The header a forwarded answer carries while its upstream's proof is missing. */ export declare const UPSTREAM_PROOF_HEADER = "agentsafe-upstream-proof"; /** The most a proof file, or one TXT record, may be; anything longer is not a proof. */ export declare const MAX_PROOF_BYTES = 1024; /** The TXT records read at the proof's name, in the order the resolver gives them. */ export declare const MAX_PROOF_RECORDS = 32; export declare const PROOF_TIMEOUT_MS = 10000; /** A proven upstream is checked again a day later, give or take the jitter. */ export declare const PROOF_RECHECK_MS: number; export declare const PROOF_JITTER_MS: number; /** While a proof is missing it is looked for every hour, and the gateway forwards for the grace. */ export declare const PROOF_MISSING_RECHECK_MS: number; export declare const PROOF_GRACE_MS: number; /** While the gateway forwards nothing, it looks every minute. */ export declare const PROOF_PENDING_RETRY_MS = 60000; /** * Whom a proof is for: the tenant's id, the Decionis organization it runs * under, and the upstream's origin as the WHATWG URL spells it (lower-case * host, no default port, no path). The base path is never part of it: the * gateway is sealed to the whole origin, so the proof covers the whole origin. */ export interface ProofBinding { readonly tenant: string; readonly org: string; readonly origin: string; } /** * The token that proves an origin for a tenant and an organization, issued * at a time in Unix seconds: `v1..`. There is no secret in it: whoever asks for a * token is given it, and what proves control is that only the origin's * controller can serve it there. */ export declare function proofToken(binding: ProofBinding, issued: number): string; /** * Whether any candidate, trimmed of white space at its ends and nothing * else, is a token bound to this tenant, organization and origin, at any * issue time: its age is onboarding's concern, never a recheck's. */ export declare function provesUpstream(candidates: readonly string[], binding: ProofBinding): boolean; /** * A proof file's lines. A comment, a blank line and anything else that is not * a token never proves anything, so nothing needs removing; a byte-order * mark at the start is dropped and a line's carriage return is trimmed with * its spaces. A body that is not UTF-8 has no lines at all, whatever one of * them might hold: onboarding refuses such a file whole, and so does this. */ export declare function proofLines(body: Uint8Array): readonly string[]; export type ProofMethod = "file" | "dns"; /** * What one check found. `missing` is definitive: the origin answered over * verified TLS and served no token bound to the tenant. `unreachable` is no * answer at all, which says nothing about the proof. */ export type ProofOutcome = { readonly kind: "proven"; readonly method: ProofMethod; } | { readonly kind: "missing"; } | { readonly kind: "unreachable"; readonly code: string; }; /** TXT lookup as `dns.promises.resolveTxt` answers it: each record as its strings. */ export type TxtResolver = (name: string) => Promise; export interface UpstreamProofCheckOptions { readonly resolveTxt: TxtResolver; /** Name resolution for the GET; the system resolver when absent. */ readonly resolve?: AddressResolver; /** A transport under the guard, for a test; `node:https` when absent. */ readonly transport?: FetchLike; } /** * One look at whether an upstream's origin serves a token bound to its * tenant. The GET goes through a guarded egress of the check's own, sealed * to the origin and the proof's path: public addresses only, a loopback name * refused, TLS verified against the public roots, redirects never followed, * at most 1 KiB, and no header of the tenant's. When the origin answers * without a token, a TXT record at `_agentsafe-challenge.` may prove it * instead; a record alone never does, because DNS is not authenticated and * only an answer over verified TLS ties the name to the origin traffic * reaches. Nothing it reads is kept or written anywhere: what it returns is * an outcome and a code. */ export declare class UpstreamProofCheck { private readonly binding; private readonly guard; private readonly resolveTxt; constructor(binding: ProofBinding, options: UpstreamProofCheckOptions); /** Looks once. Never rejects: every failure is an outcome. */ check(): Promise; close(): void; /** The TXT record at the origin's name, once the origin has answered; an address has no name. */ private txt; private static codeOf; } /** * Where a tenant's proof stands in this process. `pending`: not yet seen; * `verified`: seen, by file or by TXT; `missing`: gone since a time, and * forwarded for the grace after it; `unverified`: not served when first * looked for, or gone for longer than the grace. */ export type ProofState = { readonly kind: "pending"; } | { readonly kind: "verified"; readonly method: ProofMethod; } | { readonly kind: "missing"; readonly since: number; } | { readonly kind: "unverified"; }; /** What a change of state is reported as, on the tenant's security stream, before its origin. */ export type ProofEvent = { readonly event: "UPSTREAM_PROOF_MISSING"; readonly stops_at: string; } | { readonly event: "UPSTREAM_UNVERIFIED"; readonly code: "UPSTREAM_PROOF_NOT_SERVED" | "UPSTREAM_PROOF_GRACE_ENDED"; } | { readonly event: "UPSTREAM_PROOF_RESTORED"; readonly method: ProofMethod; }; export interface ProofStep { readonly state: ProofState; readonly event: ProofEvent | null; } /** What a tenant's request gets: forwarded, forwarded and marked, or refused. */ export type ProofAdmission = "FORWARD" | "MISSING" | "REFUSE"; export declare const PENDING: ProofState; /** * The state after a check's outcome at a time. A proof seen is verified, * and restores a tenant that had lost it. A grace that has run out ends in * unverified, whatever the check found short of a proof. A miss starts the * grace for a verified tenant, and makes a tenant never seen unverified. An * origin that did not answer changes nothing. */ export declare function advance(state: ProofState, outcome: ProofOutcome, now: number): ProofStep; /** What a request gets in a state at a time: the grace ends on the clock, not at the next check. */ export declare function admission(state: ProofState, now: number): ProofAdmission; /** * How long until the next check, with `random` in [0, 1): a day either side * of an hour once verified, so a fleet's checks do not fall together; every * hour while missing, and at the end of the grace; every minute otherwise. */ export declare function nextCheckIn(state: ProofState, now: number, random: number): number; /** What the operator's status shows of a tenant's proof: its state and times, never its text. */ export interface ProofSnapshot { readonly state: ProofState["kind"]; readonly method: ProofMethod | null; readonly checked_at: string | null; readonly stops_at: string | null; /** Why the last check had no answer, when it had none. */ readonly code: string | null; } /** * Whether a proof kept for one binding holds for another: the same tenant, * organization and origin, all three. A gateway rebuilt with any of them * changed looks from the start, so an edit to a registry entry never carries * a proof over to a binding no origin has proved. */ export declare function sameBinding(kept: ProofBinding, binding: ProofBinding): boolean; /** * Where a tenant's proof stands, whole: its state, when it was last looked * at and why that look had no answer, when the next look is due, and whether * any look has ended. A gateway built to replace another takes it over as it * stands at the swap, so a rebuild neither forgets the last look nor moves * the next one. */ export interface ProofStanding { readonly state: ProofState; readonly checkedAt: number | null; readonly code: string | null; /** When the next look is due; null while one is in flight, so whoever takes over looks at once. */ readonly dueAt: number | null; readonly settled: boolean; } export interface UpstreamProofMonitorOptions { readonly origin: string; /** One look; never rejects. */ readonly check: () => Promise; /** Puts a change of state on the tenant's security stream. */ readonly report: (event: SecurityEvent) => void; readonly clock: () => number; readonly random: () => number; } /** * A tenant's proof, kept: looked at once when nothing is known, or taken * over from the monitor it replaces, then on the cadence its state sets, each * change reported. It holds no socket and no timer that keeps a process alive. */ export declare class UpstreamProofMonitor { private readonly options; private state; private settledOnce; private checkedAt; private lastCode; private dueAt; private timer; private stopped; constructor(options: UpstreamProofMonitorOptions); /** Looks now: nothing is known yet. */ start(): void; /** * Takes up a proof where another monitor bound the same way left it: its * state and last look as they were, and its next look when it was due, or * at once when that monitor was stopped with a look in flight. */ resume(standing: ProofStanding): void; /** Whether a look has finished, here or in the monitor this one took over from. */ get settled(): boolean; get current(): ProofState; /** Everything another monitor needs to go on from here; read it once this one is stopped. */ standing(): ProofStanding; admits(): ProofAdmission; snapshot(): ProofSnapshot; /** No further look, and a look in flight changes nothing when it ends. */ stop(): void; private run; /** The next look, at a time; one already due runs at once. */ private schedule; } //# sourceMappingURL=UpstreamProof.d.ts.map