@decionis/agentsafe 0.2.5 → 0.3.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 +135 -20
- package/dist/Cli.js +19 -0
- package/dist/Cli.js.map +1 -1
- package/dist/Index.d.ts +10 -4
- package/dist/Index.d.ts.map +1 -1
- package/dist/Index.js +8 -2
- package/dist/Index.js.map +1 -1
- package/dist/TrustedExecutor.d.ts.map +1 -1
- package/dist/TrustedExecutor.js +1 -0
- package/dist/TrustedExecutor.js.map +1 -1
- package/dist/adapters/AdapterActionHandler.d.ts.map +1 -1
- package/dist/adapters/AdapterActionHandler.js +8 -4
- package/dist/adapters/AdapterActionHandler.js.map +1 -1
- package/dist/adapters/EffectAdapter.d.ts +6 -1
- package/dist/adapters/EffectAdapter.d.ts.map +1 -1
- package/dist/adapters/EffectAdapter.js +7 -1
- package/dist/adapters/EffectAdapter.js.map +1 -1
- package/dist/adapters/banking/CoreBankingHttpAdapter.d.ts.map +1 -1
- package/dist/adapters/banking/CoreBankingHttpAdapter.js +4 -4
- package/dist/adapters/banking/CoreBankingHttpAdapter.js.map +1 -1
- package/dist/adapters/cards/CardAuthorizationMatcher.d.ts +44 -0
- package/dist/adapters/cards/CardAuthorizationMatcher.d.ts.map +1 -0
- package/dist/adapters/cards/CardAuthorizationMatcher.js +39 -0
- package/dist/adapters/cards/CardAuthorizationMatcher.js.map +1 -0
- package/dist/adapters/cards/CardEffect.d.ts +52 -0
- package/dist/adapters/cards/CardEffect.d.ts.map +1 -0
- package/dist/adapters/cards/CardEffect.js +117 -0
- package/dist/adapters/cards/CardEffect.js.map +1 -0
- package/dist/adapters/cards/CardHandlers.d.ts +15 -0
- package/dist/adapters/cards/CardHandlers.d.ts.map +1 -0
- package/dist/adapters/cards/CardHandlers.js +26 -0
- package/dist/adapters/cards/CardHandlers.js.map +1 -0
- package/dist/adapters/cards/CardPurchase.d.ts +61 -0
- package/dist/adapters/cards/CardPurchase.d.ts.map +1 -0
- package/dist/adapters/cards/CardPurchase.js +116 -0
- package/dist/adapters/cards/CardPurchase.js.map +1 -0
- package/dist/adapters/cards/HeldCardGrants.d.ts +70 -0
- package/dist/adapters/cards/HeldCardGrants.d.ts.map +1 -0
- package/dist/adapters/cards/HeldCardGrants.js +79 -0
- package/dist/adapters/cards/HeldCardGrants.js.map +1 -0
- package/dist/adapters/cards/Pan.d.ts +17 -0
- package/dist/adapters/cards/Pan.d.ts.map +1 -0
- package/dist/adapters/cards/Pan.js +52 -0
- package/dist/adapters/cards/Pan.js.map +1 -0
- package/dist/adapters/mcp/McpGuard.d.ts.map +1 -1
- package/dist/adapters/mcp/McpGuard.js +9 -4
- package/dist/adapters/mcp/McpGuard.js.map +1 -1
- package/dist/audit/HashChain.d.ts +8 -2
- package/dist/audit/HashChain.d.ts.map +1 -1
- package/dist/audit/HashChain.js +14 -2
- package/dist/audit/HashChain.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/Edge.d.ts +4 -0
- package/dist/cli/Edge.d.ts.map +1 -0
- package/dist/cli/Edge.js +250 -0
- package/dist/cli/Edge.js.map +1 -0
- package/dist/cli/Help.d.ts.map +1 -1
- package/dist/cli/Help.js +8 -0
- package/dist/cli/Help.js.map +1 -1
- package/dist/cli/Host.d.ts +36 -0
- package/dist/cli/Host.d.ts.map +1 -0
- package/dist/cli/Host.js +247 -0
- package/dist/cli/Host.js.map +1 -0
- package/dist/cli/TcpBrokerCli.d.ts +4 -0
- package/dist/cli/TcpBrokerCli.d.ts.map +1 -0
- package/dist/cli/TcpBrokerCli.js +93 -0
- package/dist/cli/TcpBrokerCli.js.map +1 -0
- package/dist/cli/TcpClientCli.d.ts +16 -0
- package/dist/cli/TcpClientCli.d.ts.map +1 -0
- package/dist/cli/TcpClientCli.js +175 -0
- package/dist/cli/TcpClientCli.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 +19 -0
- package/dist/config/ConfigKeys.js.map +1 -1
- package/dist/config/ExecutorConfig.d.ts +62 -0
- package/dist/config/ExecutorConfig.d.ts.map +1 -1
- package/dist/config/ExecutorConfig.js +124 -0
- package/dist/config/ExecutorConfig.js.map +1 -1
- package/dist/edge/EdgeLicence.d.ts +25 -0
- package/dist/edge/EdgeLicence.d.ts.map +1 -0
- package/dist/edge/EdgeLicence.js +42 -0
- package/dist/edge/EdgeLicence.js.map +1 -0
- package/dist/edge/EdgeReplay.d.ts +45 -0
- package/dist/edge/EdgeReplay.d.ts.map +1 -0
- package/dist/edge/EdgeReplay.js +69 -0
- package/dist/edge/EdgeReplay.js.map +1 -0
- package/dist/edge/Entitlement.d.ts +57 -0
- package/dist/edge/Entitlement.d.ts.map +1 -0
- package/dist/edge/Entitlement.js +139 -0
- package/dist/edge/Entitlement.js.map +1 -0
- package/dist/edge/EntitlementEvaluation.d.ts +66 -0
- package/dist/edge/EntitlementEvaluation.d.ts.map +1 -0
- package/dist/edge/EntitlementEvaluation.js +74 -0
- package/dist/edge/EntitlementEvaluation.js.map +1 -0
- package/dist/edge/UsageCount.d.ts +40 -0
- package/dist/edge/UsageCount.d.ts.map +1 -0
- package/dist/edge/UsageCount.js +140 -0
- package/dist/edge/UsageCount.js.map +1 -0
- package/dist/edge/UsageKeyRegistration.d.ts +34 -0
- package/dist/edge/UsageKeyRegistration.d.ts.map +1 -0
- package/dist/edge/UsageKeyRegistration.js +74 -0
- package/dist/edge/UsageKeyRegistration.js.map +1 -0
- package/dist/edge/UsageMeter.d.ts +89 -0
- package/dist/edge/UsageMeter.d.ts.map +1 -0
- package/dist/edge/UsageMeter.js +275 -0
- package/dist/edge/UsageMeter.js.map +1 -0
- package/dist/edge/UsagePeriod.d.ts +23 -0
- package/dist/edge/UsagePeriod.d.ts.map +1 -0
- package/dist/edge/UsagePeriod.js +31 -0
- package/dist/edge/UsagePeriod.js.map +1 -0
- package/dist/edge/UsageReport.d.ts +92 -0
- package/dist/edge/UsageReport.d.ts.map +1 -0
- package/dist/edge/UsageReport.js +153 -0
- package/dist/edge/UsageReport.js.map +1 -0
- package/dist/edge/UsageTally.d.ts +63 -0
- package/dist/edge/UsageTally.d.ts.map +1 -0
- package/dist/edge/UsageTally.js +89 -0
- package/dist/edge/UsageTally.js.map +1 -0
- package/dist/egress/EgressError.d.ts +7 -1
- package/dist/egress/EgressError.d.ts.map +1 -1
- package/dist/egress/EgressError.js.map +1 -1
- package/dist/egress/EgressPolicy.d.ts +16 -3
- package/dist/egress/EgressPolicy.d.ts.map +1 -1
- package/dist/egress/EgressPolicy.js +33 -3
- package/dist/egress/EgressPolicy.js.map +1 -1
- package/dist/egress/GuardedFetch.d.ts +38 -1
- package/dist/egress/GuardedFetch.d.ts.map +1 -1
- package/dist/egress/GuardedFetch.js +52 -7
- package/dist/egress/GuardedFetch.js.map +1 -1
- package/dist/egress/TcpClient.d.ts +103 -0
- package/dist/egress/TcpClient.d.ts.map +1 -0
- package/dist/egress/TcpClient.js +490 -0
- package/dist/egress/TcpClient.js.map +1 -0
- package/dist/egress/TcpControlClient.d.ts +49 -0
- package/dist/egress/TcpControlClient.d.ts.map +1 -0
- package/dist/egress/TcpControlClient.js +186 -0
- package/dist/egress/TcpControlClient.js.map +1 -0
- package/dist/gateway/ForwardHandler.d.ts.map +1 -1
- package/dist/gateway/ForwardHandler.js +7 -4
- package/dist/gateway/ForwardHandler.js.map +1 -1
- package/dist/gateway/Gateway.d.ts +190 -10
- package/dist/gateway/Gateway.d.ts.map +1 -1
- package/dist/gateway/Gateway.js +465 -62
- package/dist/gateway/Gateway.js.map +1 -1
- package/dist/gateway/GatewayConfig.d.ts +67 -0
- package/dist/gateway/GatewayConfig.d.ts.map +1 -1
- package/dist/gateway/GatewayConfig.js +149 -2
- package/dist/gateway/GatewayConfig.js.map +1 -1
- package/dist/gateway/InterceptedRequest.d.ts +9 -2
- package/dist/gateway/InterceptedRequest.d.ts.map +1 -1
- package/dist/gateway/InterceptedRequest.js +41 -9
- package/dist/gateway/InterceptedRequest.js.map +1 -1
- package/dist/gateway/RateLimit.d.ts +29 -0
- package/dist/gateway/RateLimit.d.ts.map +1 -0
- package/dist/gateway/RateLimit.js +33 -0
- package/dist/gateway/RateLimit.js.map +1 -0
- package/dist/gateway/RefusalSampler.d.ts +28 -0
- package/dist/gateway/RefusalSampler.d.ts.map +1 -0
- package/dist/gateway/RefusalSampler.js +52 -0
- package/dist/gateway/RefusalSampler.js.map +1 -0
- package/dist/gateway/RouteTable.d.ts +3 -0
- package/dist/gateway/RouteTable.d.ts.map +1 -1
- package/dist/gateway/RouteTable.js +44 -7
- package/dist/gateway/RouteTable.js.map +1 -1
- package/dist/gateway/Upstream.d.ts +26 -0
- package/dist/gateway/Upstream.d.ts.map +1 -1
- package/dist/gateway/Upstream.js +41 -2
- package/dist/gateway/Upstream.js.map +1 -1
- package/dist/gateway/UpstreamProof.d.ts +235 -0
- package/dist/gateway/UpstreamProof.d.ts.map +1 -0
- package/dist/gateway/UpstreamProof.js +375 -0
- package/dist/gateway/UpstreamProof.js.map +1 -0
- package/dist/handlers/ForwardRequestHandler.d.ts +5 -1
- package/dist/handlers/ForwardRequestHandler.d.ts.map +1 -1
- package/dist/handlers/ForwardRequestHandler.js +12 -2
- package/dist/handlers/ForwardRequestHandler.js.map +1 -1
- package/dist/hosted/TenantHost.d.ts +180 -0
- package/dist/hosted/TenantHost.d.ts.map +1 -0
- package/dist/hosted/TenantHost.js +432 -0
- package/dist/hosted/TenantHost.js.map +1 -0
- package/dist/hosted/TenantRegistry.d.ts +73 -0
- package/dist/hosted/TenantRegistry.d.ts.map +1 -0
- package/dist/hosted/TenantRegistry.js +123 -0
- package/dist/hosted/TenantRegistry.js.map +1 -0
- package/dist/http/ExecutorHttpServer.d.ts +7 -0
- package/dist/http/ExecutorHttpServer.d.ts.map +1 -1
- package/dist/http/ExecutorHttpServer.js +30 -5
- package/dist/http/ExecutorHttpServer.js.map +1 -1
- package/dist/http/GatewayHttpServer.d.ts +55 -3
- package/dist/http/GatewayHttpServer.d.ts.map +1 -1
- package/dist/http/GatewayHttpServer.js +157 -17
- package/dist/http/GatewayHttpServer.js.map +1 -1
- package/dist/http/RedirectServer.d.ts +26 -0
- package/dist/http/RedirectServer.d.ts.map +1 -0
- package/dist/http/RedirectServer.js +62 -0
- package/dist/http/RedirectServer.js.map +1 -0
- package/dist/http/Routes.d.ts +17 -0
- package/dist/http/Routes.d.ts.map +1 -1
- package/dist/http/Routes.js +21 -0
- package/dist/http/Routes.js.map +1 -1
- package/dist/http/TcpBroker.d.ts +57 -0
- package/dist/http/TcpBroker.d.ts.map +1 -0
- package/dist/http/TcpBroker.js +299 -0
- package/dist/http/TcpBroker.js.map +1 -0
- package/dist/http/TcpHostRelay.d.ts +24 -0
- package/dist/http/TcpHostRelay.d.ts.map +1 -0
- package/dist/http/TcpHostRelay.js +194 -0
- package/dist/http/TcpHostRelay.js.map +1 -0
- package/dist/http/TcpRelayStreams.d.ts +24 -0
- package/dist/http/TcpRelayStreams.d.ts.map +1 -0
- package/dist/http/TcpRelayStreams.js +128 -0
- package/dist/http/TcpRelayStreams.js.map +1 -0
- package/dist/http/TlsListener.d.ts +3 -1
- package/dist/http/TlsListener.d.ts.map +1 -1
- package/dist/http/TlsListener.js +7 -2
- package/dist/http/TlsListener.js.map +1 -1
- package/dist/identity/PrincipalsFile.d.ts +3 -1
- package/dist/identity/PrincipalsFile.d.ts.map +1 -1
- package/dist/identity/PrincipalsFile.js +1 -0
- package/dist/identity/PrincipalsFile.js.map +1 -1
- package/dist/incident/Metrics.d.ts +2 -0
- package/dist/incident/Metrics.d.ts.map +1 -1
- package/dist/incident/Metrics.js +10 -0
- package/dist/incident/Metrics.js.map +1 -1
- package/dist/incident/SecurityEvents.d.ts +89 -0
- package/dist/incident/SecurityEvents.d.ts.map +1 -1
- package/dist/incident/SecurityEvents.js +93 -2
- package/dist/incident/SecurityEvents.js.map +1 -1
- package/dist/journal/ExecutionJournal.d.ts +27 -0
- package/dist/journal/ExecutionJournal.d.ts.map +1 -1
- package/dist/journal/ExecutionJournal.js +28 -0
- package/dist/journal/ExecutionJournal.js.map +1 -1
- package/dist/journal/FileExecutionJournal.d.ts +2 -1
- package/dist/journal/FileExecutionJournal.d.ts.map +1 -1
- package/dist/journal/FileExecutionJournal.js +4 -1
- package/dist/journal/FileExecutionJournal.js.map +1 -1
- package/dist/journal/InMemoryExecutionJournal.d.ts +2 -1
- package/dist/journal/InMemoryExecutionJournal.d.ts.map +1 -1
- package/dist/journal/InMemoryExecutionJournal.js +4 -1
- package/dist/journal/InMemoryExecutionJournal.js.map +1 -1
- package/dist/service/AuthorityClients.d.ts +8 -1
- package/dist/service/AuthorityClients.d.ts.map +1 -1
- package/dist/service/AuthorityClients.js +33 -5
- package/dist/service/AuthorityClients.js.map +1 -1
- package/dist/service/EdgeRuntime.d.ts +73 -0
- package/dist/service/EdgeRuntime.d.ts.map +1 -0
- package/dist/service/EdgeRuntime.js +209 -0
- package/dist/service/EdgeRuntime.js.map +1 -0
- package/dist/service/EscalationResolver.d.ts +82 -2
- package/dist/service/EscalationResolver.d.ts.map +1 -1
- package/dist/service/EscalationResolver.js +39 -3
- package/dist/service/EscalationResolver.js.map +1 -1
- package/dist/service/Requests.d.ts +28 -2
- package/dist/service/Requests.d.ts.map +1 -1
- package/dist/service/TrustedExecutorService.d.ts +71 -1
- package/dist/service/TrustedExecutorService.d.ts.map +1 -1
- package/dist/service/TrustedExecutorService.js +461 -27
- package/dist/service/TrustedExecutorService.js.map +1 -1
- package/dist/tcp/TcpWire.d.ts +18 -0
- package/dist/tcp/TcpWire.d.ts.map +1 -0
- package/dist/tcp/TcpWire.js +114 -0
- package/dist/tcp/TcpWire.js.map +1 -0
- package/dist/verify/VerifyAuditChain.d.ts +5 -0
- package/dist/verify/VerifyAuditChain.d.ts.map +1 -1
- package/dist/verify/VerifyAuditChain.js +20 -4
- package/dist/verify/VerifyAuditChain.js.map +1 -1
- package/package.json +7 -3
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { request } from "node:https";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { TCP_TICKET, TCP_UUID } from "../http/TcpRelayStreams.js";
|
|
4
|
+
const grantSchema = z.strictObject({
|
|
5
|
+
lease_id: z.string().regex(TCP_UUID),
|
|
6
|
+
lease_token: z.string().regex(TCP_TICKET),
|
|
7
|
+
org_id: z.string().regex(TCP_UUID),
|
|
8
|
+
route_id: z.string().regex(TCP_UUID),
|
|
9
|
+
generation: z.number().int().positive(),
|
|
10
|
+
tenant_host: z.string().max(253),
|
|
11
|
+
role: z.enum(["connector", "client"]),
|
|
12
|
+
resource_hash: z.string().regex(/^[a-f0-9]{64}$/),
|
|
13
|
+
expires_at: z.string().datetime(),
|
|
14
|
+
});
|
|
15
|
+
class TcpControlError extends Error {
|
|
16
|
+
status;
|
|
17
|
+
constructor(status) {
|
|
18
|
+
super("TCP_CONTROL_REFUSED");
|
|
19
|
+
this.status = status;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export function validGrant(value, binding, previous) {
|
|
23
|
+
const grant = grantSchema.parse(value);
|
|
24
|
+
for (const key of ["route_id", "tenant_host", "role"]) {
|
|
25
|
+
if (grant[key] !== binding[key])
|
|
26
|
+
throw new Error("TCP_GRANT_BINDING_INVALID");
|
|
27
|
+
}
|
|
28
|
+
if (previous) {
|
|
29
|
+
for (const key of [
|
|
30
|
+
"lease_id",
|
|
31
|
+
"lease_token",
|
|
32
|
+
"org_id",
|
|
33
|
+
"generation",
|
|
34
|
+
"resource_hash",
|
|
35
|
+
]) {
|
|
36
|
+
if (grant[key] !== previous[key])
|
|
37
|
+
throw new Error("TCP_GRANT_BINDING_INVALID");
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const remaining = Date.parse(grant.expires_at) - Date.now();
|
|
41
|
+
if (remaining <= 250 || remaining > 35_000)
|
|
42
|
+
throw new Error("TCP_GRANT_EXPIRY_INVALID");
|
|
43
|
+
return grant;
|
|
44
|
+
}
|
|
45
|
+
/** The only broker egress: fixed HTTPS control paths, with no redirects or peer destinations. */
|
|
46
|
+
export class TcpControlClient {
|
|
47
|
+
token;
|
|
48
|
+
ca;
|
|
49
|
+
origin;
|
|
50
|
+
healthChecked = 0;
|
|
51
|
+
healthVerified = 0;
|
|
52
|
+
healthToken = null;
|
|
53
|
+
healthPending = null;
|
|
54
|
+
pending = 0;
|
|
55
|
+
constructor(origin, token, ca) {
|
|
56
|
+
this.token = token;
|
|
57
|
+
this.ca = ca;
|
|
58
|
+
this.origin = new URL(origin);
|
|
59
|
+
if (this.origin.protocol !== "https:" ||
|
|
60
|
+
this.origin.username ||
|
|
61
|
+
this.origin.password ||
|
|
62
|
+
this.origin.pathname !== "/" ||
|
|
63
|
+
this.origin.search ||
|
|
64
|
+
this.origin.hash)
|
|
65
|
+
throw new Error("TCP_CONTROL_API_INVALID");
|
|
66
|
+
}
|
|
67
|
+
async ready() {
|
|
68
|
+
let token;
|
|
69
|
+
try {
|
|
70
|
+
token = this.serviceToken();
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
if (token === this.healthToken && Date.now() - this.healthChecked < 10_000)
|
|
76
|
+
return Date.now() - this.healthVerified < 30_000;
|
|
77
|
+
if (this.healthPending) {
|
|
78
|
+
await this.healthPending;
|
|
79
|
+
return await this.ready();
|
|
80
|
+
}
|
|
81
|
+
this.healthPending = (async () => {
|
|
82
|
+
try {
|
|
83
|
+
const value = await this.post("health", {});
|
|
84
|
+
if (typeof value !== "object" ||
|
|
85
|
+
value === null ||
|
|
86
|
+
!("transport" in value) ||
|
|
87
|
+
value.transport !== "agentsafe-tcp-relay/1" ||
|
|
88
|
+
!("ready" in value) ||
|
|
89
|
+
value.ready !== true)
|
|
90
|
+
throw new Error("TCP_CONTROL_UNAVAILABLE");
|
|
91
|
+
this.healthVerified = Date.now();
|
|
92
|
+
this.healthToken = token;
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
if (error instanceof TcpControlError && (error.status === 401 || error.status === 403))
|
|
96
|
+
this.healthVerified = 0;
|
|
97
|
+
// Only a still-valid prior successful proof can survive a transient outage.
|
|
98
|
+
}
|
|
99
|
+
finally {
|
|
100
|
+
this.healthChecked = Date.now();
|
|
101
|
+
this.healthPending = null;
|
|
102
|
+
}
|
|
103
|
+
return (this.serviceToken() === this.healthToken &&
|
|
104
|
+
token === this.healthToken &&
|
|
105
|
+
Date.now() - this.healthVerified < 30_000);
|
|
106
|
+
})();
|
|
107
|
+
return await this.healthPending;
|
|
108
|
+
}
|
|
109
|
+
async redeem(ticket, binding) {
|
|
110
|
+
return validGrant(await this.post("redeem", { ticket, ...binding }), binding);
|
|
111
|
+
}
|
|
112
|
+
async refresh(grant, phase) {
|
|
113
|
+
return validGrant(await this.post("leases/refresh", {
|
|
114
|
+
lease_id: grant.lease_id,
|
|
115
|
+
lease_token: grant.lease_token,
|
|
116
|
+
phase,
|
|
117
|
+
}), grant, grant);
|
|
118
|
+
}
|
|
119
|
+
async close(grant) {
|
|
120
|
+
await this.post("leases/close", { lease_id: grant.lease_id, lease_token: grant.lease_token });
|
|
121
|
+
}
|
|
122
|
+
serviceToken() {
|
|
123
|
+
const token = this.token().trim();
|
|
124
|
+
if (token.length < 48 ||
|
|
125
|
+
token.length > 512 ||
|
|
126
|
+
[...token].some((char) => char.charCodeAt(0) < 33 || char.charCodeAt(0) > 126))
|
|
127
|
+
throw new Error("TCP_BROKER_TOKEN_INVALID");
|
|
128
|
+
return token;
|
|
129
|
+
}
|
|
130
|
+
async post(path, body) {
|
|
131
|
+
const token = this.serviceToken();
|
|
132
|
+
if (this.pending >= 128)
|
|
133
|
+
throw new Error("TCP_CONTROL_CAPACITY_REACHED");
|
|
134
|
+
this.pending++;
|
|
135
|
+
try {
|
|
136
|
+
return await new Promise((resolve, reject) => {
|
|
137
|
+
const data = JSON.stringify(body);
|
|
138
|
+
const req = request(new URL(`/v1/internal/gateway/tcp/${path}`, this.origin), {
|
|
139
|
+
method: "POST",
|
|
140
|
+
rejectUnauthorized: true,
|
|
141
|
+
minVersion: "TLSv1.2",
|
|
142
|
+
...(this.ca ? { ca: this.ca } : {}),
|
|
143
|
+
headers: {
|
|
144
|
+
authorization: `Bearer ${token}`,
|
|
145
|
+
"content-type": "application/json",
|
|
146
|
+
"content-length": Buffer.byteLength(data),
|
|
147
|
+
},
|
|
148
|
+
agent: false,
|
|
149
|
+
}, (response) => {
|
|
150
|
+
let size = 0;
|
|
151
|
+
const chunks = [];
|
|
152
|
+
response.on("data", (chunk) => {
|
|
153
|
+
size += chunk.length;
|
|
154
|
+
if (size > 16_384)
|
|
155
|
+
req.destroy(new Error("TCP_CONTROL_RESPONSE_TOO_LARGE"));
|
|
156
|
+
else
|
|
157
|
+
chunks.push(chunk);
|
|
158
|
+
});
|
|
159
|
+
response.on("error", () => reject(new Error("TCP_CONTROL_UNAVAILABLE")));
|
|
160
|
+
response.on("end", () => {
|
|
161
|
+
clearTimeout(timer);
|
|
162
|
+
if (response.statusCode !== 200)
|
|
163
|
+
return reject(new TcpControlError(response.statusCode ?? 0));
|
|
164
|
+
try {
|
|
165
|
+
resolve(JSON.parse(Buffer.concat(chunks).toString("utf8")));
|
|
166
|
+
}
|
|
167
|
+
catch {
|
|
168
|
+
reject(new Error("TCP_CONTROL_RESPONSE_INVALID"));
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
const timer = setTimeout(() => req.destroy(new Error("TCP_CONTROL_TIMEOUT")), 5_000);
|
|
173
|
+
timer.unref();
|
|
174
|
+
req.once("error", () => {
|
|
175
|
+
clearTimeout(timer);
|
|
176
|
+
reject(new Error("TCP_CONTROL_UNAVAILABLE"));
|
|
177
|
+
});
|
|
178
|
+
req.end(data);
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
finally {
|
|
182
|
+
this.pending--;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
//# sourceMappingURL=TcpControlClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TcpControlClient.js","sourceRoot":"","sources":["../../src/egress/TcpControlClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAQlE,MAAM,WAAW,GAAG,CAAC,CAAC,YAAY,CAAC;IACjC,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC;IACpC,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC;IACzC,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC;IAClC,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC;IACpC,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE;IACvC,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC;IAChC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;IACrC,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,gBAAgB,CAAC;IACjD,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAClC,CAAC,CAAC;AAQH,MAAM,eAAgB,SAAQ,KAAK;IACE;IAAnC,YAAmC,MAAc;QAC/C,KAAK,CAAC,qBAAqB,CAAC,CAAC;QADI,WAAM,GAAN,MAA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AC;4BACP,MAAM,CAAC,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC,CAAC;wBACpD,CAAC;oBACH,CAAC,CAAC,CAAC;gBACL,CAAC,CACF,CAAC;gBACF,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;gBACrF,KAAK,CAAC,KAAK,EAAE,CAAC;gBACd,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE;oBACrB,YAAY,CAAC,KAAK,CAAC,CAAC;oBACpB,MAAM,CAAC,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC,CAAC;gBAC/C,CAAC,CAAC,CAAC;gBACH,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YAChB,CAAC,CAAC,CAAC;QACL,CAAC;gBAAS,CAAC;YACT,IAAI,CAAC,OAAO,EAAE,CAAC;QACjB,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ForwardHandler.d.ts","sourceRoot":"","sources":["../../src/gateway/ForwardHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,
|
|
1
|
+
{"version":3,"file":"ForwardHandler.d.ts","sourceRoot":"","sources":["../../src/gateway/ForwardHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAIL,KAAK,aAAa,EAClB,KAAK,cAAc,EACpB,MAAM,+BAA+B,CAAC;AAIvC,OAAO,EAGL,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACxB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE9D,yGAAyG;AACzG,eAAO,MAAM,0BAA0B;;;;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-pipeline";
|
|
2
|
+
import { JsonValueSchema, PreDispatchRefusal, ProviderRefusal, } from "@decionis/agent-safe-pipeline";
|
|
3
3
|
import { EFFECT_RECEIPT_HEADER } from "../verify/EffectReceipt.js";
|
|
4
4
|
import { dispatchBudgetMs, MonotonicDeadline } from "../time/MonotonicClock.js";
|
|
5
5
|
import { CONSEQUENTIAL_METHODS } from "./GatewayConfig.js";
|
|
6
|
-
import { bodyDigest, } from "./InterceptedRequest.js";
|
|
6
|
+
import { bodyDigest, requestDigest, } from "./InterceptedRequest.js";
|
|
7
7
|
/** The parameters an HTTP action carries; anything else the registry refuses before a grant is spent. */
|
|
8
8
|
export const HttpActionParametersSchema = z.strictObject({
|
|
9
9
|
method: z.enum(CONSEQUENTIAL_METHODS),
|
|
@@ -61,9 +61,10 @@ export function httpForwardHandler(upstream, holder) {
|
|
|
61
61
|
const context = intent.intent.context;
|
|
62
62
|
if (request.method.toUpperCase() !== parameters.method ||
|
|
63
63
|
request.path !== parameters.path ||
|
|
64
|
+
context["request_sha256"] !== requestDigest(request) ||
|
|
64
65
|
context["body_bytes"] !== request.body.length ||
|
|
65
66
|
context["body_sha256"] !== bodyDigest(request.body)) {
|
|
66
|
-
throw new
|
|
67
|
+
throw new PreDispatchRefusal("PAYLOAD_BINDING_MISMATCH");
|
|
67
68
|
}
|
|
68
69
|
const headers = upstream.headersFor(request, {
|
|
69
70
|
...held.extraHeaders,
|
|
@@ -96,7 +97,9 @@ export function httpForwardHandler(upstream, holder) {
|
|
|
96
97
|
const receipt = response.headers.find(([name]) => name === EFFECT_RECEIPT_HEADER);
|
|
97
98
|
if (receipt !== undefined)
|
|
98
99
|
dispatch.receipt(receipt[1]);
|
|
99
|
-
|
|
100
|
+
// A 408 is a timeout, not a refusal: the upstream may have acted, so it
|
|
101
|
+
// is as unknown as a 5xx (docs/execution-outcomes.md).
|
|
102
|
+
if (response.status >= 500 || response.status === 408) {
|
|
100
103
|
held.outcome = { response, failure: "UPSTREAM_ERROR" };
|
|
101
104
|
throw new UpstreamIndeterminate();
|
|
102
105
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ForwardHandler.js","sourceRoot":"","sources":["../../src/gateway/ForwardHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,eAAe,EACf,eAAe,GAGhB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAChF,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EACL,UAAU,
|
|
1
|
+
{"version":3,"file":"ForwardHandler.js","sourceRoot":"","sources":["../../src/gateway/ForwardHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,eAAe,GAGhB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAChF,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EACL,UAAU,EACV,aAAa,GAGd,MAAM,yBAAyB,CAAC;AAGjC,yGAAyG;AACzG,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,CAAC,YAAY,CAAC;IACvD,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,qBAAqB,CAAC;IACrC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC;IAChC,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,K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mB,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;gBAClE,CAAC;gBACD,IAAI,CAAC,OAAO,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;gBAC3C,OAAO,QAAQ,CAAC;YAClB,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC;AAED,0FAA0F;AAC1F,MAAM,UAAU,mBAAmB,CACjC,QAAwB,EACxB,OAA0B,EAC1B,OAA4D;IAE5D,KAAK,MAAM,MAAM,IAAI,OAAO;QAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjE,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;AACzB,CAAC"}
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import { type WorkloadSignal } from "@decionis/agent-safe-pipeline";
|
|
2
2
|
import { type EnforcementBoundary } from "../boundary/BoundaryIdentity.js";
|
|
3
3
|
import { type ProvenanceProvider } from "../provenance/ProvenanceProvider.js";
|
|
4
|
+
import { HashChain } from "../audit/HashChain.js";
|
|
5
|
+
import { type AddressResolver } from "../egress/GuardedFetch.js";
|
|
4
6
|
import type { FetchLike } from "../handlers/HandlerRegistration.js";
|
|
5
7
|
import type { SecretStore } from "../secrets/SecretStore.js";
|
|
6
|
-
import { type ActivationMilestone } from "./Activation.js";
|
|
8
|
+
import { ActivationFunnel, type ActivationMilestone } from "./Activation.js";
|
|
7
9
|
import { type DemoAuthorityHandle } from "./DemoAuthority.js";
|
|
8
|
-
import type
|
|
10
|
+
import { type GatewayConfig } from "./GatewayConfig.js";
|
|
9
11
|
import { type InstallSurface } from "./InstallSurface.js";
|
|
10
12
|
import { type InterceptedRequest } from "./InterceptedRequest.js";
|
|
13
|
+
import { type RateDecision } from "./RateLimit.js";
|
|
11
14
|
import { type RoutePlan } from "./RouteTable.js";
|
|
12
15
|
import { type ShadowSummary } from "./ShadowLedger.js";
|
|
16
|
+
import { type ProofAdmission, type ProofSnapshot, type TxtResolver } from "./UpstreamProof.js";
|
|
13
17
|
/**
|
|
14
18
|
* When a shadow gateway prints its report unasked: as the count of settled
|
|
15
19
|
* observations reaches each of these, and whenever a day has passed since
|
|
@@ -39,8 +43,12 @@ export interface GatewayDependencies {
|
|
|
39
43
|
readonly io?: GatewayIo;
|
|
40
44
|
/** The transport under the guard for the authority and Presence; `node:https` when absent. */
|
|
41
45
|
readonly authorityFetch?: FetchLike;
|
|
42
|
-
/** The transport to the upstream; the global fetch when absent. */
|
|
46
|
+
/** The transport to the upstream; the global fetch when absent, or the guarded egress when public-only. */
|
|
43
47
|
readonly upstreamFetch?: FetchLike;
|
|
48
|
+
/** Name resolution for a public-only upstream and its proof; the system resolver when absent. */
|
|
49
|
+
readonly upstreamResolve?: AddressResolver;
|
|
50
|
+
/** TXT lookup for the upstream's proof; the system resolver's when absent. */
|
|
51
|
+
readonly upstreamResolveTxt?: TxtResolver;
|
|
44
52
|
readonly secrets?: SecretStore;
|
|
45
53
|
readonly demoAuthority?: () => Promise<DemoAuthorityHandle>;
|
|
46
54
|
readonly clock?: () => number;
|
|
@@ -59,6 +67,32 @@ export interface GatewayDependencies {
|
|
|
59
67
|
* record tells a test run from a gateway in service.
|
|
60
68
|
*/
|
|
61
69
|
readonly clientExample?: string;
|
|
70
|
+
/**
|
|
71
|
+
* What the gateway this one replaces hands on: its chains are continued,
|
|
72
|
+
* neither restored from the journal nor started again from genesis, and
|
|
73
|
+
* its funnel's milestones are not reported twice. The upstream's proof is
|
|
74
|
+
* not part of it: that is taken over at the swap (`takeOver`), as it
|
|
75
|
+
* stands then.
|
|
76
|
+
*/
|
|
77
|
+
readonly continues?: GatewayContinuation;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* A gateway's chains and adoption funnel, handed to the gateway built to
|
|
81
|
+
* replace it. Linking is synchronous, so the replaced gateway, finishing
|
|
82
|
+
* what it has in flight, and its replacement write one sequence per stream.
|
|
83
|
+
*/
|
|
84
|
+
export interface GatewayContinuation {
|
|
85
|
+
readonly evidence: HashChain;
|
|
86
|
+
readonly gateway: HashChain;
|
|
87
|
+
readonly security: HashChain;
|
|
88
|
+
readonly activation: ActivationFunnel;
|
|
89
|
+
}
|
|
90
|
+
/** Where a hosted gateway's configuration came from, when a host built it from a tenant registry. */
|
|
91
|
+
export interface RegistrySource {
|
|
92
|
+
/** The registry the host last loaded, as a short digest of its text. */
|
|
93
|
+
readonly revision: string;
|
|
94
|
+
/** The tenant's entry this gateway was built from, as a short digest of its fingerprint. */
|
|
95
|
+
readonly entry: string;
|
|
62
96
|
}
|
|
63
97
|
/** What `/_agentsafe/status` reports: identifiers and counts, never a value. */
|
|
64
98
|
export interface GatewayStatus {
|
|
@@ -81,7 +115,31 @@ export interface GatewayStatus {
|
|
|
81
115
|
readonly surface: InstallSurface | null;
|
|
82
116
|
/** In shadow, what the authority would have decided so far, by verdict and action; null in enforcement. */
|
|
83
117
|
readonly shadow: ShadowSummary | null;
|
|
118
|
+
/**
|
|
119
|
+
* A hosted gateway's tenant, the tenant keys it admits now, each as a
|
|
120
|
+
* short prefix of its digest and never the digest, and the registry it was
|
|
121
|
+
* built from when a host built it; null for a gateway that is not hosted,
|
|
122
|
+
* whose status may answer without the operator's token.
|
|
123
|
+
*/
|
|
124
|
+
readonly hosted: {
|
|
125
|
+
readonly tenant: string | null;
|
|
126
|
+
readonly tenant_keys: readonly string[];
|
|
127
|
+
readonly registry: RegistrySource | null;
|
|
128
|
+
/** Where the upstream's proof stands, when the gateway requires one; never its text. */
|
|
129
|
+
readonly upstream_proof: ProofSnapshot | null;
|
|
130
|
+
} | null;
|
|
84
131
|
}
|
|
132
|
+
/** How much of a `sha256:` digest a readback shows: enough to tell two apart, never the digest. */
|
|
133
|
+
export declare function shortDigest(digest: string): string;
|
|
134
|
+
/** Why a caller cannot see or resume a hold: nothing is held, or the token is not the holder's. */
|
|
135
|
+
type HoldRefusal = "ESCALATION_NOT_HELD" | "RESUME_TOKEN_INVALID";
|
|
136
|
+
/** Why a tenant key refuses a request: none was presented, or not one of the tenant's. */
|
|
137
|
+
export type TenantKeyRefusal = "TENANT_KEY_MISSING" | "TENANT_KEY_INVALID";
|
|
138
|
+
/**
|
|
139
|
+
* The header a resume token travels in. Never the path or the query: those
|
|
140
|
+
* are what proxies, access logs and this gateway's own report write down.
|
|
141
|
+
*/
|
|
142
|
+
export declare const RESUME_TOKEN_HEADER = "agentsafe-resume-token";
|
|
85
143
|
/**
|
|
86
144
|
* The HTTP-interception ingress over the unchanged lifecycle. A request the
|
|
87
145
|
* route table calls consequential becomes a captured intent; the authority
|
|
@@ -98,6 +156,7 @@ export declare class Gateway {
|
|
|
98
156
|
private readonly metrics;
|
|
99
157
|
private readonly emitLine;
|
|
100
158
|
private readonly io;
|
|
159
|
+
private readonly security;
|
|
101
160
|
private readonly secrets;
|
|
102
161
|
private readonly demo;
|
|
103
162
|
private readonly evidence;
|
|
@@ -107,6 +166,7 @@ export declare class Gateway {
|
|
|
107
166
|
private readonly surface;
|
|
108
167
|
readonly boundary: EnforcementBoundary;
|
|
109
168
|
readonly workload: WorkloadSignal | null;
|
|
169
|
+
private readonly proof;
|
|
110
170
|
private readonly held;
|
|
111
171
|
private readonly holder;
|
|
112
172
|
private readonly capture;
|
|
@@ -117,15 +177,29 @@ export declare class Gateway {
|
|
|
117
177
|
private readonly counts;
|
|
118
178
|
private readonly activation;
|
|
119
179
|
private readonly ledger;
|
|
180
|
+
private readonly bucket;
|
|
181
|
+
/** The tenant key's refusals on the security stream, bounded per window. */
|
|
182
|
+
private readonly refusals;
|
|
120
183
|
private lastShadowReportAt;
|
|
184
|
+
/** The tenant keys admitted now: the configuration's, until a host replaces them in place. */
|
|
185
|
+
private admitted;
|
|
186
|
+
private registry;
|
|
121
187
|
private constructor();
|
|
122
188
|
/**
|
|
123
189
|
* Assembles the gateway: the secrets it needs opened, the demo authority
|
|
124
190
|
* started when chosen, the guarded egress sealed to the authority, the
|
|
125
|
-
* pipeline objects built over it, the evidence chains restored
|
|
126
|
-
* listens; the listener is the caller's.
|
|
191
|
+
* pipeline objects built over it, the evidence chains restored or
|
|
192
|
+
* continued. Nothing listens; the listener is the caller's.
|
|
127
193
|
*/
|
|
128
194
|
static create(config: GatewayConfig, dependencies?: GatewayDependencies): Promise<Gateway>;
|
|
195
|
+
/**
|
|
196
|
+
* The upstream's proof, when the configuration requires one: a check of its
|
|
197
|
+
* own and a monitor, pending until it looks or takes over from the gateway
|
|
198
|
+
* this one replaces (`takeOver`).
|
|
199
|
+
*/
|
|
200
|
+
private static upstreamProof;
|
|
201
|
+
/** TXT through the system's resolver, bounded, so a check never waits on DNS for long. */
|
|
202
|
+
private static systemTxt;
|
|
129
203
|
get authorityLabel(): string;
|
|
130
204
|
get evidenceLabel(): string;
|
|
131
205
|
/** The banner, once the listener is bound. */
|
|
@@ -145,21 +219,97 @@ export declare class Gateway {
|
|
|
145
219
|
readonly body: Record<string, unknown>;
|
|
146
220
|
};
|
|
147
221
|
status(): GatewayStatus;
|
|
222
|
+
/** The tenant keys the gateway admits now, as digests. */
|
|
223
|
+
get tenantKeys(): readonly string[];
|
|
224
|
+
/**
|
|
225
|
+
* Replaces the tenant keys the gateway admits, at once and without a
|
|
226
|
+
* rebuild, so a rotation or a revocation changes nothing else: not the
|
|
227
|
+
* chains, the rate, the counts or what is in flight. The digests are held
|
|
228
|
+
* to the configuration's rule; digests that break it are refused whole,
|
|
229
|
+
* and the keys admitted stay as they were.
|
|
230
|
+
*/
|
|
231
|
+
admitKeys(digests: readonly string[]): void;
|
|
232
|
+
/** The registry a host last loaded, and the entry this gateway was built from, for the status. */
|
|
233
|
+
builtFrom(source: RegistrySource): void;
|
|
234
|
+
/** What the gateway built to replace this one takes up: its chains and its funnel. */
|
|
235
|
+
continuation(): GatewayContinuation;
|
|
236
|
+
/**
|
|
237
|
+
* The swap: this gateway, built to replace `from` with its continuation,
|
|
238
|
+
* takes over what `from` still did itself. `from` stops persisting the
|
|
239
|
+
* chains' heads and looking at the upstream's proof, a look in flight
|
|
240
|
+
* included, and only finishes what it has in flight. The proof is taken as
|
|
241
|
+
* it stands now, not as it stood when this one was built: a look that ended
|
|
242
|
+
* while the registry was loading counts, and is reported once, by `from`;
|
|
243
|
+
* the last look and the next stay when they were. When `from` was bound to
|
|
244
|
+
* another tenant, organization or origin, this one looks from the start.
|
|
245
|
+
*/
|
|
246
|
+
takeOver(from: Gateway): void;
|
|
247
|
+
/**
|
|
248
|
+
* Hands on what the gateway that continues this one now does itself:
|
|
249
|
+
* persisting the chains' heads, and looking at the upstream's proof. This
|
|
250
|
+
* one goes on finishing what it has in flight. Called again, it does nothing.
|
|
251
|
+
*/
|
|
252
|
+
handedOn(): void;
|
|
253
|
+
/**
|
|
254
|
+
* What the upstream's proof lets a tenant's request do now: forwarded,
|
|
255
|
+
* forwarded and marked missing, or refused. Always forwarded when the
|
|
256
|
+
* gateway requires no proof.
|
|
257
|
+
*/
|
|
258
|
+
upstreamProof(): ProofAdmission;
|
|
259
|
+
/** Whether the first look at the upstream's proof has ended, or there is none to take. */
|
|
260
|
+
get upstreamProofSettled(): boolean;
|
|
261
|
+
/**
|
|
262
|
+
* The answer to an admitted request while the upstream's proof is not
|
|
263
|
+
* established: nothing forwarded, and the upstream named, since the gateway
|
|
264
|
+
* only observes and calling it directly loses nothing but the observation.
|
|
265
|
+
*/
|
|
266
|
+
unverified(): GatewayResponse;
|
|
267
|
+
/**
|
|
268
|
+
* Stops persisting the chains' heads, once the gateway that continues them
|
|
269
|
+
* persists them itself. A replaced gateway still finishing its requests
|
|
270
|
+
* links on the same chains, so its last checkpoint, at the end of its
|
|
271
|
+
* drain, would otherwise land after the live one's.
|
|
272
|
+
*/
|
|
273
|
+
releaseJournal(): void;
|
|
148
274
|
/** The switch the shadow report ends with, for whoever renders the status elsewhere. */
|
|
149
275
|
get enforcementSwitch(): string;
|
|
150
276
|
metricsText(): string;
|
|
151
|
-
/**
|
|
277
|
+
/**
|
|
278
|
+
* A request that is not consequential: forwarded unchanged, counted, not
|
|
279
|
+
* evaluated, and relayed as `PASSTHROUGH`, so a caller can tell an answer
|
|
280
|
+
* that came through the gateway from one that never reached it.
|
|
281
|
+
*/
|
|
152
282
|
passthrough(request: InterceptedRequest): Promise<GatewayResponse>;
|
|
153
283
|
/** A consequential request, through the whole lifecycle. */
|
|
154
284
|
govern(request: InterceptedRequest, action: string): Promise<GatewayResponse>;
|
|
155
|
-
/**
|
|
156
|
-
|
|
285
|
+
/**
|
|
286
|
+
* Why a request's tenant key refuses it, or null when it admits it: always
|
|
287
|
+
* admitted when the gateway has no keys; otherwise only a key that hashes
|
|
288
|
+
* to one of them. Every configured digest is compared, in constant time,
|
|
289
|
+
* whether or not an earlier one matched. A refusal is counted and put on
|
|
290
|
+
* the security stream with its reason, never with the value presented:
|
|
291
|
+
* one line each up to a bound per window, and a count of the rest, so a
|
|
292
|
+
* flood without the key cannot grow the chained stream with its rate.
|
|
293
|
+
*/
|
|
294
|
+
keyRefusal(presented: string | undefined): TenantKeyRefusal | null;
|
|
295
|
+
/**
|
|
296
|
+
* Whether the gateway's rate admits one more request now. Taken after the
|
|
297
|
+
* tenant key, so only the tenant's own traffic spends the tenant's rate; a
|
|
298
|
+
* refusal is counted, and says when to try again.
|
|
299
|
+
*/
|
|
300
|
+
rate(): RateDecision;
|
|
301
|
+
/**
|
|
302
|
+
* What a held escalation looks like from outside, to the caller holding its
|
|
303
|
+
* resume token; otherwise why not. The intent id is a correlation id, written
|
|
304
|
+
* to stdout and to evidence, so it is never enough on its own.
|
|
305
|
+
*/
|
|
306
|
+
escalation(intentId: string, resumeToken: string | null): Record<string, unknown> | HoldRefusal;
|
|
157
307
|
/**
|
|
158
308
|
* Asks the authority again about a held intent. Only a fresh `ALLOW` with
|
|
159
309
|
* a grant executes, once; anything else is still held or refused. The
|
|
160
310
|
* gateway never turns the hold into permission on its own.
|
|
161
311
|
*/
|
|
162
|
-
resume(intentId: string): Promise<GatewayResponse>;
|
|
312
|
+
resume(intentId: string, resumeToken: string | null): Promise<GatewayResponse>;
|
|
163
313
|
close(): Promise<void>;
|
|
164
314
|
private captureIntent;
|
|
165
315
|
private principalOf;
|
|
@@ -170,14 +320,43 @@ export declare class Gateway {
|
|
|
170
320
|
/** An ALLOW: the grant claimed, the exact request sent once, the outcome finalized and relayed. */
|
|
171
321
|
private execute;
|
|
172
322
|
private hold;
|
|
323
|
+
/**
|
|
324
|
+
* The hold under an id, for the caller presenting its token. A refusal is
|
|
325
|
+
* linked to the evidence stream, because a wrong token for a live hold is
|
|
326
|
+
* someone who read an intent id and is not its caller.
|
|
327
|
+
*/
|
|
328
|
+
private heldFor;
|
|
329
|
+
private static resumeDigest;
|
|
173
330
|
private release;
|
|
174
331
|
private expireHeld;
|
|
175
332
|
private holdBody;
|
|
176
333
|
/** The handoff without the intent, which the gateway holds itself. */
|
|
177
334
|
private handoffBody;
|
|
178
335
|
private interception;
|
|
336
|
+
/**
|
|
337
|
+
* Forwards a request as it came, counted as a passthrough, and relays the
|
|
338
|
+
* answer with the gateway's own headers; a failure is the gateway's own
|
|
339
|
+
* response, which carries its own.
|
|
340
|
+
*/
|
|
341
|
+
private forwardUnchanged;
|
|
179
342
|
private relay;
|
|
180
|
-
|
|
343
|
+
/**
|
|
344
|
+
* What a failed forward is. It is `NOT_FORWARDED` only when nothing of the
|
|
345
|
+
* request can have been accepted: a public-only upstream resolved inward,
|
|
346
|
+
* the upstream refused the handshake or its certificate did not verify,
|
|
347
|
+
* or no connection was ever made. Anything else may have come after the
|
|
348
|
+
* request was written, and the upstream may have acted on it, so it is
|
|
349
|
+
* never a refusal a caller may retry. A timeout is one wherever the send
|
|
350
|
+
* was when it ran out: the send cannot say whether it had written the
|
|
351
|
+
* request. Too large is the relay's own bound or the guarded egress's just
|
|
352
|
+
* outside it, whichever reader saw it first. A refused handshake is the
|
|
353
|
+
* tenant's configuration, reported once as `UPSTREAM_TLS_REFUSED`.
|
|
354
|
+
*/
|
|
355
|
+
private failureOf;
|
|
356
|
+
/** The gateway's own answer to a forward that failed. */
|
|
357
|
+
private failed;
|
|
358
|
+
/** A failed send's transport code: its own, as `node:http` raises it, or its cause's, as `fetch` wraps it. */
|
|
359
|
+
private static transportCode;
|
|
181
360
|
/** A response the gateway itself makes: JSON, protective headers, the wire version. */
|
|
182
361
|
private own;
|
|
183
362
|
private report;
|
|
@@ -185,4 +364,5 @@ export declare class Gateway {
|
|
|
185
364
|
private link;
|
|
186
365
|
private count;
|
|
187
366
|
}
|
|
367
|
+
export {};
|
|
188
368
|
//# sourceMappingURL=Gateway.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Gateway.d.ts","sourceRoot":"","sources":["../../src/gateway/Gateway.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Gateway.d.ts","sourceRoot":"","sources":["../../src/gateway/Gateway.ts"],"names":[],"mappings":"AAIA,OAAO,EAaL,KAAK,cAAc,EACpB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAGL,KAAK,mBAAmB,EACzB,MAAM,iCAAiC,CAAC;AAIzC,OAAO,EAAmB,KAAK,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AAE/F,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAKlD,OAAO,EAGL,KAAK,eAAe,EACrB,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oCAAoC,CAAC;AAMpE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAE7D,OAAO,EAAE,gBAAgB,EAAE,KAAK,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAC7E,OAAO,EAAsB,KAAK,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAOlF,OAAO,EAAuB,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAE7E,OAAO,EAAkB,KAAK,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAS1E,OAAO,EAAoB,KAAK,kBAAkB,EAAE,MAAM,y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