@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,3 +1,4 @@
|
|
|
1
|
+
import { ApiProfile, ApiProfiles } from "@decionis/agent-safe-pipeline";
|
|
1
2
|
import { CONSEQUENTIAL_METHODS, } from "./GatewayConfig.js";
|
|
2
3
|
const SEGMENT_WILDCARD = "*";
|
|
3
4
|
const TREE_WILDCARD = "**";
|
|
@@ -53,17 +54,29 @@ export function derivedAction(method) {
|
|
|
53
54
|
}
|
|
54
55
|
/**
|
|
55
56
|
* The route table: which requests are consequential, and what each is
|
|
56
|
-
* called. A safe method is never consequential. An
|
|
57
|
-
*
|
|
58
|
-
*
|
|
57
|
+
* called. A safe method is never consequential. An explicit route is tried
|
|
58
|
+
* first, then the API profile's operations, when the gateway governs by one
|
|
59
|
+
* (`agent-safe.profile.api/1`). An unsafe request neither names is governed
|
|
60
|
+
* under a derived name unless the configuration chose passthrough, so
|
|
61
|
+
* narrowing what is governed is an explicit act. In facts-only privacy the
|
|
62
|
+
* profile alone names a call: what it does not name is refused, because
|
|
63
|
+
* governing it would send the authority its raw path.
|
|
59
64
|
*/
|
|
60
65
|
export class RouteTable {
|
|
61
66
|
unmatched;
|
|
62
67
|
enabled;
|
|
68
|
+
profile;
|
|
69
|
+
privacy;
|
|
70
|
+
reads;
|
|
63
71
|
routes;
|
|
64
|
-
constructor(routes, unmatched, enabled = true
|
|
72
|
+
constructor(routes, unmatched, enabled = true,
|
|
73
|
+
/** The API profile the table governs by, after any explicit route; null for routes alone. */
|
|
74
|
+
profile = null, privacy = "FULL", reads = "PASSTHROUGH") {
|
|
65
75
|
this.unmatched = unmatched;
|
|
66
76
|
this.enabled = enabled;
|
|
77
|
+
this.profile = profile;
|
|
78
|
+
this.privacy = privacy;
|
|
79
|
+
this.reads = reads;
|
|
67
80
|
this.routes = routes.map((config) => {
|
|
68
81
|
const segments = routingSegments(config.path);
|
|
69
82
|
// Pattern syntax is literal configuration. Encoded wildcards must not
|
|
@@ -73,20 +86,121 @@ export class RouteTable {
|
|
|
73
86
|
return { config, segments, methods: new Set(config.methods) };
|
|
74
87
|
});
|
|
75
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* The table a gateway with this configuration plans by. Reads are checked
|
|
91
|
+
* only when the gateway pins subjects, and unknown ones refused only when
|
|
92
|
+
* the configuration says so.
|
|
93
|
+
*/
|
|
94
|
+
static of(config) {
|
|
95
|
+
const reads = config.subject === null
|
|
96
|
+
? "PASSTHROUGH"
|
|
97
|
+
: config.interception.refuseUnknownReads
|
|
98
|
+
? "REFUSE_UNKNOWN"
|
|
99
|
+
: "CHECK";
|
|
100
|
+
return new RouteTable(config.interception.routes, config.interception.unmatched, config.interception.http, config.interception.profile === null ? null : ApiProfiles.get(config.interception.profile), config.interception.privacy, reads);
|
|
101
|
+
}
|
|
76
102
|
/** Every action name this table can produce, for the registry to be sealed over. */
|
|
77
103
|
actions() {
|
|
78
104
|
const names = new Set(CONSEQUENTIAL_METHODS.map((method) => derivedAction(method)));
|
|
79
105
|
for (const route of this.routes)
|
|
80
106
|
names.add(route.config.action);
|
|
107
|
+
for (const action of this.profile?.actions() ?? [])
|
|
108
|
+
names.add(action);
|
|
81
109
|
return [...names];
|
|
82
110
|
}
|
|
83
|
-
|
|
111
|
+
/**
|
|
112
|
+
* What the table governs, in the order `plan` tries it: the explicit routes
|
|
113
|
+
* (none in facts-only privacy, which never reads them), the profile's
|
|
114
|
+
* writes, then what becomes of every other consequential request. A read
|
|
115
|
+
* is never governed, so it is not a row.
|
|
116
|
+
*/
|
|
117
|
+
rows() {
|
|
118
|
+
if (!this.enabled) {
|
|
119
|
+
return [
|
|
120
|
+
{ methods: CONSEQUENTIAL_METHODS, path: "/**", action: null, disposition: "PASSTHROUGH" },
|
|
121
|
+
];
|
|
122
|
+
}
|
|
123
|
+
const rows = [];
|
|
124
|
+
for (const route of this.privacy === "FACTS" ? [] : this.routes) {
|
|
125
|
+
rows.push({
|
|
126
|
+
methods: route.config.methods,
|
|
127
|
+
path: route.config.path,
|
|
128
|
+
action: route.config.action,
|
|
129
|
+
disposition: "GOVERN",
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
for (const operation of this.profile?.definition.operations ?? []) {
|
|
133
|
+
if (ApiProfile.isRead(operation))
|
|
134
|
+
continue;
|
|
135
|
+
rows.push({
|
|
136
|
+
methods: [operation.method],
|
|
137
|
+
path: operation.path,
|
|
138
|
+
action: operation.action,
|
|
139
|
+
disposition: "GOVERN",
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
if (this.privacy === "FACTS" || this.reads === "REFUSE_UNKNOWN") {
|
|
143
|
+
rows.push({
|
|
144
|
+
methods: CONSEQUENTIAL_METHODS,
|
|
145
|
+
path: "/**",
|
|
146
|
+
action: null,
|
|
147
|
+
disposition: "REFUSE",
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
else if (this.unmatched === "PASSTHROUGH") {
|
|
151
|
+
rows.push({
|
|
152
|
+
methods: CONSEQUENTIAL_METHODS,
|
|
153
|
+
path: "/**",
|
|
154
|
+
action: null,
|
|
155
|
+
disposition: "PASSTHROUGH",
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
for (const method of CONSEQUENTIAL_METHODS) {
|
|
160
|
+
rows.push({
|
|
161
|
+
methods: [method],
|
|
162
|
+
path: "/**",
|
|
163
|
+
action: derivedAction(method),
|
|
164
|
+
disposition: "GOVERN",
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return rows;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* A read, when reads are checked. A `GET` a profile operation names is
|
|
172
|
+
* checked. One that only resembles an operation (another letter case, an
|
|
173
|
+
* encoded literal) is refused as ambiguous, since the upstream may serve
|
|
174
|
+
* it as that operation. A path beneath a checked read (`/$count`, a
|
|
175
|
+
* navigation, a media stream) answers what the read's subject rule does
|
|
176
|
+
* not check, and a `HEAD` or `OPTIONS` on a checked read's path has no
|
|
177
|
+
* answer to check while its status says whether a record exists: both are
|
|
178
|
+
* refused. Anything else passes, or is refused when unknown reads are.
|
|
179
|
+
*/
|
|
180
|
+
planRead(method, pathname, query) {
|
|
181
|
+
if (this.reads === "PASSTHROUGH" || this.profile === null) {
|
|
182
|
+
return { kind: "PASSTHROUGH", reason: "SAFE_METHOD" };
|
|
183
|
+
}
|
|
184
|
+
const operation = method === "GET" ? this.profile.operationFor("GET", pathname, query) : null;
|
|
185
|
+
if (operation !== null) {
|
|
186
|
+
return { kind: "CHECK", action: operation.action, operation: operation.id };
|
|
187
|
+
}
|
|
188
|
+
const resembles = this.profile.resembles("GET", pathname);
|
|
189
|
+
if (this.reads === "REFUSE_UNKNOWN" ||
|
|
190
|
+
(resembles && method !== "GET") ||
|
|
191
|
+
this.profile.beneath("GET", pathname)) {
|
|
192
|
+
return { kind: "REFUSE", code: "READ_OPERATION_UNMATCHED" };
|
|
193
|
+
}
|
|
194
|
+
if (resembles)
|
|
195
|
+
return { kind: "REFUSE", code: "HTTP_PATH_AMBIGUOUS" };
|
|
196
|
+
return { kind: "PASSTHROUGH", reason: "SAFE_METHOD" };
|
|
197
|
+
}
|
|
198
|
+
plan(method, pathname, query = {}) {
|
|
84
199
|
if (!this.enabled)
|
|
85
200
|
return { kind: "PASSTHROUGH", reason: "DISABLED" };
|
|
86
201
|
const upper = method.toUpperCase();
|
|
87
|
-
if (SAFE_METHODS.has(upper))
|
|
88
|
-
return
|
|
89
|
-
}
|
|
202
|
+
if (SAFE_METHODS.has(upper))
|
|
203
|
+
return this.planRead(upper, pathname, query);
|
|
90
204
|
// WebDAV and extension methods can mutate state too. A method outside
|
|
91
205
|
// this execution contract cannot inherit the privilege of a safe read.
|
|
92
206
|
if (!CONSEQUENTIAL_METHODS.includes(upper)) {
|
|
@@ -96,11 +210,21 @@ export class RouteTable {
|
|
|
96
210
|
const path = routingSegments(pathname);
|
|
97
211
|
if (path === null)
|
|
98
212
|
return { kind: "REFUSE", code: "HTTP_PATH_AMBIGUOUS" };
|
|
99
|
-
|
|
213
|
+
const factsOnly = this.privacy === "FACTS";
|
|
214
|
+
for (const route of factsOnly ? [] : this.routes) {
|
|
100
215
|
if (route.methods.has(consequential) && matches(route.segments, path)) {
|
|
101
216
|
return { kind: "GOVERN", action: route.config.action, route: route.config };
|
|
102
217
|
}
|
|
103
218
|
}
|
|
219
|
+
const operation = this.profile?.operationFor(consequential, pathname, query) ?? null;
|
|
220
|
+
if (operation !== null) {
|
|
221
|
+
return { kind: "GOVERN", action: operation.action, route: null, operation: operation.id };
|
|
222
|
+
}
|
|
223
|
+
// Facts-only privacy would send the raw path; refusing unknown calls
|
|
224
|
+
// would relay an answer, a batch's included, that no subject rule checks.
|
|
225
|
+
if (factsOnly || this.reads === "REFUSE_UNKNOWN") {
|
|
226
|
+
return { kind: "REFUSE", code: "PROFILE_OPERATION_UNMATCHED" };
|
|
227
|
+
}
|
|
104
228
|
if (this.unmatched === "PASSTHROUGH")
|
|
105
229
|
return { kind: "PASSTHROUGH", reason: "UNMATCHED" };
|
|
106
230
|
return { kind: "GOVERN", action: derivedAction(consequential), route: null };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RouteTable.js","sourceRoot":"","sources":["../../src/gateway/RouteTable.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,
|
|
1
|
+
{"version":3,"file":"RouteTable.js","sourceRoot":"","sources":["../../src/gateway/RouteTable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AACxE,OAAO,EACL,qBAAqB,GAMtB,MAAM,oBAAoB,CAAC;AAmD5B,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAC7B,MAAM,aAAa,GAAG,IAAI,CAAC;AAC3B,MAAM,YAAY,GAAwB,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;AAC9E,MAAM,yBAAyB,GAAwB,IAAI,GAAG,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AAc3F,SAAS,UAAU,CAAC,IAAY;IAC9B,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,KAAK,EAAE,CAAC,CAAC;AAC7D,CAAC;AAED;;;;GAIG;AACH,SAAS,eAAe,CAAC,IAAY;IACnC,IAAI,OAAe,CAAC;IACpB,IAAI,CAAC;QACH,OAAO,GAAG,kBAAkB,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC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C,OAAO,EAAE,YAAY,CAAC,aAAa,EAAE,QAAQ,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC;QACrF,IAAI,SAAS,KAAK,IAAI,EAAE,CAAC;YACvB,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,CAAC,EAAE,EAAE,CAAC;QAC5F,CAAC;QACD,qEAAqE;QACrE,0EAA0E;QAC1E,IAAI,SAAS,IAAI,IAAI,CAAC,KAAK,KAAK,gBAAgB,EAAE,CAAC;YACjD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,6BAA6B,EAAE,CAAC;QACjE,CAAC;QACD,IAAI,IAAI,CAAC,SAAS,KAAK,aAAa;YAAE,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC;QAC1F,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,aAAa,CAAC,aAAa,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IAC/E,CAAC;CACF"}
|
|
@@ -27,7 +27,15 @@ export interface AcceptedCounts {
|
|
|
27
27
|
readonly ESCALATE: number;
|
|
28
28
|
readonly BLOCK: number;
|
|
29
29
|
}
|
|
30
|
+
/** Of the would-be ALLOWs of payments, what the exposure ledger would have said, by status. */
|
|
31
|
+
export type ExposureCounts = Readonly<Record<string, number>>;
|
|
30
32
|
export interface ShadowSummary {
|
|
33
|
+
/**
|
|
34
|
+
* Present once a route that releases money was observed: of its would-be
|
|
35
|
+
* ALLOWs, what the exposure ledger would have said (`WITHIN_LIMIT`,
|
|
36
|
+
* `EXCEEDED`, `UNAVAILABLE`, ...). Nothing was counted against a limit.
|
|
37
|
+
*/
|
|
38
|
+
readonly exposure?: ExposureCounts;
|
|
31
39
|
/** When the first and the last observation settled; null before any did. */
|
|
32
40
|
readonly since: string | null;
|
|
33
41
|
readonly until: string | null;
|
|
@@ -51,6 +59,7 @@ export declare class ShadowLedger {
|
|
|
51
59
|
private would;
|
|
52
60
|
private accepted;
|
|
53
61
|
private readonly byAction;
|
|
62
|
+
private exposure;
|
|
54
63
|
/** How many observations have settled so far. */
|
|
55
64
|
get observed(): number;
|
|
56
65
|
/**
|
|
@@ -59,6 +68,8 @@ export declare class ShadowLedger {
|
|
|
59
68
|
* upstream answered the forwarded request with (null when it did not).
|
|
60
69
|
*/
|
|
61
70
|
record(action: string, verdict: ShadowVerdict | null, at: string, upstreamStatus?: number | null): void;
|
|
71
|
+
/** What the exposure ledger would have said about one would-be ALLOW of a payment. */
|
|
72
|
+
recordExposure(status: string): void;
|
|
62
73
|
summary(): ShadowSummary;
|
|
63
74
|
}
|
|
64
75
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ShadowLedger.d.ts","sourceRoot":"","sources":["../../src/gateway/ShadowLedger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExD,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,UAAU,GAAG,OAAO,GAAG,MAAM,CAAC;AAEpE,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,wFAAwF;IACxF,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED;;;;;GAKG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,aAAa;IAC5B,4EAA4E;IAC5E,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,QAAQ,CAA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MAAM,CACX,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,aAAa,GAAG,IAAI,EAC7B,EAAE,EAAE,MAAM,EACV,cAAc,GAAE,MAAM,GAAG,IAAW,GACnC,IAAI;IAgBP,sFAAsF;IAC/E,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAKpC,OAAO,IAAI,aAAa;CAahC;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,CAoB/D;AAWD,+GAA+G;AAC/G,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE;IAAE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GACnC,MAAM,CAiFR"}
|
|
@@ -8,6 +8,7 @@ export class ShadowLedger {
|
|
|
8
8
|
would = ZERO;
|
|
9
9
|
accepted = { ESCALATE: 0, BLOCK: 0 };
|
|
10
10
|
byAction = new Map();
|
|
11
|
+
exposure = null;
|
|
11
12
|
/** How many observations have settled so far. */
|
|
12
13
|
get observed() {
|
|
13
14
|
return this.count;
|
|
@@ -31,8 +32,14 @@ export class ShadowLedger {
|
|
|
31
32
|
const counts = this.byAction.get(name) ?? ZERO;
|
|
32
33
|
this.byAction.set(name, { ...counts, [outcome]: counts[outcome] + 1 });
|
|
33
34
|
}
|
|
35
|
+
/** What the exposure ledger would have said about one would-be ALLOW of a payment. */
|
|
36
|
+
recordExposure(status) {
|
|
37
|
+
this.exposure ??= {};
|
|
38
|
+
this.exposure[status] = (this.exposure[status] ?? 0) + 1;
|
|
39
|
+
}
|
|
34
40
|
summary() {
|
|
35
41
|
return {
|
|
42
|
+
...(this.exposure === null ? {} : { exposure: { ...this.exposure } }),
|
|
36
43
|
since: this.since,
|
|
37
44
|
until: this.until,
|
|
38
45
|
observed: this.count,
|
|
@@ -96,6 +103,10 @@ export function renderShadowReport(report, options) {
|
|
|
96
103
|
lines.push(row(index === 0 ? "By action" : "", `${name.padEnd(width)} ${String(total).padStart(5)} ${dim(`allow ${String(counts.ALLOW)} hold ${String(counts.ESCALATE)} block ${String(counts.BLOCK)}${counts.NONE === 0 ? "" : ` none ${String(counts.NONE)}`}`)}`));
|
|
97
104
|
});
|
|
98
105
|
}
|
|
106
|
+
if (shadow.exposure !== undefined) {
|
|
107
|
+
const counts = Object.entries(shadow.exposure).sort(([a], [b]) => (a < b ? -1 : 1));
|
|
108
|
+
lines.push(row("Limits", `${counts.map(([status, count]) => `${status.toLowerCase().replace(/_/g, " ")} ${String(count)}`).join(" ")}${dim(" payments the ledger was asked about; none was counted")}`));
|
|
109
|
+
}
|
|
99
110
|
const changed = would.ESCALATE + would.BLOCK;
|
|
100
111
|
lines.push("", changed === 0
|
|
101
112
|
? `Enforcement would have changed nothing: all ${String(shadow.observed)} would have gone through as they did.`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ShadowLedger.js","sourceRoot":"","sources":["../../src/gateway/ShadowLedger.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ShadowLedger.js","sourceRoot":"","sources":["../../src/gateway/ShadowLedger.ts"],"names":[],"mappings":"AA6DA,MAAM,IAAI,GAAiB,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;AACxE,kGAAkG;AAClG,MAAM,WAAW,GAAG,KAAK,CAAC;AAE1B,MAAM,OAAO,YAAY;IACf,KAAK,GAAkB,IAAI,CAAC;IAC5B,KAAK,GAAkB,IAAI,CAAC;IAC5B,KAAK,GAAG,CAAC,CAAC;IACV,KAAK,GAAiB,IAAI,CAAC;IAC3B,QAAQ,GAAmB,EAAE,QAAQ,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;IAC5C,QAAQ,GAAG,IAAI,GAAG,EAAwB,CAAC;IACpD,QAAQ,GAAkC,IAAI,CAAC;IAEvD,iDAAiD;IACjD,IAAW,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CAAC,QAAQ,CAAC,KAAK,GAAG,CAAC,EAAE,CAAC;QAC9B,KAAK,CAAC,IAAI,CACR,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,kBAAkB,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,6LAA6L,CAClS,CAAC;IACJ,CAAC;IACD,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,EAAE,MAAM,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC;IAClD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { type WorkloadJwtVerifier } from "../identity/WorkloadJwtVerifier.js";
|
|
2
|
+
/** RFC 8693's grant type, and the token types a subject token may be stated as. */
|
|
3
|
+
export declare const TOKEN_EXCHANGE_GRANT = "urn:ietf:params:oauth:grant-type:token-exchange";
|
|
4
|
+
/** What the exchange issues: an opaque token for this gateway, never a bearer anywhere else. */
|
|
5
|
+
export declare const ISSUED_TOKEN_TYPE = "urn:ietf:params:oauth:token-type:access_token";
|
|
6
|
+
/** The most sessions held at once; beyond it a new one is refused rather than an old one dropped. */
|
|
7
|
+
export declare const MAX_SESSIONS = 10000;
|
|
8
|
+
/** How old a subject token may be: a short-lived token, minted for the conversation at hand. */
|
|
9
|
+
export declare const MAX_SUBJECT_TOKEN_AGE_SECONDS = 3600;
|
|
10
|
+
/** A subject the gateway has pinned: who, until when, and a short digest that names the session in evidence. */
|
|
11
|
+
export interface SubjectSession {
|
|
12
|
+
readonly subject: string;
|
|
13
|
+
readonly expiresAt: number;
|
|
14
|
+
/** `sha256:` and 12 hex characters of the token's digest; never the token. */
|
|
15
|
+
readonly id: string;
|
|
16
|
+
}
|
|
17
|
+
/** Why a request's session does not stand: the code a caller sees and the evidence records. */
|
|
18
|
+
export type SessionRefusal = "SUBJECT_SESSION_INVALID" | "SUBJECT_TOKEN_INVALID" | "SUBJECT_TOKEN_AMBIGUOUS";
|
|
19
|
+
/** A verified subject token: the subject it names and when it expires, in epoch milliseconds. */
|
|
20
|
+
export interface VerifiedSubject {
|
|
21
|
+
readonly subject: string;
|
|
22
|
+
readonly expiresAt: number;
|
|
23
|
+
}
|
|
24
|
+
/** Turns a subject token into the subject it names, or throws `JwtError`. */
|
|
25
|
+
export interface SubjectTokenVerifier {
|
|
26
|
+
verify(token: string): Promise<VerifiedSubject>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The operator's identity provider: a signature from its key set, its issuer
|
|
30
|
+
* exactly, the gateway's audience, a token at most an hour old, and the
|
|
31
|
+
* subject in the configured claim, a string or a number of at most 200
|
|
32
|
+
* characters. Who the customer is, is the provider's statement; the gateway
|
|
33
|
+
* only pins it.
|
|
34
|
+
*/
|
|
35
|
+
export declare class IssuerSubjectVerifier implements SubjectTokenVerifier {
|
|
36
|
+
private readonly jwt;
|
|
37
|
+
private readonly issuer;
|
|
38
|
+
private readonly claim;
|
|
39
|
+
constructor(jwt: WorkloadJwtVerifier, issuer: string, claim: string);
|
|
40
|
+
verify(token: string): Promise<VerifiedSubject>;
|
|
41
|
+
}
|
|
42
|
+
/** The token exchange's answer: RFC 8693 §2.2, or an RFC 6749 §5.2 error. */
|
|
43
|
+
export type ExchangeAnswer = {
|
|
44
|
+
readonly status: 200;
|
|
45
|
+
readonly body: {
|
|
46
|
+
readonly access_token: string;
|
|
47
|
+
readonly issued_token_type: typeof ISSUED_TOKEN_TYPE;
|
|
48
|
+
readonly token_type: "N_A";
|
|
49
|
+
readonly expires_in: number;
|
|
50
|
+
};
|
|
51
|
+
/** The session, for the evidence line; its token is in the body only. */
|
|
52
|
+
readonly session: SubjectSession;
|
|
53
|
+
} | {
|
|
54
|
+
readonly status: 400 | 503;
|
|
55
|
+
readonly body: {
|
|
56
|
+
readonly error: string;
|
|
57
|
+
readonly error_description: string;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Subject-bound sessions. The app that starts an agent (a contact centre, a
|
|
62
|
+
* CRM, a customer's own portal) holds a short-lived token from its identity
|
|
63
|
+
* provider naming the customer in context. It gives the gateway that token,
|
|
64
|
+
* and the gateway pins the subject for the session:
|
|
65
|
+
*
|
|
66
|
+
* - by RFC 8693 token exchange: `POST /_agentsafe/v1/sessions` returns an
|
|
67
|
+
* opaque session token, which the agent presents in `AgentSafe-Session`;
|
|
68
|
+
* the gateway keeps only the token's digest, beside the subject;
|
|
69
|
+
* - or per request, the provider's token itself in `AgentSafe-Subject-Token`.
|
|
70
|
+
*
|
|
71
|
+
* Either way the subject comes from the provider's signature and nothing the
|
|
72
|
+
* agent sends can change it: the session token maps to a subject held here,
|
|
73
|
+
* and the provider's token is verified on every request. Both headers end at
|
|
74
|
+
* the gateway. A session lasts as long as this gateway process: it is held in
|
|
75
|
+
* memory, so behind several replicas present the provider's token per
|
|
76
|
+
* request, or keep a caller on one replica.
|
|
77
|
+
*/
|
|
78
|
+
export declare class SubjectSessions {
|
|
79
|
+
private readonly verifier;
|
|
80
|
+
private readonly options;
|
|
81
|
+
private readonly sessions;
|
|
82
|
+
/**
|
|
83
|
+
* The session each subject token was last exchanged for, by the token's
|
|
84
|
+
* digest: exchanging a token again replaces its session rather than add
|
|
85
|
+
* one, so one token cannot fill the gateway's sessions.
|
|
86
|
+
*/
|
|
87
|
+
private readonly byToken;
|
|
88
|
+
constructor(verifier: SubjectTokenVerifier, options: {
|
|
89
|
+
readonly ttlSeconds: number;
|
|
90
|
+
readonly clock: () => number;
|
|
91
|
+
readonly maxSessions?: number;
|
|
92
|
+
});
|
|
93
|
+
/** The sessions held now, expired ones dropped first. */
|
|
94
|
+
get size(): number;
|
|
95
|
+
/**
|
|
96
|
+
* RFC 8693 token exchange: a subject token in, a session token out. The
|
|
97
|
+
* request is the form the RFC defines; an actor token (delegation) is not
|
|
98
|
+
* accepted, and the only token issued is this gateway's session token. A
|
|
99
|
+
* token that does not verify is `invalid_request`, as the RFC says, with
|
|
100
|
+
* the stable code as its description and nothing from the token.
|
|
101
|
+
*/
|
|
102
|
+
exchange(form: URLSearchParams): Promise<ExchangeAnswer>;
|
|
103
|
+
/**
|
|
104
|
+
* The session a request presents: null when it presents none, the session
|
|
105
|
+
* when it stands, and the refusal otherwise. A request may present one of
|
|
106
|
+
* the two headers, never both, since two would be two answers to whose
|
|
107
|
+
* session it is.
|
|
108
|
+
*/
|
|
109
|
+
resolve(headers: Readonly<Record<string, string>>): Promise<SubjectSession | SessionRefusal | null>;
|
|
110
|
+
private expire;
|
|
111
|
+
private static digest;
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=SubjectSessions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SubjectSessions.d.ts","sourceRoot":"","sources":["../../src/gateway/SubjectSessions.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,KAAK,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAGxF,mFAAmF;AACnF,eAAO,MAAM,oBAAoB,oDAAoD,CAAC;AAMtF,gGAAgG;AAChG,eAAO,MAAM,iBAAiB,kDAAkD,CAAC;AACjF,qGAAqG;AACrG,eAAO,MAAM,YAAY,QAAS,CAAC;AAGnC,gGAAgG;AAChG,eAAO,MAAM,6BAA6B,OAAQ,CAAC;AAEnD,gHAAgH;AAChH,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,8EAA8E;IAC9E,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;CACrB;AAED,+FAA+F;AAC/F,MAAM,MAAM,cAAc,GACxB,yBAAyB,GAAG,uBAAuB,GAAG,yBAAyB,CAAC;AAElF,iGAAiG;AACjG,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,OAAO,EA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