@decionis/agentsafe 0.6.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +68 -20
- package/dist/Cli.js +30 -3
- package/dist/Cli.js.map +1 -1
- package/dist/Index.d.ts +5 -3
- package/dist/Index.d.ts.map +1 -1
- package/dist/Index.js +3 -1
- package/dist/Index.js.map +1 -1
- package/dist/TrustedExecutor.d.ts.map +1 -1
- package/dist/TrustedExecutor.js +2 -0
- package/dist/TrustedExecutor.js.map +1 -1
- package/dist/acceptance/AcceptancePlan.d.ts +109 -0
- package/dist/acceptance/AcceptancePlan.d.ts.map +1 -0
- package/dist/acceptance/AcceptancePlan.js +128 -0
- package/dist/acceptance/AcceptancePlan.js.map +1 -0
- package/dist/acceptance/AcceptanceReport.d.ts +596 -0
- package/dist/acceptance/AcceptanceReport.d.ts.map +1 -0
- package/dist/acceptance/AcceptanceReport.js +361 -0
- package/dist/acceptance/AcceptanceReport.js.map +1 -0
- package/dist/acceptance/AcceptanceRun.d.ts +118 -0
- package/dist/acceptance/AcceptanceRun.d.ts.map +1 -0
- package/dist/acceptance/AcceptanceRun.js +419 -0
- package/dist/acceptance/AcceptanceRun.js.map +1 -0
- package/dist/acceptance/Coverage.d.ts +12 -0
- package/dist/acceptance/Coverage.d.ts.map +1 -0
- package/dist/acceptance/Coverage.js +48 -0
- package/dist/acceptance/Coverage.js.map +1 -0
- package/dist/acceptance/OutageDoubles.d.ts +34 -0
- package/dist/acceptance/OutageDoubles.d.ts.map +1 -0
- package/dist/acceptance/OutageDoubles.js +67 -0
- package/dist/acceptance/OutageDoubles.js.map +1 -0
- package/dist/acceptance/ZoneProbes.d.ts +368 -0
- package/dist/acceptance/ZoneProbes.d.ts.map +1 -0
- package/dist/acceptance/ZoneProbes.js +488 -0
- package/dist/acceptance/ZoneProbes.js.map +1 -0
- package/dist/adapters/JcsDigest.d.ts +6 -5
- package/dist/adapters/JcsDigest.d.ts.map +1 -1
- package/dist/adapters/JcsDigest.js +9 -8
- package/dist/adapters/JcsDigest.js.map +1 -1
- package/dist/adapters/mcp/McpGuard.d.ts +32 -3
- package/dist/adapters/mcp/McpGuard.d.ts.map +1 -1
- package/dist/adapters/mcp/McpGuard.js +29 -5
- package/dist/adapters/mcp/McpGuard.js.map +1 -1
- package/dist/adapters/mcp/McpIntentBinder.d.ts +18 -3
- package/dist/adapters/mcp/McpIntentBinder.d.ts.map +1 -1
- package/dist/adapters/mcp/McpIntentBinder.js +48 -1
- package/dist/adapters/mcp/McpIntentBinder.js.map +1 -1
- package/dist/adapters/mcp/McpInvocation.d.ts +9 -2
- package/dist/adapters/mcp/McpInvocation.d.ts.map +1 -1
- package/dist/adapters/mcp/McpInvocation.js.map +1 -1
- package/dist/cli/Accept.d.ts +9 -0
- package/dist/cli/Accept.d.ts.map +1 -0
- package/dist/cli/Accept.js +209 -0
- package/dist/cli/Accept.js.map +1 -0
- package/dist/cli/Actions.d.ts +16 -0
- package/dist/cli/Actions.d.ts.map +1 -0
- package/dist/cli/Actions.js +194 -0
- package/dist/cli/Actions.js.map +1 -0
- package/dist/cli/Arguments.d.ts +4 -0
- package/dist/cli/Arguments.d.ts.map +1 -1
- package/dist/cli/Arguments.js +12 -3
- package/dist/cli/Arguments.js.map +1 -1
- package/dist/cli/Commands.d.ts +1 -1
- package/dist/cli/Commands.d.ts.map +1 -1
- package/dist/cli/Commands.js +5 -0
- package/dist/cli/Commands.js.map +1 -1
- package/dist/cli/ConfigCommand.d.ts.map +1 -1
- package/dist/cli/ConfigCommand.js +10 -0
- package/dist/cli/ConfigCommand.js.map +1 -1
- package/dist/cli/Doctor.d.ts.map +1 -1
- package/dist/cli/Doctor.js +67 -1
- package/dist/cli/Doctor.js.map +1 -1
- package/dist/cli/Help.d.ts.map +1 -1
- package/dist/cli/Help.js +18 -1
- package/dist/cli/Help.js.map +1 -1
- package/dist/cli/Host.d.ts +5 -2
- package/dist/cli/Host.d.ts.map +1 -1
- package/dist/cli/Host.js +24 -2
- package/dist/cli/Host.js.map +1 -1
- package/dist/cli/Identity.d.ts +13 -1
- package/dist/cli/Identity.d.ts.map +1 -1
- package/dist/cli/Identity.js +25 -2
- package/dist/cli/Identity.js.map +1 -1
- package/dist/cli/Profile.d.ts +24 -0
- package/dist/cli/Profile.d.ts.map +1 -0
- package/dist/cli/Profile.js +168 -0
- package/dist/cli/Profile.js.map +1 -0
- package/dist/cli/Records.d.ts +15 -0
- package/dist/cli/Records.d.ts.map +1 -0
- package/dist/cli/Records.js +205 -0
- package/dist/cli/Records.js.map +1 -0
- package/dist/cli/Status.d.ts +23 -0
- package/dist/cli/Status.d.ts.map +1 -1
- package/dist/cli/Status.js +80 -18
- package/dist/cli/Status.js.map +1 -1
- package/dist/cli/VerifyAcceptance.d.ts +38 -0
- package/dist/cli/VerifyAcceptance.d.ts.map +1 -0
- package/dist/cli/VerifyAcceptance.js +143 -0
- package/dist/cli/VerifyAcceptance.js.map +1 -0
- package/dist/config/ConfigKeys.d.ts +2 -2
- package/dist/config/ConfigKeys.d.ts.map +1 -1
- package/dist/config/ConfigKeys.js +6 -0
- package/dist/config/ConfigKeys.js.map +1 -1
- package/dist/config/ExecutorConfig.d.ts +35 -1
- package/dist/config/ExecutorConfig.d.ts.map +1 -1
- package/dist/config/ExecutorConfig.js +53 -1
- package/dist/config/ExecutorConfig.js.map +1 -1
- package/dist/egress/ZoneHttpClient.d.ts +3 -0
- package/dist/egress/ZoneHttpClient.d.ts.map +1 -0
- package/dist/egress/ZoneHttpClient.js +72 -0
- package/dist/egress/ZoneHttpClient.js.map +1 -0
- package/dist/exposure/DecionisExposureLedger.d.ts +44 -0
- package/dist/exposure/DecionisExposureLedger.d.ts.map +1 -0
- package/dist/exposure/DecionisExposureLedger.js +175 -0
- package/dist/exposure/DecionisExposureLedger.js.map +1 -0
- package/dist/exposure/ExposureDeclaration.d.ts +68 -0
- package/dist/exposure/ExposureDeclaration.d.ts.map +1 -0
- package/dist/exposure/ExposureDeclaration.js +83 -0
- package/dist/exposure/ExposureDeclaration.js.map +1 -0
- package/dist/exposure/ExposureFacts.d.ts +61 -0
- package/dist/exposure/ExposureFacts.d.ts.map +1 -0
- package/dist/exposure/ExposureFacts.js +201 -0
- package/dist/exposure/ExposureFacts.js.map +1 -0
- package/dist/exposure/ExposureGate.d.ts +144 -0
- package/dist/exposure/ExposureGate.d.ts.map +1 -0
- package/dist/exposure/ExposureGate.js +446 -0
- package/dist/exposure/ExposureGate.js.map +1 -0
- package/dist/exposure/ExposureLedger.d.ts +93 -0
- package/dist/exposure/ExposureLedger.d.ts.map +1 -0
- package/dist/exposure/ExposureLedger.js +24 -0
- package/dist/exposure/ExposureLedger.js.map +1 -0
- package/dist/gateway/AttemptStore.d.ts +83 -0
- package/dist/gateway/AttemptStore.d.ts.map +1 -0
- package/dist/gateway/AttemptStore.js +229 -0
- package/dist/gateway/AttemptStore.js.map +1 -0
- package/dist/gateway/ForwardHandler.d.ts +50 -6
- package/dist/gateway/ForwardHandler.d.ts.map +1 -1
- package/dist/gateway/ForwardHandler.js +58 -14
- package/dist/gateway/ForwardHandler.js.map +1 -1
- package/dist/gateway/Gateway.d.ts +347 -15
- package/dist/gateway/Gateway.d.ts.map +1 -1
- package/dist/gateway/Gateway.js +1524 -63
- package/dist/gateway/Gateway.js.map +1 -1
- package/dist/gateway/GatewayConfig.d.ts +295 -0
- package/dist/gateway/GatewayConfig.d.ts.map +1 -1
- package/dist/gateway/GatewayConfig.js +485 -13
- package/dist/gateway/GatewayConfig.js.map +1 -1
- package/dist/gateway/GatewayManifest.d.ts +18 -0
- package/dist/gateway/GatewayManifest.d.ts.map +1 -0
- package/dist/gateway/GatewayManifest.js +42 -0
- package/dist/gateway/GatewayManifest.js.map +1 -0
- package/dist/gateway/GatewayMetrics.d.ts +12 -4
- package/dist/gateway/GatewayMetrics.d.ts.map +1 -1
- package/dist/gateway/GatewayMetrics.js +5 -0
- package/dist/gateway/GatewayMetrics.js.map +1 -1
- package/dist/gateway/GatewayReport.d.ts +39 -2
- package/dist/gateway/GatewayReport.d.ts.map +1 -1
- package/dist/gateway/GatewayReport.js +14 -0
- package/dist/gateway/GatewayReport.js.map +1 -1
- package/dist/gateway/HoldStore.d.ts +89 -0
- package/dist/gateway/HoldStore.d.ts.map +1 -0
- package/dist/gateway/HoldStore.js +280 -0
- package/dist/gateway/HoldStore.js.map +1 -0
- package/dist/gateway/InterceptedRequest.d.ts +55 -1
- package/dist/gateway/InterceptedRequest.d.ts.map +1 -1
- package/dist/gateway/InterceptedRequest.js +63 -1
- package/dist/gateway/InterceptedRequest.js.map +1 -1
- package/dist/gateway/PolicySelector.d.ts +5 -0
- package/dist/gateway/PolicySelector.d.ts.map +1 -0
- package/dist/gateway/PolicySelector.js +9 -0
- package/dist/gateway/PolicySelector.js.map +1 -0
- package/dist/gateway/RouteTable.d.ts +72 -7
- package/dist/gateway/RouteTable.d.ts.map +1 -1
- package/dist/gateway/RouteTable.js +133 -9
- package/dist/gateway/RouteTable.js.map +1 -1
- package/dist/gateway/ShadowLedger.d.ts +11 -0
- package/dist/gateway/ShadowLedger.d.ts.map +1 -1
- package/dist/gateway/ShadowLedger.js +11 -0
- package/dist/gateway/ShadowLedger.js.map +1 -1
- package/dist/gateway/SubjectSessions.d.ts +113 -0
- package/dist/gateway/SubjectSessions.d.ts.map +1 -0
- package/dist/gateway/SubjectSessions.js +219 -0
- package/dist/gateway/SubjectSessions.js.map +1 -0
- package/dist/gateway/TargetEffect.d.ts +74 -0
- package/dist/gateway/TargetEffect.d.ts.map +1 -0
- package/dist/gateway/TargetEffect.js +95 -0
- package/dist/gateway/TargetEffect.js.map +1 -0
- package/dist/gateway/TargetReader.d.ts +70 -0
- package/dist/gateway/TargetReader.d.ts.map +1 -0
- package/dist/gateway/TargetReader.js +106 -0
- package/dist/gateway/TargetReader.js.map +1 -0
- package/dist/gateway/Upstream.d.ts +26 -0
- package/dist/gateway/Upstream.d.ts.map +1 -1
- package/dist/gateway/Upstream.js +42 -3
- package/dist/gateway/Upstream.js.map +1 -1
- package/dist/hosted/TenantHost.d.ts +26 -6
- package/dist/hosted/TenantHost.d.ts.map +1 -1
- package/dist/hosted/TenantHost.js +45 -10
- package/dist/hosted/TenantHost.js.map +1 -1
- package/dist/hosted/TenantRegistry.d.ts +28 -0
- package/dist/hosted/TenantRegistry.d.ts.map +1 -1
- package/dist/hosted/TenantRegistry.js +60 -1
- package/dist/hosted/TenantRegistry.js.map +1 -1
- package/dist/http/GatewayHttpServer.d.ts +7 -0
- package/dist/http/GatewayHttpServer.d.ts.map +1 -1
- package/dist/http/GatewayHttpServer.js +103 -3
- package/dist/http/GatewayHttpServer.js.map +1 -1
- package/dist/identity/WorkloadJwtVerifier.d.ts +13 -0
- package/dist/identity/WorkloadJwtVerifier.d.ts.map +1 -1
- package/dist/identity/WorkloadJwtVerifier.js +40 -8
- package/dist/identity/WorkloadJwtVerifier.js.map +1 -1
- package/dist/incident/HaltSwitch.d.ts +10 -2
- package/dist/incident/HaltSwitch.d.ts.map +1 -1
- package/dist/incident/HaltSwitch.js +22 -2
- package/dist/incident/HaltSwitch.js.map +1 -1
- package/dist/incident/SecurityEvents.d.ts +18 -0
- package/dist/incident/SecurityEvents.d.ts.map +1 -1
- package/dist/incident/SecurityEvents.js +17 -0
- package/dist/incident/SecurityEvents.js.map +1 -1
- package/dist/limits/HardLimits.d.ts.map +1 -1
- package/dist/limits/HardLimits.js.map +1 -1
- package/dist/outcomes/CardOutcomeEvidence.d.ts +56 -0
- package/dist/outcomes/CardOutcomeEvidence.d.ts.map +1 -0
- package/dist/outcomes/CardOutcomeEvidence.js +211 -0
- package/dist/outcomes/CardOutcomeEvidence.js.map +1 -0
- package/dist/outcomes/CardOutcomeFact.d.ts +90 -0
- package/dist/outcomes/CardOutcomeFact.d.ts.map +1 -0
- package/dist/outcomes/CardOutcomeFact.js +76 -0
- package/dist/outcomes/CardOutcomeFact.js.map +1 -0
- package/dist/outcomes/CardOutcomeLedger.d.ts +26 -0
- package/dist/outcomes/CardOutcomeLedger.d.ts.map +1 -0
- package/dist/outcomes/CardOutcomeLedger.js +31 -0
- package/dist/outcomes/CardOutcomeLedger.js.map +1 -0
- package/dist/outcomes/CardOutcomeRecorder.d.ts +35 -0
- package/dist/outcomes/CardOutcomeRecorder.d.ts.map +1 -0
- package/dist/outcomes/CardOutcomeRecorder.js +84 -0
- package/dist/outcomes/CardOutcomeRecorder.js.map +1 -0
- package/dist/outcomes/CardOutcomes.d.ts +68 -0
- package/dist/outcomes/CardOutcomes.d.ts.map +1 -0
- package/dist/outcomes/CardOutcomes.js +191 -0
- package/dist/outcomes/CardOutcomes.js.map +1 -0
- package/dist/outcomes/CoreOutcomeEvidenceClient.d.ts +54 -0
- package/dist/outcomes/CoreOutcomeEvidenceClient.d.ts.map +1 -0
- package/dist/outcomes/CoreOutcomeEvidenceClient.js +116 -0
- package/dist/outcomes/CoreOutcomeEvidenceClient.js.map +1 -0
- package/dist/outcomes/FileCardOutcomeLedger.d.ts +36 -0
- package/dist/outcomes/FileCardOutcomeLedger.d.ts.map +1 -0
- package/dist/outcomes/FileCardOutcomeLedger.js +152 -0
- package/dist/outcomes/FileCardOutcomeLedger.js.map +1 -0
- package/dist/outcomes/OutcomeEvidence.d.ts +238 -0
- package/dist/outcomes/OutcomeEvidence.d.ts.map +1 -0
- package/dist/outcomes/OutcomeEvidence.js +130 -0
- package/dist/outcomes/OutcomeEvidence.js.map +1 -0
- package/dist/outcomes/OutcomeEvidencePublisher.d.ts +81 -0
- package/dist/outcomes/OutcomeEvidencePublisher.d.ts.map +1 -0
- package/dist/outcomes/OutcomeEvidencePublisher.js +189 -0
- package/dist/outcomes/OutcomeEvidencePublisher.js.map +1 -0
- package/dist/outcomes/OutcomeEvidenceStore.d.ts +57 -0
- package/dist/outcomes/OutcomeEvidenceStore.d.ts.map +1 -0
- package/dist/outcomes/OutcomeEvidenceStore.js +191 -0
- package/dist/outcomes/OutcomeEvidenceStore.js.map +1 -0
- package/dist/posture/ActionSpaceDrift.d.ts +40 -0
- package/dist/posture/ActionSpaceDrift.d.ts.map +1 -0
- package/dist/posture/ActionSpaceDrift.js +67 -0
- package/dist/posture/ActionSpaceDrift.js.map +1 -0
- package/dist/posture/DeploymentFingerprint.d.ts +88 -0
- package/dist/posture/DeploymentFingerprint.d.ts.map +1 -0
- package/dist/posture/DeploymentFingerprint.js +78 -0
- package/dist/posture/DeploymentFingerprint.js.map +1 -0
- package/dist/secrets/SecretStore.d.ts +6 -1
- package/dist/secrets/SecretStore.d.ts.map +1 -1
- package/dist/secrets/SecretStore.js.map +1 -1
- package/dist/service/EscalationResolver.d.ts +6 -6
- package/dist/service/EscalationResolver.d.ts.map +1 -1
- package/dist/service/EscalationResolver.js +8 -4
- package/dist/service/EscalationResolver.js.map +1 -1
- package/dist/service/Requests.d.ts +6 -0
- package/dist/service/Requests.d.ts.map +1 -1
- package/dist/service/Requests.js +9 -1
- package/dist/service/Requests.js.map +1 -1
- package/dist/service/TrustedExecutorService.d.ts +21 -1
- package/dist/service/TrustedExecutorService.d.ts.map +1 -1
- package/dist/service/TrustedExecutorService.js +54 -13
- package/dist/service/TrustedExecutorService.js.map +1 -1
- package/dist/verify/VerifyingProvider.d.ts +32 -6
- package/dist/verify/VerifyingProvider.d.ts.map +1 -1
- package/dist/verify/VerifyingProvider.js +16 -2
- package/dist/verify/VerifyingProvider.js.map +1 -1
- package/package.json +7 -6
|
@@ -1,25 +1,87 @@
|
|
|
1
|
+
import { ApiProfiles } from "@decionis/agent-safe-pipeline";
|
|
2
|
+
import { isAbsolute } from "node:path";
|
|
1
3
|
import { z } from "zod";
|
|
2
4
|
import { ExecutorConfigLoader, } from "../config/ExecutorConfig.js";
|
|
5
|
+
import { parseTarget } from "../containment/ContainmentProbe.js";
|
|
3
6
|
import { EgressPolicy } from "../egress/EgressPolicy.js";
|
|
7
|
+
import { exposureDeclaration, RouteExposureSchema, } from "../exposure/ExposureDeclaration.js";
|
|
4
8
|
import { HOSTED_DEFAULT_RATE_LIMIT } from "./RateLimit.js";
|
|
9
|
+
import { PolicyIdSchema, PolicyVersionSchema } from "./PolicySelector.js";
|
|
5
10
|
/** The methods a route governs unless it names its own; a safe method is never consequential. */
|
|
6
11
|
export const CONSEQUENTIAL_METHODS = ["POST", "PUT", "PATCH", "DELETE"];
|
|
7
12
|
/** The intent contract's action name: what a route may call the action it governs. */
|
|
8
13
|
export const ACTION_NAME = /^[a-z][a-z0-9._:-]*$/;
|
|
9
14
|
/** The header a tenant presents its ingress key in; never the URL, never forwarded. */
|
|
10
15
|
export const TENANT_KEY_HEADER = "agentsafe-tenant-key";
|
|
16
|
+
/** The header a caller presents a subject session in, from the gateway's token exchange; never forwarded. */
|
|
17
|
+
export const SESSION_HEADER = "agentsafe-session";
|
|
18
|
+
/** The header a caller presents the identity provider's subject token in, per request; never forwarded. */
|
|
19
|
+
export const SUBJECT_TOKEN_HEADER = "agentsafe-subject-token";
|
|
20
|
+
/**
|
|
21
|
+
* The header the gateway presents its own token to the upstream in, so the
|
|
22
|
+
* upstream can tell a request came through it; a caller's value is never forwarded.
|
|
23
|
+
*/
|
|
24
|
+
export const GATEWAY_TOKEN_HEADER = "agentsafe-gateway-token";
|
|
25
|
+
/** The secret the gateway token is opened as, from the file its configuration names. */
|
|
26
|
+
export const GATEWAY_TOKEN_SECRET = "AGENTSAFE_GATEWAY_TOKEN";
|
|
27
|
+
/** The secret an acceptance report is signed with, opened from `acceptance.key.file`. */
|
|
28
|
+
export const ACCEPTANCE_KEY_SECRET = "AGENTSAFE_ACCEPTANCE_KEY";
|
|
29
|
+
/** The bearer of `/_agentsafe/v1/acceptance`, opened from `acceptance.operatorToken.file`. */
|
|
30
|
+
export const ACCEPTANCE_TOKEN_SECRET = "AGENTSAFE_ACCEPTANCE_TOKEN";
|
|
11
31
|
const TENANT_KEY_DIGEST = /^sha256:[0-9a-f]{64}$/;
|
|
12
32
|
/** A tenant's registry id: the DNS label it is served under. */
|
|
13
33
|
const HOSTED_TENANT = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
|
|
34
|
+
/** A header name as RFC 9110 spells a token, lower-cased. */
|
|
35
|
+
const HEADER_TOKEN = /^[a-z0-9!#$%&'*+.^_`|~-]{1,64}$/;
|
|
36
|
+
/**
|
|
37
|
+
* Headers an upstream credential may not be carried in: those that describe
|
|
38
|
+
* the hop or frame the request, which the gateway sets or drops itself, and
|
|
39
|
+
* those the authority reads (the intent binds Content-Type and
|
|
40
|
+
* Idempotency-Key), so a credential never reaches the intent.
|
|
41
|
+
*/
|
|
42
|
+
const CREDENTIAL_HEADERS_REFUSED = new Set([
|
|
43
|
+
"host",
|
|
44
|
+
"content-length",
|
|
45
|
+
"content-type",
|
|
46
|
+
"content-encoding",
|
|
47
|
+
"transfer-encoding",
|
|
48
|
+
"connection",
|
|
49
|
+
"keep-alive",
|
|
50
|
+
"upgrade",
|
|
51
|
+
"te",
|
|
52
|
+
"trailer",
|
|
53
|
+
"expect",
|
|
54
|
+
"accept-encoding",
|
|
55
|
+
"idempotency-key",
|
|
56
|
+
"proxy-authorization",
|
|
57
|
+
"proxy-authenticate",
|
|
58
|
+
"proxy-connection",
|
|
59
|
+
TENANT_KEY_HEADER,
|
|
60
|
+
]);
|
|
61
|
+
const CREDENTIAL_PREFIXES_REFUSED = ["agentsafe-", "x-agent-safe-", "x-forwarded-"];
|
|
14
62
|
/** The tenant the demo authority evaluates under; a reserved fixture identifier, never an organization. */
|
|
15
63
|
export const LOCAL_TENANT_ID = "00000000-0000-4000-8000-000000000009";
|
|
16
64
|
export const DEFAULT_AUTHORITY_ENDPOINT = "https://api.decionis.com";
|
|
17
65
|
export const DEFAULT_LISTEN = { host: "127.0.0.1", port: 8080 };
|
|
66
|
+
/** How long after a refusal its target is read again, by default, and at most. */
|
|
67
|
+
export const DEFAULT_REFUSAL_WINDOW_MS = 1_000;
|
|
68
|
+
export const MAX_REFUSAL_WINDOW_MS = 30_000;
|
|
18
69
|
const DEFAULT_TIMEOUT_MS = 4_000;
|
|
19
70
|
const DEFAULT_UPSTREAM_TIMEOUT_MS = 10_000;
|
|
20
71
|
const DEFAULT_MAX_BODY_BYTES = 1024 * 1024;
|
|
21
72
|
const DEFAULT_MAX_EMBEDDED_BODY_BYTES = 64 * 1024;
|
|
22
73
|
const DEFAULT_INTENT_TTL_SECONDS = 120;
|
|
74
|
+
/** The longest a shadow answer may wait for its observation: well under any caller's timeout. */
|
|
75
|
+
export const MAX_SHADOW_VERDICT_WAIT_MS = 2_000;
|
|
76
|
+
/** The longest intent a short-lived action may have: the authority's own limit. */
|
|
77
|
+
const MAX_INTENT_TTL_SECONDS = 300;
|
|
78
|
+
/**
|
|
79
|
+
* The longest a hold may last: the authority lets an intent live this long
|
|
80
|
+
* only when it asks the policy for its approvers (a managed escalation that
|
|
81
|
+
* names no approver), and still mints its grant only after the approval.
|
|
82
|
+
*/
|
|
83
|
+
export const MAX_HOLD_TTL_SECONDS = 7 * 24 * 60 * 60;
|
|
84
|
+
const DEFAULT_SESSION_TTL_SECONDS = 900;
|
|
23
85
|
/** The most a body may be, so the bound is a bound and not a suggestion. */
|
|
24
86
|
const MAX_BODY_BYTES = 16 * 1024 * 1024;
|
|
25
87
|
const lowerEnum = (values) => z.preprocess((value) => (typeof value === "string" ? value.trim().toLowerCase() : value), z.enum(values));
|
|
@@ -32,6 +94,9 @@ const RouteSchema = z.strictObject({
|
|
|
32
94
|
path: routePath,
|
|
33
95
|
action: actionName,
|
|
34
96
|
methods: z.array(method).min(1).max(4).optional(),
|
|
97
|
+
policyId: z.string().trim().toLowerCase().pipe(PolicyIdSchema).optional(),
|
|
98
|
+
policyVersion: z.string().trim().pipe(PolicyVersionSchema).optional(),
|
|
99
|
+
exposure: RouteExposureSchema.optional(),
|
|
35
100
|
});
|
|
36
101
|
const AuthoritySchema = z.strictObject({
|
|
37
102
|
endpoint: z.union([z.literal("local"), url]).optional(),
|
|
@@ -61,6 +126,13 @@ export const GatewayFileSchema = z.strictObject({
|
|
|
61
126
|
upstream: url.optional(),
|
|
62
127
|
upstreamInsecure: z.boolean().optional(),
|
|
63
128
|
upstreamPublicOnly: z.boolean().optional(),
|
|
129
|
+
upstreamCredential: z
|
|
130
|
+
.strictObject({
|
|
131
|
+
header: z.string().trim().min(1).max(64),
|
|
132
|
+
file: z.string().trim().min(1).max(500),
|
|
133
|
+
})
|
|
134
|
+
.optional(),
|
|
135
|
+
gatewayToken: z.strictObject({ file: z.string().trim().min(1).max(500) }).optional(),
|
|
64
136
|
hosted: z.boolean().optional(),
|
|
65
137
|
tenantKeyDigests: z.array(z.string()).optional(),
|
|
66
138
|
rateLimit: z
|
|
@@ -92,6 +164,49 @@ export const GatewayFileSchema = z.strictObject({
|
|
|
92
164
|
.max(128)
|
|
93
165
|
.regex(/^[\w!#$%&'*+.^`|~-]+$/)
|
|
94
166
|
.optional(),
|
|
167
|
+
profile: z.string().trim().min(1).max(120).optional(),
|
|
168
|
+
// facts: the authority receives the profile's operation and facts, never the request.
|
|
169
|
+
privacy: lowerEnum(["full", "facts"]).optional(),
|
|
170
|
+
// facts only: the custody file the keyed digests are derived from, the same on every replica.
|
|
171
|
+
digestKeyFile: z.string().trim().min(1).max(500).optional(),
|
|
172
|
+
// true: a read no profile operation names is refused; needs subject and a profile.
|
|
173
|
+
refuseUnknownReads: z.boolean().optional(),
|
|
174
|
+
// false: a refused write's target is not read again; on by default.
|
|
175
|
+
observeRefusals: z.boolean().optional(),
|
|
176
|
+
refusalWindowMs: z.number().int().min(0).max(MAX_REFUSAL_WINDOW_MS).optional(),
|
|
177
|
+
})
|
|
178
|
+
.optional(),
|
|
179
|
+
subject: z
|
|
180
|
+
.strictObject({
|
|
181
|
+
issuer: z.string().trim().min(1).max(500),
|
|
182
|
+
audience: z.string().trim().min(1).max(500),
|
|
183
|
+
jwksFile: z.string().trim().min(1).max(500).optional(),
|
|
184
|
+
jwksUrl: url.optional(),
|
|
185
|
+
claim: z
|
|
186
|
+
.string()
|
|
187
|
+
.trim()
|
|
188
|
+
.min(1)
|
|
189
|
+
.max(200)
|
|
190
|
+
.regex(/^[^\s"\\]+$/)
|
|
191
|
+
.optional(),
|
|
192
|
+
sessionTtlSeconds: z.number().int().min(60).max(3_600).optional(),
|
|
193
|
+
})
|
|
194
|
+
.optional(),
|
|
195
|
+
containment: z
|
|
196
|
+
.strictObject({
|
|
197
|
+
// `name=host:port`, as probe-containment takes them.
|
|
198
|
+
targets: z.array(z.string().trim().min(1).max(300)).max(64).optional(),
|
|
199
|
+
})
|
|
200
|
+
.optional(),
|
|
201
|
+
acceptance: z
|
|
202
|
+
.strictObject({
|
|
203
|
+
key: z.strictObject({ file: z.string().trim().min(1).max(500) }).optional(),
|
|
204
|
+
operatorToken: z.strictObject({ file: z.string().trim().min(1).max(500) }).optional(),
|
|
205
|
+
kid: z
|
|
206
|
+
.string()
|
|
207
|
+
.trim()
|
|
208
|
+
.regex(/^[\w.-]{1,128}$/)
|
|
209
|
+
.optional(),
|
|
95
210
|
})
|
|
96
211
|
.optional(),
|
|
97
212
|
actor: z
|
|
@@ -112,11 +227,25 @@ export const GatewayFileSchema = z.strictObject({
|
|
|
112
227
|
})
|
|
113
228
|
.optional(),
|
|
114
229
|
intentTtlSeconds: positiveInt.max(300).optional(),
|
|
230
|
+
shadow: z
|
|
231
|
+
.strictObject({
|
|
232
|
+
verdictWaitMs: z.number().int().min(0).max(MAX_SHADOW_VERDICT_WAIT_MS).optional(),
|
|
233
|
+
})
|
|
234
|
+
.optional(),
|
|
235
|
+
holds: z
|
|
236
|
+
.strictObject({
|
|
237
|
+
dir: z.string().trim().min(1).max(500),
|
|
238
|
+
keyFile: z.string().trim().min(1).max(500),
|
|
239
|
+
/** How long a captured intent, and so a hold, lives; over 300 only for a hold the policy routes. */
|
|
240
|
+
ttlSeconds: positiveInt.max(MAX_HOLD_TTL_SECONDS).optional(),
|
|
241
|
+
})
|
|
242
|
+
.optional(),
|
|
115
243
|
presence: PresenceSchema.optional(),
|
|
116
244
|
evidence: z
|
|
117
245
|
.strictObject({
|
|
118
246
|
enabled: z.boolean().optional(),
|
|
119
247
|
journalDir: z.string().trim().min(1).max(500).optional(),
|
|
248
|
+
observer: z.string().trim().min(1).max(500).optional(),
|
|
120
249
|
})
|
|
121
250
|
.optional(),
|
|
122
251
|
output: z
|
|
@@ -146,6 +275,10 @@ const ENVIRONMENT = {
|
|
|
146
275
|
upstreamProofRequired: "AGENTSAFE_UPSTREAM_PROOF_REQUIRED",
|
|
147
276
|
hosted: "AGENTSAFE_HOSTED_GATEWAY",
|
|
148
277
|
hostedTenant: "AGENTSAFE_HOSTED_TENANT",
|
|
278
|
+
hostedDedicated: "AGENTSAFE_HOSTED_DEDICATED",
|
|
279
|
+
upstreamCredentialHeader: "AGENTSAFE_UPSTREAM_CREDENTIAL_HEADER",
|
|
280
|
+
upstreamCredentialFile: "AGENTSAFE_UPSTREAM_CREDENTIAL_FILE",
|
|
281
|
+
gatewayTokenFile: "AGENTSAFE_GATEWAY_TOKEN_FILE",
|
|
149
282
|
tenantKeyDigests: "AGENTSAFE_TENANT_KEY_DIGESTS",
|
|
150
283
|
rateLimitRps: "AGENTSAFE_RATE_LIMIT_RPS",
|
|
151
284
|
rateLimitBurst: "AGENTSAFE_RATE_LIMIT_BURST",
|
|
@@ -165,10 +298,16 @@ const ENVIRONMENT = {
|
|
|
165
298
|
logLevel: "AGENTSAFE_LOG_LEVEL",
|
|
166
299
|
logFormat: "AGENTSAFE_LOG_FORMAT",
|
|
167
300
|
evidenceDir: "AGENTSAFE_EVIDENCE_DIR",
|
|
301
|
+
shadowVerdictWaitMs: "AGENTSAFE_SHADOW_VERDICT_WAIT_MS",
|
|
168
302
|
actorId: "AGENTSAFE_ACTOR_ID",
|
|
169
303
|
actorType: "AGENTSAFE_ACTOR_TYPE",
|
|
170
304
|
boundaryId: "AGENTSAFE_BOUNDARY_ID",
|
|
171
305
|
principalHeader: "AGENTSAFE_PRINCIPAL_HEADER",
|
|
306
|
+
profile: "AGENTSAFE_PROFILE",
|
|
307
|
+
privacy: "AGENTSAFE_PRIVACY",
|
|
308
|
+
containmentTargets: "AGENTSAFE_CONTAINMENT_TARGETS",
|
|
309
|
+
acceptanceKeyFile: "AGENTSAFE_ACCEPTANCE_KEY_FILE",
|
|
310
|
+
acceptanceTokenFile: "AGENTSAFE_ACCEPTANCE_TOKEN_FILE",
|
|
172
311
|
presenceApproverId: "PRESENCE_APPROVER_ID",
|
|
173
312
|
presenceApproverRole: "PRESENCE_APPROVER_ROLE",
|
|
174
313
|
presenceLevel: "PRESENCE_VERIFICATION_LEVEL",
|
|
@@ -181,6 +320,7 @@ const COMMAND_ENVIRONMENT = [
|
|
|
181
320
|
"AGENTSAFE_HOME",
|
|
182
321
|
"AGENTSAFE_METRICS_TOKEN",
|
|
183
322
|
"AGENTSAFE_TENANT_REGISTRY",
|
|
323
|
+
"AGENTSAFE_HOST_TENANT",
|
|
184
324
|
"AGENTSAFE_TLS_CERT_FILE",
|
|
185
325
|
"AGENTSAFE_TLS_KEY_FILE",
|
|
186
326
|
"AGENTSAFE_REDIRECT_LISTEN",
|
|
@@ -274,6 +414,16 @@ function parseUnmatched(value, setting) {
|
|
|
274
414
|
return "PASSTHROUGH";
|
|
275
415
|
throw new GatewayConfigError("CONFIG_INVALID", setting, "govern or passthrough");
|
|
276
416
|
}
|
|
417
|
+
function parsePrivacy(value, setting) {
|
|
418
|
+
if (value === undefined)
|
|
419
|
+
return undefined;
|
|
420
|
+
const lower = value.trim().toLowerCase();
|
|
421
|
+
if (lower === "full")
|
|
422
|
+
return "FULL";
|
|
423
|
+
if (lower === "facts")
|
|
424
|
+
return "FACTS";
|
|
425
|
+
throw new GatewayConfigError("CONFIG_INVALID", setting, "full or facts");
|
|
426
|
+
}
|
|
277
427
|
function parseMethods(value, setting) {
|
|
278
428
|
if (value === undefined)
|
|
279
429
|
return undefined;
|
|
@@ -419,11 +569,6 @@ export class GatewayConfigLoader {
|
|
|
419
569
|
// authority accepts in shadow only; starting it in enforcement would fail
|
|
420
570
|
// every action closed, so the refusal is at start, by name.
|
|
421
571
|
const provisional = kind === "DECIONIS" && keyFromCredentials && credentials.provisional === true;
|
|
422
|
-
// Hosted enforcement would hold every tenant's provider credentials; it is
|
|
423
|
-
// not offered, so a hosted gateway that says enforce is refused at start.
|
|
424
|
-
if (hosted && mode === "ENFORCEMENT") {
|
|
425
|
-
throw new GatewayConfigError("CONFIG_INVALID", "authority.mode", "a hosted gateway runs in shadow only");
|
|
426
|
-
}
|
|
427
572
|
if (provisional && mode === "ENFORCEMENT") {
|
|
428
573
|
throw new GatewayConfigError("CONFIG_INVALID", "authority.mode", "the stored login is a provisional workspace, which evaluates in shadow only; run agentsafe login with a key from your Decionis organization to enforce");
|
|
429
574
|
}
|
|
@@ -482,6 +627,9 @@ export class GatewayConfigLoader {
|
|
|
482
627
|
path: route.path,
|
|
483
628
|
action: route.action,
|
|
484
629
|
methods: route.methods ?? [...CONSEQUENTIAL_METHODS],
|
|
630
|
+
...(route.policyId === undefined ? {} : { policyId: route.policyId }),
|
|
631
|
+
...(route.policyVersion === undefined ? {} : { policyVersion: route.policyVersion }),
|
|
632
|
+
...(route.exposure === undefined ? {} : { exposure: exposureDeclaration(route.exposure) }),
|
|
485
633
|
}));
|
|
486
634
|
sources["interception.routes"] = file?.interception?.routes === undefined ? "default" : "file";
|
|
487
635
|
const unmatched = resolve("interception.unmatched", [
|
|
@@ -503,10 +651,62 @@ export class GatewayConfigLoader {
|
|
|
503
651
|
{ source: "environment", raw: env[ENVIRONMENT.principalHeader]?.trim() },
|
|
504
652
|
{ source: "file", raw: file?.interception?.principalHeader },
|
|
505
653
|
], null);
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
654
|
+
const profile = resolve("interception.profile", [
|
|
655
|
+
{ source: "environment", raw: env[ENVIRONMENT.profile]?.trim() || undefined },
|
|
656
|
+
{ source: "file", raw: file?.interception?.profile },
|
|
657
|
+
], null);
|
|
658
|
+
if (profile !== null && ApiProfiles.get(profile) === null) {
|
|
659
|
+
throw new GatewayConfigError("CONFIG_INVALID", "interception.profile", `one of ${ApiProfiles.ids().join(", ")}`);
|
|
660
|
+
}
|
|
661
|
+
const privacy = resolve("interception.privacy", [
|
|
662
|
+
{ source: "environment", raw: parsePrivacy(env[ENVIRONMENT.privacy], ENVIRONMENT.privacy) },
|
|
663
|
+
{
|
|
664
|
+
source: "file",
|
|
665
|
+
raw: parsePrivacy(file?.interception?.privacy, "interception.privacy"),
|
|
666
|
+
},
|
|
667
|
+
], "FULL");
|
|
668
|
+
if (privacy === "FACTS") {
|
|
669
|
+
GatewayConfigLoader.factsOnly(profile, routes, principalHeader, sources["interception.unmatched"] === "default" ? null : unmatched);
|
|
670
|
+
}
|
|
671
|
+
const digestKeyFile = file?.interception?.digestKeyFile ?? null;
|
|
672
|
+
if (digestKeyFile !== null) {
|
|
673
|
+
if (privacy !== "FACTS") {
|
|
674
|
+
throw new GatewayConfigError("CONFIG_INVALID", "interception.digestKeyFile", "only with privacy: facts, whose digests it keys");
|
|
675
|
+
}
|
|
676
|
+
if (!isAbsolute(digestKeyFile)) {
|
|
677
|
+
throw new GatewayConfigError("CONFIG_INVALID", "interception.digestKeyFile", "an absolute path");
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
const subject = GatewayConfigLoader.subject(file, allowInsecureLoopback, sources);
|
|
681
|
+
const containment = GatewayConfigLoader.containmentTargets(resolve("containment.targets", [
|
|
682
|
+
{
|
|
683
|
+
source: "environment",
|
|
684
|
+
raw: env[ENVIRONMENT.containmentTargets]
|
|
685
|
+
?.split(",")
|
|
686
|
+
.map((value) => value.trim())
|
|
687
|
+
.filter((value) => value !== ""),
|
|
688
|
+
},
|
|
689
|
+
{ source: "file", raw: file?.containment?.targets },
|
|
690
|
+
], null) ?? []);
|
|
691
|
+
const acceptance = GatewayConfigLoader.acceptance(env, file, resolve);
|
|
692
|
+
// Scoping is only as good as what it covers, so pinning subjects with a
|
|
693
|
+
// profile refuses what the profile cannot check unless the file says not.
|
|
694
|
+
const refuseUnknownReads = resolve("interception.refuseUnknownReads", [{ source: "file", raw: file?.interception?.refuseUnknownReads }], subject !== null && profile !== null);
|
|
695
|
+
if (refuseUnknownReads && (subject === null || profile === null)) {
|
|
696
|
+
throw new GatewayConfigError("CONFIG_INVALID", "interception.refuseUnknownReads", "needs subject and interception.profile: reads are checked against a session");
|
|
697
|
+
}
|
|
698
|
+
// The tenant key and the subject session headers are the gateway's own
|
|
699
|
+
// credentials: they are stripped before forwarding, and the value of a
|
|
700
|
+
// principal header is sent to the authority, so none of them can be the
|
|
701
|
+
// header that names a principal.
|
|
702
|
+
const ownCredential = [
|
|
703
|
+
TENANT_KEY_HEADER,
|
|
704
|
+
SESSION_HEADER,
|
|
705
|
+
SUBJECT_TOKEN_HEADER,
|
|
706
|
+
GATEWAY_TOKEN_HEADER,
|
|
707
|
+
].find((header) => header === principalHeader?.toLowerCase());
|
|
708
|
+
if (ownCredential !== undefined) {
|
|
709
|
+
throw new GatewayConfigError("CONFIG_INVALID", "interception.principalHeader", `${ownCredential} is the gateway's own credential`);
|
|
510
710
|
}
|
|
511
711
|
const tenantKeys = GatewayConfigLoader.tenantKeys(resolve("tenantKeyDigests", [
|
|
512
712
|
{
|
|
@@ -523,6 +723,15 @@ export class GatewayConfigLoader {
|
|
|
523
723
|
throw new GatewayConfigError("CONFIG_INVALID", ENVIRONMENT.hostedTenant, "a lower-case DNS label, on a hosted gateway");
|
|
524
724
|
}
|
|
525
725
|
GatewayConfigLoader.requireTenantKey(tenantKeys, hosted);
|
|
726
|
+
const hostedDedicated = resolve("hostedDedicated", [
|
|
727
|
+
{
|
|
728
|
+
source: "environment",
|
|
729
|
+
raw: parseBoolean(env[ENVIRONMENT.hostedDedicated], ENVIRONMENT.hostedDedicated),
|
|
730
|
+
},
|
|
731
|
+
], false);
|
|
732
|
+
if (hostedDedicated && !hosted) {
|
|
733
|
+
throw new GatewayConfigError("CONFIG_INVALID", ENVIRONMENT.hostedDedicated, "on a hosted gateway");
|
|
734
|
+
}
|
|
526
735
|
// The proof binds the hosted tenant and the organization its key belongs
|
|
527
736
|
// to, so it means nothing on a gateway that has neither.
|
|
528
737
|
const proofRequired = resolve("upstream.proofRequired", [
|
|
@@ -534,14 +743,44 @@ export class GatewayConfigLoader {
|
|
|
534
743
|
if (proofRequired && (!hosted || hostedTenant === null || kind !== "DECIONIS")) {
|
|
535
744
|
throw new GatewayConfigError("CONFIG_INVALID", ENVIRONMENT.upstreamProofRequired, `a hosted gateway with ${ENVIRONMENT.hostedTenant} and a Decionis organization in ${ENVIRONMENT.tenantId}`);
|
|
536
745
|
}
|
|
746
|
+
const credential = GatewayConfigLoader.upstreamCredential(env, file, principalHeader, resolve);
|
|
747
|
+
const gatewayToken = GatewayConfigLoader.gatewayToken(env, file, resolve);
|
|
748
|
+
// A gateway that holds the upstream's credential is the agent's only way
|
|
749
|
+
// in, so with subjects pinned, a call it cannot check is never let through.
|
|
750
|
+
if (credential !== null && subject !== null && !refuseUnknownReads) {
|
|
751
|
+
throw new GatewayConfigError("CONFIG_INVALID", "interception.refuseUnknownReads", "a gateway that holds the upstream credential and pins subjects refuses what it cannot check");
|
|
752
|
+
}
|
|
753
|
+
// Hosted enforcement is the tenant's opt-in, and runs only where every
|
|
754
|
+
// control its design asks for is on (design.agentsafe-hosted-shadow.md
|
|
755
|
+
// §14): a process of its own, a Decionis organization, failing closed, a
|
|
756
|
+
// proven upstream, a credential the gateway holds in place of the agent,
|
|
757
|
+
// and evidence written before anything executes.
|
|
758
|
+
if (hosted && mode === "ENFORCEMENT") {
|
|
759
|
+
GatewayConfigLoader.requireHostedEnforcement({
|
|
760
|
+
dedicated: hostedDedicated,
|
|
761
|
+
tenant: hostedTenant,
|
|
762
|
+
kind,
|
|
763
|
+
failurePolicy,
|
|
764
|
+
proofRequired,
|
|
765
|
+
credential,
|
|
766
|
+
evidence: file?.evidence?.enabled ?? true,
|
|
767
|
+
});
|
|
768
|
+
}
|
|
537
769
|
const rateLimit = resolve("rateLimit", [
|
|
538
770
|
{ source: "environment", raw: GatewayConfigLoader.rateLimitFromEnvironment(env) },
|
|
539
771
|
{ source: "file", raw: file?.gateway?.rateLimit },
|
|
540
772
|
], null) ?? (hosted ? HOSTED_DEFAULT_RATE_LIMIT : null);
|
|
541
773
|
const escalation = GatewayConfigLoader.escalation(file, env, mode, kind, resolve);
|
|
774
|
+
const holds = GatewayConfigLoader.holds(file, mode, escalation);
|
|
542
775
|
const required = [];
|
|
543
776
|
if (kind === "DECIONIS")
|
|
544
777
|
required.push("DECIONIS_API_KEY");
|
|
778
|
+
if (credential !== null)
|
|
779
|
+
required.push("DOWNSTREAM_CREDENTIAL");
|
|
780
|
+
if (gatewayToken !== null)
|
|
781
|
+
required.push(GATEWAY_TOKEN_SECRET);
|
|
782
|
+
if (acceptance !== null)
|
|
783
|
+
required.push(ACCEPTANCE_KEY_SECRET, ACCEPTANCE_TOKEN_SECRET);
|
|
545
784
|
if (escalation.mode === "DIRECT")
|
|
546
785
|
required.push("PRESENCE_API_KEY");
|
|
547
786
|
const verbose = resolve("output.verbose", [
|
|
@@ -577,6 +816,7 @@ export class GatewayConfigLoader {
|
|
|
577
816
|
listen,
|
|
578
817
|
hosted,
|
|
579
818
|
hostedTenant,
|
|
819
|
+
hostedDedicated,
|
|
580
820
|
tenantKeys,
|
|
581
821
|
rateLimit,
|
|
582
822
|
upstream: {
|
|
@@ -584,6 +824,8 @@ export class GatewayConfigLoader {
|
|
|
584
824
|
insecure: upstreamInsecure,
|
|
585
825
|
publicOnly: upstreamPublicOnly,
|
|
586
826
|
proofRequired,
|
|
827
|
+
credential,
|
|
828
|
+
gatewayToken,
|
|
587
829
|
system: resolve("upstream.system", [
|
|
588
830
|
{ source: "environment", raw: env[ENVIRONMENT.system]?.trim() },
|
|
589
831
|
{ source: "file", raw: file?.gateway?.system },
|
|
@@ -624,7 +866,16 @@ export class GatewayConfigLoader {
|
|
|
624
866
|
maxBodyBytes,
|
|
625
867
|
maxEmbeddedBodyBytes,
|
|
626
868
|
principalHeader: principalHeader === null ? null : principalHeader.toLowerCase(),
|
|
869
|
+
profile,
|
|
870
|
+
privacy,
|
|
871
|
+
digestKeyFile,
|
|
872
|
+
refuseUnknownReads,
|
|
873
|
+
observeRefusals: resolve("interception.observeRefusals", [{ source: "file", raw: file?.interception?.observeRefusals }], true),
|
|
874
|
+
refusalWindowMs: resolve("interception.refusalWindowMs", [{ source: "file", raw: file?.interception?.refusalWindowMs }], DEFAULT_REFUSAL_WINDOW_MS),
|
|
627
875
|
},
|
|
876
|
+
subject,
|
|
877
|
+
containment: { targets: containment },
|
|
878
|
+
acceptance,
|
|
628
879
|
actor: {
|
|
629
880
|
id: resolve("actor.id", [
|
|
630
881
|
{ source: "environment", raw: env[ENVIRONMENT.actorId]?.trim() },
|
|
@@ -636,7 +887,15 @@ export class GatewayConfigLoader {
|
|
|
636
887
|
], "GATEWAY"),
|
|
637
888
|
runtime: `agentsafe/${input.version}`,
|
|
638
889
|
},
|
|
639
|
-
intentTtlSeconds: resolve("intentTtlSeconds", [{ source: "file", raw: file?.intentTtlSeconds }], DEFAULT_INTENT_TTL_SECONDS),
|
|
890
|
+
intentTtlSeconds: resolve("intentTtlSeconds", [{ source: "file", raw: file?.holds?.ttlSeconds ?? file?.intentTtlSeconds }], DEFAULT_INTENT_TTL_SECONDS),
|
|
891
|
+
holds,
|
|
892
|
+
shadowVerdictWaitMs: resolve("shadow.verdictWaitMs", [
|
|
893
|
+
{
|
|
894
|
+
source: "environment",
|
|
895
|
+
raw: GatewayConfigLoader.verdictWait(env[ENVIRONMENT.shadowVerdictWaitMs]),
|
|
896
|
+
},
|
|
897
|
+
{ source: "file", raw: file?.shadow?.verdictWaitMs },
|
|
898
|
+
], 0),
|
|
640
899
|
escalation,
|
|
641
900
|
evidence: {
|
|
642
901
|
enabled: resolve("evidence.enabled", [{ source: "file", raw: file?.evidence?.enabled }], true),
|
|
@@ -644,6 +903,7 @@ export class GatewayConfigLoader {
|
|
|
644
903
|
{ source: "environment", raw: env[ENVIRONMENT.evidenceDir]?.trim() },
|
|
645
904
|
{ source: "file", raw: file?.evidence?.journalDir },
|
|
646
905
|
], null),
|
|
906
|
+
observer: resolve("evidence.observer", [{ source: "file", raw: file?.evidence?.observer }], null),
|
|
647
907
|
},
|
|
648
908
|
output: { format, verbose },
|
|
649
909
|
production,
|
|
@@ -651,6 +911,66 @@ export class GatewayConfigLoader {
|
|
|
651
911
|
sources,
|
|
652
912
|
};
|
|
653
913
|
}
|
|
914
|
+
/** Each declared containment target as `name=host:port`, refused by setting when it is not one. */
|
|
915
|
+
static containmentTargets(values) {
|
|
916
|
+
if (values.length > 64) {
|
|
917
|
+
throw new GatewayConfigError("CONFIG_INVALID", "containment.targets", "at most 64 targets");
|
|
918
|
+
}
|
|
919
|
+
return values.map((value) => {
|
|
920
|
+
try {
|
|
921
|
+
return parseTarget(value);
|
|
922
|
+
}
|
|
923
|
+
catch {
|
|
924
|
+
throw new GatewayConfigError("CONFIG_INVALID", "containment.targets", "name=host:port");
|
|
925
|
+
}
|
|
926
|
+
});
|
|
927
|
+
}
|
|
928
|
+
/**
|
|
929
|
+
* The subject section, when there is one: an issuer, an audience and a key
|
|
930
|
+
* set, on disk or at an address the guarded egress fetches. The address is
|
|
931
|
+
* https, or loopback with the authority's loopback allowance.
|
|
932
|
+
*/
|
|
933
|
+
static subject(file, allowInsecureLoopback, sources) {
|
|
934
|
+
const section = file?.subject;
|
|
935
|
+
sources["subject"] = section === undefined ? "default" : "file";
|
|
936
|
+
if (section === undefined)
|
|
937
|
+
return null;
|
|
938
|
+
if (section.jwksFile === undefined && section.jwksUrl === undefined) {
|
|
939
|
+
throw new GatewayConfigError("CONFIG_MISSING", "subject.jwksFile", "subject.jwksFile or subject.jwksUrl: the identity provider's keys");
|
|
940
|
+
}
|
|
941
|
+
return {
|
|
942
|
+
issuer: section.issuer,
|
|
943
|
+
audience: section.audience,
|
|
944
|
+
jwksFile: section.jwksFile ?? null,
|
|
945
|
+
jwksUrl: section.jwksUrl === undefined
|
|
946
|
+
? null
|
|
947
|
+
: GatewayConfigLoader.authorityUrl(section.jwksUrl, "subject.jwksUrl", allowInsecureLoopback),
|
|
948
|
+
claim: section.claim ?? "sub",
|
|
949
|
+
sessionTtlSeconds: section.sessionTtlSeconds ?? DEFAULT_SESSION_TTL_SECONDS,
|
|
950
|
+
};
|
|
951
|
+
}
|
|
952
|
+
/**
|
|
953
|
+
* Facts-only mode sends the authority a profile's operation and facts, so
|
|
954
|
+
* it governs by a profile alone. Every setting that would put a raw part of
|
|
955
|
+
* the request in front of the authority, or govern a call no operation
|
|
956
|
+
* names, is refused by name rather than quietly overridden: a route (its
|
|
957
|
+
* target is the raw path), a principal header (a raw header value), and an
|
|
958
|
+
* explicit passthrough of unmatched calls (facts-only refuses them).
|
|
959
|
+
*/
|
|
960
|
+
static factsOnly(profile, routes, principalHeader, unmatched) {
|
|
961
|
+
if (profile === null) {
|
|
962
|
+
throw new GatewayConfigError("CONFIG_MISSING", "interception.profile", "facts-only privacy governs by an API profile's operations");
|
|
963
|
+
}
|
|
964
|
+
if (routes.length > 0) {
|
|
965
|
+
throw new GatewayConfigError("CONFIG_INVALID", "interception.routes", "facts-only privacy governs by the profile alone; a route sends the raw path");
|
|
966
|
+
}
|
|
967
|
+
if (principalHeader !== null) {
|
|
968
|
+
throw new GatewayConfigError("CONFIG_INVALID", "interception.principalHeader", "facts-only privacy sends no header value; name the agent in actor.id");
|
|
969
|
+
}
|
|
970
|
+
if (unmatched === "PASSTHROUGH") {
|
|
971
|
+
throw new GatewayConfigError("CONFIG_INVALID", "interception.unmatched", "facts-only privacy refuses a call no profile operation names");
|
|
972
|
+
}
|
|
973
|
+
}
|
|
654
974
|
/** The file's shape, refused by the name of the first key that is wrong. */
|
|
655
975
|
static file(raw) {
|
|
656
976
|
if (raw === null || raw === undefined)
|
|
@@ -695,6 +1015,116 @@ export class GatewayConfigLoader {
|
|
|
695
1015
|
GatewayConfigLoader.requireTenantKey(keys, hosted);
|
|
696
1016
|
return keys;
|
|
697
1017
|
}
|
|
1018
|
+
/**
|
|
1019
|
+
* The upstream credential the gateway presents, from the environment or
|
|
1020
|
+
* the file: a header and the file holding its value, both or neither. The
|
|
1021
|
+
* header is one a credential can travel in without the gateway setting or
|
|
1022
|
+
* dropping it, and never one whose value reaches the authority.
|
|
1023
|
+
*/
|
|
1024
|
+
static upstreamCredential(env, file, principalHeader, resolve) {
|
|
1025
|
+
const header = resolve("upstream.credential.header", [
|
|
1026
|
+
{
|
|
1027
|
+
source: "environment",
|
|
1028
|
+
raw: env[ENVIRONMENT.upstreamCredentialHeader]?.trim() || undefined,
|
|
1029
|
+
},
|
|
1030
|
+
{ source: "file", raw: file?.gateway?.upstreamCredential?.header },
|
|
1031
|
+
], null);
|
|
1032
|
+
const path = resolve("upstream.credential.file", [
|
|
1033
|
+
{
|
|
1034
|
+
source: "environment",
|
|
1035
|
+
raw: env[ENVIRONMENT.upstreamCredentialFile]?.trim() || undefined,
|
|
1036
|
+
},
|
|
1037
|
+
{ source: "file", raw: file?.gateway?.upstreamCredential?.file },
|
|
1038
|
+
], null);
|
|
1039
|
+
if (header === null && path === null)
|
|
1040
|
+
return null;
|
|
1041
|
+
if (header === null || path === null) {
|
|
1042
|
+
throw new GatewayConfigError("CONFIG_MISSING", header === null ? ENVIRONMENT.upstreamCredentialHeader : ENVIRONMENT.upstreamCredentialFile, "an upstream credential needs its header and the file holding its value");
|
|
1043
|
+
}
|
|
1044
|
+
const name = header.toLowerCase();
|
|
1045
|
+
if (!HEADER_TOKEN.test(name) ||
|
|
1046
|
+
CREDENTIAL_HEADERS_REFUSED.has(name) ||
|
|
1047
|
+
CREDENTIAL_PREFIXES_REFUSED.some((prefix) => name.startsWith(prefix)) ||
|
|
1048
|
+
name === principalHeader?.toLowerCase()) {
|
|
1049
|
+
throw new GatewayConfigError("CONFIG_INVALID", "upstream.credential.header", "a header the gateway neither sets nor sends to the authority, such as authorization or x-api-key");
|
|
1050
|
+
}
|
|
1051
|
+
if (!isAbsolute(path)) {
|
|
1052
|
+
throw new GatewayConfigError("CONFIG_INVALID", "upstream.credential.file", "an absolute path");
|
|
1053
|
+
}
|
|
1054
|
+
return { header: name, file: path };
|
|
1055
|
+
}
|
|
1056
|
+
/**
|
|
1057
|
+
* An acceptance run's key and operator token, from the environment or the
|
|
1058
|
+
* file: both or neither, each an absolute path. One without the other is
|
|
1059
|
+
* refused, because a key with no way to ask for a run signs nothing, and a
|
|
1060
|
+
* token with nothing to sign opens runs that cannot close.
|
|
1061
|
+
*/
|
|
1062
|
+
static acceptance(env, file, resolve) {
|
|
1063
|
+
const path = (name, environment, fromFile) => resolve(name, [
|
|
1064
|
+
{ source: "environment", raw: env[environment]?.trim() || undefined },
|
|
1065
|
+
{ source: "file", raw: fromFile },
|
|
1066
|
+
], null);
|
|
1067
|
+
const key = path("acceptance.key.file", ENVIRONMENT.acceptanceKeyFile, file?.acceptance?.key?.file);
|
|
1068
|
+
const token = path("acceptance.operatorToken.file", ENVIRONMENT.acceptanceTokenFile, file?.acceptance?.operatorToken?.file);
|
|
1069
|
+
if (key === null && token === null)
|
|
1070
|
+
return null;
|
|
1071
|
+
for (const [name, value] of [
|
|
1072
|
+
["acceptance.key.file", key],
|
|
1073
|
+
["acceptance.operatorToken.file", token],
|
|
1074
|
+
]) {
|
|
1075
|
+
if (value === null) {
|
|
1076
|
+
throw new GatewayConfigError("CONFIG_INVALID", name, "both acceptance.key and acceptance.operatorToken, or neither");
|
|
1077
|
+
}
|
|
1078
|
+
if (!isAbsolute(value))
|
|
1079
|
+
throw new GatewayConfigError("CONFIG_INVALID", name, "an absolute path");
|
|
1080
|
+
}
|
|
1081
|
+
return {
|
|
1082
|
+
key: { file: key },
|
|
1083
|
+
operatorToken: { file: token },
|
|
1084
|
+
kid: resolve("acceptance.kid", [{ source: "file", raw: file?.acceptance?.kid }], null),
|
|
1085
|
+
};
|
|
1086
|
+
}
|
|
1087
|
+
/**
|
|
1088
|
+
* The file holding the gateway's own token, from the environment or the
|
|
1089
|
+
* file: an absolute path, or none. The header it travels in is fixed, so
|
|
1090
|
+
* nothing about it can collide with what the authority reads.
|
|
1091
|
+
*/
|
|
1092
|
+
static gatewayToken(env, file, resolve) {
|
|
1093
|
+
const path = resolve("upstream.gatewayToken.file", [
|
|
1094
|
+
{ source: "environment", raw: env[ENVIRONMENT.gatewayTokenFile]?.trim() || undefined },
|
|
1095
|
+
{ source: "file", raw: file?.gateway?.gatewayToken?.file },
|
|
1096
|
+
], null);
|
|
1097
|
+
if (path === null)
|
|
1098
|
+
return null;
|
|
1099
|
+
if (!isAbsolute(path)) {
|
|
1100
|
+
throw new GatewayConfigError("CONFIG_INVALID", "upstream.gatewayToken.file", "an absolute path");
|
|
1101
|
+
}
|
|
1102
|
+
return { file: path };
|
|
1103
|
+
}
|
|
1104
|
+
/** Every control hosted enforcement needs, refused by the first one missing, by name. */
|
|
1105
|
+
static requireHostedEnforcement(facts) {
|
|
1106
|
+
if (!facts.dedicated) {
|
|
1107
|
+
throw new GatewayConfigError("CONFIG_INVALID", ENVIRONMENT.hostedDedicated, "a hosted gateway enforces only in a process of its own: agentsafe host --tenant");
|
|
1108
|
+
}
|
|
1109
|
+
if (facts.tenant === null) {
|
|
1110
|
+
throw new GatewayConfigError("CONFIG_MISSING", ENVIRONMENT.hostedTenant, "the tenant a hosted gateway enforces for");
|
|
1111
|
+
}
|
|
1112
|
+
if (facts.kind !== "DECIONIS") {
|
|
1113
|
+
throw new GatewayConfigError("CONFIG_INVALID", "authority", "a hosted gateway enforces against a Decionis organization");
|
|
1114
|
+
}
|
|
1115
|
+
if (facts.failurePolicy !== "FAIL_CLOSED") {
|
|
1116
|
+
throw new GatewayConfigError("CONFIG_INVALID", "authority.failurePolicy", "a hosted gateway enforces fail-closed");
|
|
1117
|
+
}
|
|
1118
|
+
if (!facts.proofRequired) {
|
|
1119
|
+
throw new GatewayConfigError("CONFIG_MISSING", ENVIRONMENT.upstreamProofRequired, "a hosted gateway enforces only for an upstream that proves it is the tenant's");
|
|
1120
|
+
}
|
|
1121
|
+
if (facts.credential === null) {
|
|
1122
|
+
throw new GatewayConfigError("CONFIG_MISSING", "upstream.credential", "a hosted gateway that enforces holds the upstream credential, so the agent cannot go around it");
|
|
1123
|
+
}
|
|
1124
|
+
if (!facts.evidence) {
|
|
1125
|
+
throw new GatewayConfigError("CONFIG_INVALID", "evidence.enabled", "a hosted gateway that enforces writes evidence before execution");
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
698
1128
|
/** Hosted, the tenant is the only caller the gateway admits, from day one. */
|
|
699
1129
|
static requireTenantKey(keys, hosted) {
|
|
700
1130
|
if (hosted && keys.length === 0) {
|
|
@@ -751,6 +1181,36 @@ export class GatewayConfigLoader {
|
|
|
751
1181
|
end -= 1;
|
|
752
1182
|
return checked.slice(0, end);
|
|
753
1183
|
}
|
|
1184
|
+
/**
|
|
1185
|
+
* Where held requests live. A shared directory is for enforcement only
|
|
1186
|
+
* (shadow never holds), named by absolute paths, and the only place a hold
|
|
1187
|
+
* may outlive the authority's short intent window: that longer window is
|
|
1188
|
+
* for a managed escalation whose approvers the policy names, which is the
|
|
1189
|
+
* one the authority lets live up to seven days.
|
|
1190
|
+
*/
|
|
1191
|
+
static holds(file, mode, escalation) {
|
|
1192
|
+
const section = file?.holds;
|
|
1193
|
+
if (section === undefined)
|
|
1194
|
+
return null;
|
|
1195
|
+
if (mode === "SHADOW") {
|
|
1196
|
+
throw new GatewayConfigError("CONFIG_INVALID", "holds", "shadow never holds a request");
|
|
1197
|
+
}
|
|
1198
|
+
for (const [setting, path] of [
|
|
1199
|
+
["holds.dir", section.dir],
|
|
1200
|
+
["holds.keyFile", section.keyFile],
|
|
1201
|
+
]) {
|
|
1202
|
+
if (!isAbsolute(path))
|
|
1203
|
+
throw new GatewayConfigError("CONFIG_INVALID", setting, "an absolute path");
|
|
1204
|
+
}
|
|
1205
|
+
if (section.ttlSeconds !== undefined && file?.intentTtlSeconds !== undefined) {
|
|
1206
|
+
throw new GatewayConfigError("CONFIG_INVALID", "holds.ttlSeconds", "set it here or as intentTtlSeconds, not both");
|
|
1207
|
+
}
|
|
1208
|
+
const policyRouted = escalation.mode === "MANAGED" && escalation.approverId === null;
|
|
1209
|
+
if ((section.ttlSeconds ?? 0) > MAX_INTENT_TTL_SECONDS && !policyRouted) {
|
|
1210
|
+
throw new GatewayConfigError("CONFIG_INVALID", "holds.ttlSeconds", `over ${MAX_INTENT_TTL_SECONDS} only with presence.managed and no presence.approverId`);
|
|
1211
|
+
}
|
|
1212
|
+
return { dir: section.dir, keyFile: section.keyFile };
|
|
1213
|
+
}
|
|
754
1214
|
/**
|
|
755
1215
|
* How an `ESCALATE` is resolved, in the executor's own shape. Managed is
|
|
756
1216
|
* the gateway's default when Presence is configured at all: Decionis
|
|
@@ -781,9 +1241,6 @@ export class GatewayConfigLoader {
|
|
|
781
1241
|
if (kind === "LOCAL") {
|
|
782
1242
|
throw new GatewayConfigError("CONFIG_INVALID", "presence.managed", "the demo authority holds; it orchestrates nothing");
|
|
783
1243
|
}
|
|
784
|
-
if (approverId === null) {
|
|
785
|
-
throw new GatewayConfigError("CONFIG_MISSING", "presence.approverId", "who approves a managed escalation");
|
|
786
|
-
}
|
|
787
1244
|
const level = resolve("presence.level", [
|
|
788
1245
|
{
|
|
789
1246
|
source: "environment",
|
|
@@ -813,6 +1270,15 @@ export class GatewayConfigLoader {
|
|
|
813
1270
|
requirements: { methods, level },
|
|
814
1271
|
};
|
|
815
1272
|
}
|
|
1273
|
+
static verdictWait(value) {
|
|
1274
|
+
if (value === undefined || value.trim() === "")
|
|
1275
|
+
return undefined;
|
|
1276
|
+
const wait = Number(value.trim());
|
|
1277
|
+
if (!Number.isInteger(wait) || wait < 0 || wait > MAX_SHADOW_VERDICT_WAIT_MS) {
|
|
1278
|
+
throw new GatewayConfigError("CONFIG_INVALID", ENVIRONMENT.shadowVerdictWaitMs, `whole milliseconds, 0 to ${MAX_SHADOW_VERDICT_WAIT_MS}`);
|
|
1279
|
+
}
|
|
1280
|
+
return wait;
|
|
1281
|
+
}
|
|
816
1282
|
static level(value, setting) {
|
|
817
1283
|
if (value === undefined)
|
|
818
1284
|
return undefined;
|
|
@@ -839,6 +1305,12 @@ export function renderConfigFile(options) {
|
|
|
839
1305
|
` - path: ${route.path}`,
|
|
840
1306
|
` action: ${route.action}`,
|
|
841
1307
|
` methods: [${route.methods.join(", ")}]`,
|
|
1308
|
+
...(route.policyId === undefined
|
|
1309
|
+
? []
|
|
1310
|
+
: [` policyId: ${JSON.stringify(route.policyId)}`]),
|
|
1311
|
+
...(route.policyVersion === undefined
|
|
1312
|
+
? []
|
|
1313
|
+
: [` policyVersion: ${JSON.stringify(route.policyVersion)}`]),
|
|
842
1314
|
]),
|
|
843
1315
|
];
|
|
844
1316
|
return [
|