import { z } from "zod"; import { type EscalationConfig } from "../config/ExecutorConfig.js"; import { type ContainmentTarget } from "../containment/ContainmentProbe.js"; import { type ExposureDeclaration } from "../exposure/ExposureDeclaration.js"; import type { SecretName } from "../secrets/SecretStore.js"; import { type RateLimit } from "./RateLimit.js"; export type GatewayMode = "SHADOW" | "ENFORCEMENT"; export type FailurePolicy = "FAIL_CLOSED" | "FAIL_OPEN"; export type AuthorityKind = "LOCAL" | "DECIONIS"; export type UnmatchedPolicy = "GOVERN" | "PASSTHROUGH"; /** * What of a governed request the authority receives. `FULL` is the method, * path, query and, within the embedding bound, the body. `FACTS` is the API * profile's operation id and path template and the facts it names, and never * a raw path, query, header or body byte. */ export type PrivacyMode = "FULL" | "FACTS"; export type OutputFormat = "HUMAN" | "JSON"; /** The methods a route governs unless it names its own; a safe method is never consequential. */ export declare const CONSEQUENTIAL_METHODS: readonly ["POST", "PUT", "PATCH", "DELETE"]; export type ConsequentialMethod = (typeof CONSEQUENTIAL_METHODS)[number]; /** The intent contract's action name: what a route may call the action it governs. */ export declare const ACTION_NAME: RegExp; /** The header a tenant presents its ingress key in; never the URL, never forwarded. */ export declare const TENANT_KEY_HEADER = "agentsafe-tenant-key"; /** The header a caller presents a subject session in, from the gateway's token exchange; never forwarded. */ export declare const SESSION_HEADER = "agentsafe-session"; /** The header a caller presents the identity provider's subject token in, per request; never forwarded. */ export declare const SUBJECT_TOKEN_HEADER = "agentsafe-subject-token"; /** * The header the gateway presents its own token to the upstream in, so the * upstream can tell a request came through it; a caller's value is never forwarded. */ export declare const GATEWAY_TOKEN_HEADER = "agentsafe-gateway-token"; /** The secret the gateway token is opened as, from the file its configuration names. */ export declare const GATEWAY_TOKEN_SECRET = "AGENTSAFE_GATEWAY_TOKEN"; /** The secret an acceptance report is signed with, opened from `acceptance.key.file`. */ export declare const ACCEPTANCE_KEY_SECRET = "AGENTSAFE_ACCEPTANCE_KEY"; /** The bearer of `/_agentsafe/v1/acceptance`, opened from `acceptance.operatorToken.file`. */ export declare const ACCEPTANCE_TOKEN_SECRET = "AGENTSAFE_ACCEPTANCE_TOKEN"; /** The tenant the demo authority evaluates under; a reserved fixture identifier, never an organization. */ export declare const LOCAL_TENANT_ID = "00000000-0000-4000-8000-000000000009"; export declare const DEFAULT_AUTHORITY_ENDPOINT = "https://api.decionis.com"; export declare const DEFAULT_LISTEN: { readonly host: "127.0.0.1"; readonly port: 8080; }; /** How long after a refusal its target is read again, by default, and at most. */ export declare const DEFAULT_REFUSAL_WINDOW_MS = 1000; export declare const MAX_REFUSAL_WINDOW_MS = 30000; /** The longest a shadow answer may wait for its observation: well under any caller's timeout. */ export declare const MAX_SHADOW_VERDICT_WAIT_MS = 2000; /** * The longest a hold may last: the authority lets an intent live this long * only when it asks the policy for its approvers (a managed escalation that * names no approver), and still mints its grant only after the approval. */ export declare const MAX_HOLD_TTL_SECONDS: number; /** * Who a session is for: the identity provider whose short-lived token names * the subject (the customer in context), and where in the token the subject * is. The gateway pins that subject for the session. */ export interface SubjectConfig { readonly issuer: string; readonly audience: string; /** A JWKS document on disk; the first key set, and the one kept when a refresh fails. */ readonly jwksFile: string | null; /** Where the key set is refreshed from, through the guarded egress; fetched at start without a file. */ readonly jwksUrl: string | null; /** The claim naming the subject; `sub` by default. */ readonly claim: string; /** The longest a session from the token exchange lasts; never past the token's own expiry. */ readonly sessionTtlSeconds: number; } export interface RouteConfig { readonly path: string; readonly action: string; readonly methods: readonly ConsequentialMethod[]; /** A published immutable policy bundle UUID, not a workspace policy head or rule ID. */ readonly policyId?: string; /** An exact published policy version; when both selectors are set, both must match. */ readonly policyVersion?: string; /** * The route releases money: where its amount, currency and subjects are, * so each payment is reserved against the organisation's cumulative limits * before it is forwarded (docs/gateway/exposure.md). Absent, the route is * governed exactly as before. */ readonly exposure?: ExposureDeclaration; } /** * Everything the gateway runs on, resolved from flags, environment, file and * defaults in that order, with no secret value in it: the names of the * secrets it needs are in `secrets.required`, and the values are opened by a * store at start, the way the executor's are. */ export interface GatewayConfig { readonly listen: { readonly host: string; readonly port: number; }; /** * Run for a tenant by someone else, as Decionis runs hosted shadow: the * upstream is public-only, the mode is shadow, the gateway's own status and * metrics answer only the operator, a relayed cookie is host-only, and a * relayed response is sandboxed (no script runs in it). */ readonly hosted: boolean; /** * The tenant a hosted gateway runs for, as its registry id: written into the * envelope of every chained line, so the tenant is covered by the hash. */ readonly hostedTenant: string | null; /** * A hosted gateway that is the only gateway its process serves: a host * started for one tenant (`agentsafe host --tenant`), or a single hosted * gateway. A hosted gateway enforces nowhere else, so no other tenant's * process ever holds its credentials or its held requests. */ readonly hostedDedicated: boolean; /** * The tenant's ingress keys, as `sha256:` digests: one, or two while a * rotation overlaps. When there are any, a request that is not the * gateway's own must carry a key in `AgentSafe-Tenant-Key` that hashes to * one of them. The key itself is never in the configuration. */ readonly tenantKeys: readonly string[]; /** * The rate this gateway admits its traffic at, after the tenant key: a * sustained rate and a burst, per process. A hosted gateway without one * gets HOSTED_DEFAULT_RATE_LIMIT; otherwise null is no limit. */ readonly rateLimit: RateLimit | null; readonly upstream: { readonly url: string; /** A plain-HTTP upstream off loopback is refused unless this says the network protects the hop. */ readonly insecure: boolean; /** * Connect to the upstream only at public addresses, through the guarded * egress. For a gateway whose upstream someone else chose, as a hosted * tenant does: a name that resolves to a private, shared, platform or * loopback address is refused before a socket exists. */ readonly publicOnly: boolean; /** * Forward nothing until the upstream's origin serves a token bound to this * tenant, its organization and that origin, and keep checking that it * does (gateway/UpstreamProof.ts). Hosted only: the binding is the * hosted tenant and the Decionis organization it runs under. */ readonly proofRequired: boolean; /** * The credential the gateway, and not its caller, presents to the * upstream: one header it sets on every request it forwards, whose value * is the secret in `file` (opened as `DOWNSTREAM_CREDENTIAL`, and followed * when the file is rotated). A caller's own value of that header is * dropped. Null forwards the caller's headers as they are. */ readonly credential: { readonly header: string; readonly file: string; } | null; /** * The gateway's own token: the secret in `file` (opened as * `AGENTSAFE_GATEWAY_TOKEN`, and followed when the file is rotated), sent * as `AgentSafe-Gateway-Token` on every request it forwards, so the * upstream can tell the request came through this gateway. It is apart * from `credential`, which stands in for the caller. Null sends none; a * caller's own value of that header is dropped either way. */ readonly gatewayToken: { readonly file: string; } | null; readonly system: string; readonly environment: string; readonly timeoutMs: number; readonly maxResponseBytes: number; }; readonly authority: { readonly kind: AuthorityKind; readonly endpoint: string; readonly mode: GatewayMode; readonly failurePolicy: FailurePolicy; readonly tenantId: string; readonly timeoutMs: number; readonly allowInsecureLoopback: boolean; /** * The key is a workspace an example provisioned without an account, which * the authority evaluates in shadow only; enforcement needs an owned key. */ readonly provisional: boolean; }; readonly interception: { readonly http: boolean; readonly routes: readonly RouteConfig[]; readonly unmatched: UnmatchedPolicy; readonly maxBodyBytes: number; /** The largest JSON body embedded in the intent for policy to read; 0 embeds none. */ readonly maxEmbeddedBodyBytes: number; /** A request header whose value names the calling principal; carried, never verified. */ readonly principalHeader: string | null; /** * The API intent profile (`agent-safe.profile.api/1`) the gateway governs by, after any * explicit route: its operations name the action and the facts. Null governs by routes only. */ readonly profile: string | null; /** `FACTS`: the authority receives the profile's operation and facts, never the request. */ readonly privacy: PrivacyMode; /** * Facts-only privacy: a file in the tenant's custody holding the key its * keyed digests (`request_hmac_sha256`, the keyed idempotency key) are * derived from, so every replica states the same values. Null keys them * with a secret each gateway process makes for itself. */ readonly digestKeyFile: string | null; /** * Refuse a call the profile cannot check: a read no profile operation * names, a path beneath one, and a write neither a route nor an operation * names (a batch included), whatever `unmatched` says. On by default when * the gateway pins subjects with a profile. */ readonly refuseUnknownReads: boolean; /** * After a BLOCK, a held ESCALATE or a fail-closed refusal of a write whose * profile operation names a read, read the target again and record what * it showed (`REFUSAL_OBSERVATION`): one more `GET` per refusal. On by * default; enforcement only. */ readonly observeRefusals: boolean; /** How long after the refusal that read is made, so the window it covers is not empty. */ readonly refusalWindowMs: number; }; /** Subject-bound sessions: null when the gateway pins no subject. */ readonly subject: SubjectConfig | null; /** * The systems of record the agent zone must not reach except through this * gateway, as the operator declares them. Nothing here dials them: they are * part of what the deployment says it is (its fingerprint), and what * `agentsafe probe-containment` is pointed at. */ readonly containment: { readonly targets: readonly ContainmentTarget[]; }; /** * An acceptance run's two secrets, or null when the gateway serves no run * (ADR 0009): the key that signs its reports and nothing else, and the * bearer the operator's tool presents on `/_agentsafe/v1/acceptance`. Each * is a file, opened as a secret; `kid` names the key in a report's header, * its RFC 7638 thumbprint when null. */ readonly acceptance: { readonly key: { readonly file: string; }; readonly operatorToken: { readonly file: string; }; readonly kid: string | null; } | null; readonly actor: { readonly id: string; readonly type: string; readonly runtime: string; }; /** * What the operator calls this enforcement boundary. Null leaves it to be * derived from the configuration, which is stable across restarts; see * `boundary/BoundaryIdentity.ts`. */ readonly boundary: { readonly id: string | null; }; readonly intentTtlSeconds: number; /** * In shadow, how long a forwarded answer may wait, after the upstream has * answered, for the observation to settle so `AgentSafe-Shadow-Verdict` * can name it. 0, the default, never waits: the header says what had * settled by then, or `PENDING`. */ readonly shadowVerdictWaitMs: number; /** * Where held requests are kept: a directory every replica mounts, each hold * sealed under the key in `keyFile`. Null keeps them in this process's * memory, where a restart loses them and only this replica can resume them. */ readonly holds: { readonly dir: string; readonly keyFile: string; } | null; readonly escalation: EscalationConfig; readonly evidence: { readonly enabled: boolean; readonly journalDir: string | null; /** * Who the gateway's effect evidence names as its observer: the identity * the authority's trusted-observer allowlist must list for a read-back to * be recorded `CONFIRMED`. Null names the boundary. */ readonly observer: string | null; }; readonly output: { readonly format: OutputFormat; readonly verbose: boolean; }; readonly production: boolean; readonly secrets: { readonly required: readonly SecretName[]; }; /** Where the value of each setting came from, for `agentsafe config`. */ readonly sources: Readonly>; } export type ConfigSource = "flag" | "environment" | "file" | "credentials" | "default"; /** The file, `agentsafe.yaml`: `version: 1` and any of these sections; an unknown key is refused by name. */ export declare const GatewayFileSchema: z.ZodObject<{ version: z.ZodLiteral<1>; gateway: z.ZodOptional; upstream: z.ZodOptional; upstreamInsecure: z.ZodOptional; upstreamPublicOnly: z.ZodOptional; upstreamCredential: z.ZodOptional>; gatewayToken: z.ZodOptional>; hosted: z.ZodOptional; tenantKeyDigests: z.ZodOptional>; rateLimit: z.ZodOptional>; upstreamTimeoutMs: z.ZodOptional; system: z.ZodOptional; environment: z.ZodOptional; }, z.core.$strict>>; authority: z.ZodOptional, z.ZodString]>>; mode: z.ZodOptional, unknown>>; failurePolicy: z.ZodOptional, unknown>>; tenantId: z.ZodOptional; timeoutMs: z.ZodOptional; allowInsecureLoopback: z.ZodOptional; }, z.core.$strict>>; decionis: z.ZodOptional, z.ZodString]>>; mode: z.ZodOptional, unknown>>; failurePolicy: z.ZodOptional, unknown>>; tenantId: z.ZodOptional; timeoutMs: z.ZodOptional; allowInsecureLoopback: z.ZodOptional; }, z.core.$strict>>; interception: z.ZodOptional; routes: z.ZodOptional, unknown>>>; policyId: z.ZodOptional>; policyVersion: z.ZodOptional>; exposure: z.ZodOptional, unknown>>; amount: z.ZodOptional; amountUnit: z.ZodOptional, unknown>>; currency: z.ZodOptional; subjects: z.ZodOptional; customer: z.ZodOptional; sku: z.ZodOptional; agent: z.ZodOptional; }, z.core.$strict>>; settledAmount: z.ZodOptional; failurePolicy: z.ZodOptional, unknown>>; }, z.core.$strict>>; }, z.core.$strict>>>; unmatched: z.ZodOptional, unknown>>; maxBodyBytes: z.ZodOptional; maxEmbeddedBodyBytes: z.ZodOptional; principalHeader: z.ZodOptional; profile: z.ZodOptional; privacy: z.ZodOptional, unknown>>; digestKeyFile: z.ZodOptional; refuseUnknownReads: z.ZodOptional; observeRefusals: z.ZodOptional; refusalWindowMs: z.ZodOptional; }, z.core.$strict>>; subject: z.ZodOptional; jwksUrl: z.ZodOptional; claim: z.ZodOptional; sessionTtlSeconds: z.ZodOptional; }, z.core.$strict>>; containment: z.ZodOptional>; }, z.core.$strict>>; acceptance: z.ZodOptional>; operatorToken: z.ZodOptional>; kid: z.ZodOptional; }, z.core.$strict>>; actor: z.ZodOptional; type: z.ZodOptional; }, z.core.$strict>>; boundary: z.ZodOptional; }, z.core.$strict>>; intentTtlSeconds: z.ZodOptional; shadow: z.ZodOptional; }, z.core.$strict>>; holds: z.ZodOptional; }, z.core.$strict>>; presence: z.ZodOptional; approverId: z.ZodOptional; approverRole: z.ZodOptional; level: z.ZodOptional, unknown>>; methods: z.ZodOptional, unknown>>>; }, z.core.$strict>>; evidence: z.ZodOptional; journalDir: z.ZodOptional; observer: z.ZodOptional; }, z.core.$strict>>; output: z.ZodOptional, unknown>>; verbose: z.ZodOptional; }, z.core.$strict>>; }, z.core.$strict>; export type GatewayFile = z.infer; /** What the command line may override; every field is optional and wins over everything else. */ export interface GatewayFlags { readonly upstream?: string; readonly port?: number; readonly listen?: string; readonly mode?: string; readonly failurePolicy?: string; readonly authority?: string; readonly verbose?: boolean; readonly json?: boolean; } /** A stored login: the key, and the organization and endpoint it belongs to. */ export interface StoredCredentials { readonly apiKey: string; readonly tenantId: string | null; readonly endpoint: string | null; /** True for a workspace an example provisioned without an account; absent for a login. */ readonly provisional?: boolean; } export interface GatewayConfigInput { readonly flags?: GatewayFlags; readonly env: Readonly>; /** The parsed file, or null when there is none. */ readonly file?: unknown; /** What `agentsafe login` stored, read by the command outside production; null when absent. */ readonly credentials?: StoredCredentials | null; /** This package's version, for the actor's runtime. */ readonly version: string; } /** A refusal to start that names the setting and never its value. */ export declare class GatewayConfigError extends Error { readonly code: string; readonly setting: string; constructor(code: string, setting: string, detail?: string | null); } /** Every variable the gateway and its commands read, for the reference page. */ export declare const GATEWAY_ENVIRONMENT: readonly string[]; /** `host:port`, `:port` (every interface) or a bare port; anything else is refused by setting. */ export declare function parseListen(value: string, setting: string): { host: string; port: number; }; /** * Resolves the gateway's configuration. Precedence is the command line, * then the environment, then the file, then the stored login for the * credential alone, then the defaults; each setting says which layer it * came from. Every refusal names the setting and never a value. */ export declare class GatewayConfigLoader { static load(input: GatewayConfigInput): GatewayConfig; /** Each declared containment target as `name=host:port`, refused by setting when it is not one. */ private static containmentTargets; /** * The subject section, when there is one: an issuer, an audience and a key * set, on disk or at an address the guarded egress fetches. The address is * https, or loopback with the authority's loopback allowance. */ private static subject; /** * Facts-only mode sends the authority a profile's operation and facts, so * it governs by a profile alone. Every setting that would put a raw part of * the request in front of the authority, or govern a call no operation * names, is refused by name rather than quietly overridden: a route (its * target is the raw path), a principal header (a raw header value), and an * explicit passthrough of unmatched calls (facts-only refuses them). */ private static factsOnly; /** The file's shape, refused by the name of the first key that is wrong. */ private static file; /** * The upstream is where authorized requests go. TLS is the default; a * loopback address may be plain, and anything else may be plain only when * the configuration says the network protects that hop. */ /** Both rate variables or neither: a rate without a burst, or the reverse, is refused by name. */ private static rateLimitFromEnvironment; /** * The tenant keys a running gateway may be given in place of its own: held * to the same rule as the configuration's, one or two distinct digests, * and at least one when it is hosted. */ static admittedKeys(digests: readonly string[], hosted: boolean): readonly string[]; /** * The upstream credential the gateway presents, from the environment or * the file: a header and the file holding its value, both or neither. The * header is one a credential can travel in without the gateway setting or * dropping it, and never one whose value reaches the authority. */ private static upstreamCredential; /** * An acceptance run's key and operator token, from the environment or the * file: both or neither, each an absolute path. One without the other is * refused, because a key with no way to ask for a run signs nothing, and a * token with nothing to sign opens runs that cannot close. */ private static acceptance; /** * The file holding the gateway's own token, from the environment or the * file: an absolute path, or none. The header it travels in is fixed, so * nothing about it can collide with what the authority reads. */ private static gatewayToken; /** Every control hosted enforcement needs, refused by the first one missing, by name. */ private static requireHostedEnforcement; /** Hosted, the tenant is the only caller the gateway admits, from day one. */ private static requireTenantKey; /** One or two distinct `sha256:` digests, lower-case hex; anything else is refused by name. */ private static tenantKeys; private static upstreamUrl; private static authorityUrl; /** * Where held requests live. A shared directory is for enforcement only * (shadow never holds), named by absolute paths, and the only place a hold * may outlive the authority's short intent window: that longer window is * for a managed escalation whose approvers the policy names, which is the * one the authority lets live up to seven days. */ private static holds; /** * How an `ESCALATE` is resolved, in the executor's own shape. Managed is * the gateway's default when Presence is configured at all: Decionis * orchestrates the ceremony and this process holds no Presence credential. * Direct is available for a deployment that already holds one. */ private static escalation; private static verdictWait; private static level; } /** The file `agentsafe init` writes: the smallest working configuration, commented. */ export declare function renderConfigFile(options: { readonly upstream: string; readonly listen: string; readonly mode: GatewayMode; readonly routes: readonly RouteConfig[]; }): string; //# sourceMappingURL=GatewayConfig.d.ts.map