@decionis/agentsafe 0.2.5 → 0.4.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 +264 -89
- package/dist/Cli.js +24 -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 +2 -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/EffectAwareGrantVerifier.d.ts +5 -2
- package/dist/adapters/EffectAwareGrantVerifier.d.ts.map +1 -1
- package/dist/adapters/EffectAwareGrantVerifier.js +9 -0
- package/dist/adapters/EffectAwareGrantVerifier.js.map +1 -1
- package/dist/adapters/banking/BankingAction.d.ts +2 -2
- 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/CardHoldSeal.d.ts +29 -0
- package/dist/adapters/cards/CardHoldSeal.d.ts.map +1 -0
- package/dist/adapters/cards/CardHoldSeal.js +87 -0
- package/dist/adapters/cards/CardHoldSeal.js.map +1 -0
- package/dist/adapters/cards/CardHoldStore.d.ts +102 -0
- package/dist/adapters/cards/CardHoldStore.d.ts.map +1 -0
- package/dist/adapters/cards/CardHoldStore.js +9 -0
- package/dist/adapters/cards/CardHoldStore.js.map +1 -0
- package/dist/adapters/cards/CardHolds.d.ts +19 -0
- package/dist/adapters/cards/CardHolds.d.ts.map +1 -0
- package/dist/adapters/cards/CardHolds.js +57 -0
- package/dist/adapters/cards/CardHolds.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 +69 -0
- package/dist/adapters/cards/HeldCardGrants.d.ts.map +1 -0
- package/dist/adapters/cards/HeldCardGrants.js +169 -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/cards/PostgresCardHolds.d.ts +95 -0
- package/dist/adapters/cards/PostgresCardHolds.d.ts.map +1 -0
- package/dist/adapters/cards/PostgresCardHolds.js +411 -0
- package/dist/adapters/cards/PostgresCardHolds.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/Cards.d.ts +5 -0
- package/dist/cli/Cards.d.ts.map +1 -0
- package/dist/cli/Cards.js +48 -0
- package/dist/cli/Cards.js.map +1 -0
- 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 +9 -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 +31 -0
- package/dist/config/ConfigKeys.js.map +1 -1
- package/dist/config/ExecutorConfig.d.ts +115 -0
- package/dist/config/ExecutorConfig.d.ts.map +1 -1
- package/dist/config/ExecutorConfig.js +212 -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 +24 -0
- package/dist/http/Routes.d.ts.map +1 -1
- package/dist/http/Routes.js +28 -1
- 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/Authenticator.d.ts.map +1 -1
- package/dist/identity/Authenticator.js +5 -2
- package/dist/identity/Authenticator.js.map +1 -1
- package/dist/identity/PrincipalsFile.d.ts +5 -1
- package/dist/identity/PrincipalsFile.d.ts.map +1 -1
- package/dist/identity/PrincipalsFile.js +2 -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 +98 -0
- package/dist/incident/SecurityEvents.d.ts.map +1 -1
- package/dist/incident/SecurityEvents.js +96 -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 +109 -5
- package/dist/service/EscalationResolver.d.ts.map +1 -1
- package/dist/service/EscalationResolver.js +41 -3
- package/dist/service/EscalationResolver.js.map +1 -1
- package/dist/service/Requests.d.ts +45 -2
- package/dist/service/Requests.d.ts.map +1 -1
- package/dist/service/TrustedExecutorService.d.ts +144 -1
- package/dist/service/TrustedExecutorService.d.ts.map +1 -1
- package/dist/service/TrustedExecutorService.js +866 -37
- 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,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A usage period: one calendar month in UTC, written `YYYY-MM`. Its start is
|
|
3
|
+
* the first instant of the month and its end the first instant of the next,
|
|
4
|
+
* so a line belongs to exactly one period: `start <= at < end`.
|
|
5
|
+
*/
|
|
6
|
+
export interface UsagePeriod {
|
|
7
|
+
readonly period: string;
|
|
8
|
+
/** Milliseconds since the epoch, inclusive. */
|
|
9
|
+
readonly start: number;
|
|
10
|
+
/** Milliseconds since the epoch, exclusive: the next period's start. */
|
|
11
|
+
readonly end: number;
|
|
12
|
+
}
|
|
13
|
+
/** The period `period` names, or null when it is not one. */
|
|
14
|
+
export declare function usagePeriod(period: string): UsagePeriod | null;
|
|
15
|
+
/** The period an instant falls in. */
|
|
16
|
+
export declare function periodOf(instant: number): UsagePeriod;
|
|
17
|
+
/** The period before `period`. */
|
|
18
|
+
export declare function previousPeriod(period: UsagePeriod): UsagePeriod;
|
|
19
|
+
/** Whether `instant` lies inside the period. */
|
|
20
|
+
export declare function inPeriod(period: UsagePeriod, instant: number): boolean;
|
|
21
|
+
/** When the report for `period` is due: `dueDays` days after it ends. */
|
|
22
|
+
export declare function reportDueAt(period: UsagePeriod, dueDays: number): number;
|
|
23
|
+
//# sourceMappingURL=UsagePeriod.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UsagePeriod.d.ts","sourceRoot":"","sources":["../../src/edge/UsagePeriod.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,+CAA+C;IAC/C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,wEAAwE;IACxE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAMD,6DAA6D;AAC7D,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CAM9D;AAED,sCAAsC;AACtC,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,WAAW,CAIrD;AAED,kCAAkC;AAClC,wBAAgB,cAAc,CAAC,MAAM,EAAE,WAAW,GAAG,WAAW,CAE/D;AAED,gDAAgD;AAChD,wBAAgB,QAAQ,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAEtE;AAED,yEAAyE;AACzE,wBAAgB,WAAW,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAExE"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** Years 2000 to 2999: `Date.UTC` reads a two-digit year as the 1900s, so none is accepted. */
|
|
2
|
+
const PERIOD = /^(2\d{3})-(0[1-9]|1[0-2])$/;
|
|
3
|
+
const DAY_MS = 86_400_000;
|
|
4
|
+
/** The period `period` names, or null when it is not one. */
|
|
5
|
+
export function usagePeriod(period) {
|
|
6
|
+
const match = PERIOD.exec(period);
|
|
7
|
+
if (match === null)
|
|
8
|
+
return null;
|
|
9
|
+
const year = Number(match[1]);
|
|
10
|
+
const month = Number(match[2]) - 1;
|
|
11
|
+
return { period, start: Date.UTC(year, month, 1), end: Date.UTC(year, month + 1, 1) };
|
|
12
|
+
}
|
|
13
|
+
/** The period an instant falls in. */
|
|
14
|
+
export function periodOf(instant) {
|
|
15
|
+
const date = new Date(instant);
|
|
16
|
+
const month = String(date.getUTCMonth() + 1).padStart(2, "0");
|
|
17
|
+
return usagePeriod(`${String(date.getUTCFullYear())}-${month}`);
|
|
18
|
+
}
|
|
19
|
+
/** The period before `period`. */
|
|
20
|
+
export function previousPeriod(period) {
|
|
21
|
+
return periodOf(period.start - 1);
|
|
22
|
+
}
|
|
23
|
+
/** Whether `instant` lies inside the period. */
|
|
24
|
+
export function inPeriod(period, instant) {
|
|
25
|
+
return instant >= period.start && instant < period.end;
|
|
26
|
+
}
|
|
27
|
+
/** When the report for `period` is due: `dueDays` days after it ends. */
|
|
28
|
+
export function reportDueAt(period, dueDays) {
|
|
29
|
+
return period.end + dueDays * DAY_MS;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=UsagePeriod.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UsagePeriod.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AAE,OAAe;IAC3D,OAAO,OAAO,IAAI,MAAM,CAAC,KAAK,IAAI,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC;AACzD,CAAC;AAED,yEAAyE;AACzE,MAAM,UAAU,WAAW,CAAC,MAAmB,EAAE,OAAe;IAC9D,OAAO,MAAM,CAAC,GAAG,GAAG,OAAO,GAAG,MAAM,CAAC;AACvC,CAAC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { type KeyObject } from "node:crypto";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { type UsagePeriod } from "./UsagePeriod.js";
|
|
4
|
+
import type { PeriodUsage } from "./UsageTally.js";
|
|
5
|
+
/** The JWS `typ` of a usage report, as Decionis ingestion checks it. */
|
|
6
|
+
export declare const USAGE_REPORT_TYPE = "decionis-edge-usage+jwt";
|
|
7
|
+
/** The claims of a usage report (Edge evaluator phase 4, section 3). */
|
|
8
|
+
export declare const UsageReportClaimsSchema: z.ZodObject<{
|
|
9
|
+
iss: z.ZodString;
|
|
10
|
+
aud: z.ZodString;
|
|
11
|
+
iat: z.ZodNumber;
|
|
12
|
+
jti: z.ZodString;
|
|
13
|
+
period: z.ZodString;
|
|
14
|
+
period_start: z.ZodString;
|
|
15
|
+
period_end: z.ZodString;
|
|
16
|
+
counts: z.ZodObject<{
|
|
17
|
+
by_mode: z.ZodObject<{
|
|
18
|
+
ENFORCEMENT: z.ZodNumber;
|
|
19
|
+
SHADOW: z.ZodNumber;
|
|
20
|
+
}, z.core.$strict>;
|
|
21
|
+
by_verdict: z.ZodObject<{
|
|
22
|
+
ALLOW: z.ZodNumber;
|
|
23
|
+
ESCALATE: z.ZodNumber;
|
|
24
|
+
BLOCK: z.ZodNumber;
|
|
25
|
+
}, z.core.$strict>;
|
|
26
|
+
total: z.ZodNumber;
|
|
27
|
+
}, z.core.$strict>;
|
|
28
|
+
delegated: z.ZodNumber;
|
|
29
|
+
chain: z.ZodObject<{
|
|
30
|
+
stream: z.ZodString;
|
|
31
|
+
first_seq: z.ZodNullable<z.ZodNumber>;
|
|
32
|
+
last_seq: z.ZodNullable<z.ZodNumber>;
|
|
33
|
+
first_hash: z.ZodNullable<z.ZodString>;
|
|
34
|
+
last_hash: z.ZodNullable<z.ZodString>;
|
|
35
|
+
}, z.core.$strict>;
|
|
36
|
+
bundles: z.ZodArray<z.ZodString>;
|
|
37
|
+
}, z.core.$strict>;
|
|
38
|
+
export type UsageReportClaims = z.infer<typeof UsageReportClaimsSchema>;
|
|
39
|
+
/** The usage report's claims for one period, as this installation counted it. */
|
|
40
|
+
export declare function usageReportClaims(input: {
|
|
41
|
+
readonly installationId: string;
|
|
42
|
+
readonly orgId: string;
|
|
43
|
+
readonly period: UsagePeriod;
|
|
44
|
+
readonly usage: PeriodUsage;
|
|
45
|
+
readonly stream: string;
|
|
46
|
+
readonly now: number;
|
|
47
|
+
/** The report's id; a fresh UUID unless a fixed vector names one. */
|
|
48
|
+
readonly jti?: string;
|
|
49
|
+
}): UsageReportClaims;
|
|
50
|
+
/** The usage the claims state, in the tally's shape, for a recount to compare with. */
|
|
51
|
+
export declare function claimedUsage(claims: UsageReportClaims): PeriodUsage & {
|
|
52
|
+
readonly stream: string;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Whether the claims agree with themselves: the period's bounds are the
|
|
56
|
+
* period's, each breakdown sums to the total, no more were delegated than
|
|
57
|
+
* decided, and the range is named exactly when something was counted.
|
|
58
|
+
*/
|
|
59
|
+
export declare function consistentClaims(claims: UsageReportClaims): boolean;
|
|
60
|
+
/** An installation's usage-report key: Ed25519, with the `kid` it is registered under. */
|
|
61
|
+
export interface UsageSigningKey {
|
|
62
|
+
readonly kid: string;
|
|
63
|
+
readonly privateKey: KeyObject;
|
|
64
|
+
/** The public half, as `POST /v1/execution/provider-keys` takes it. */
|
|
65
|
+
readonly publicJwk: {
|
|
66
|
+
readonly kty: "OKP";
|
|
67
|
+
readonly crv: "Ed25519";
|
|
68
|
+
readonly x: string;
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Reads a PKCS#8 PEM Ed25519 key. The `kid` is the one configured, or the
|
|
73
|
+
* key's RFC 7638 thumbprint, so the same key always has the same id.
|
|
74
|
+
*/
|
|
75
|
+
export declare function usageSigningKey(pem: string, kid?: string | null): UsageSigningKey;
|
|
76
|
+
/** The compact JWS Decionis ingests: `alg` EdDSA, `typ` the usage report's, `kid` the key's. */
|
|
77
|
+
export declare function signUsageReport(claims: UsageReportClaims, key: UsageSigningKey): Promise<string>;
|
|
78
|
+
export type UsageReportRead = {
|
|
79
|
+
readonly ok: true;
|
|
80
|
+
readonly kid: string;
|
|
81
|
+
readonly claims: UsageReportClaims;
|
|
82
|
+
} | {
|
|
83
|
+
readonly ok: false;
|
|
84
|
+
readonly code: string;
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Checks a usage report's signature against a public key and its claims
|
|
88
|
+
* against the schema and themselves. It does not recount: `verifyUsage`
|
|
89
|
+
* does that against the chain.
|
|
90
|
+
*/
|
|
91
|
+
export declare function readUsageReport(token: string, publicJwk: Readonly<Record<string, unknown>>): Promise<UsageReportRead>;
|
|
92
|
+
//# sourceMappingURL=UsageReport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UsageReport.d.ts","sourceRoot":"","sources":["../../src/edge/UsageReport.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,SAAS,EACf,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAe,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEnD,wEAAwE;AACxE,eAAO,MAAM,iBAAiB,4BAA4B,CAAC;AAM3D,wEAAwE;AACxE,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAwBlC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AE,eAAe,GACnB,OAAO,CAAC,MAAM,CAAC,CAKjB;AAED,MAAM,MAAM,eAAe,GACvB;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,iBAAiB,CAAA;CAAE,GAC/E;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAElD;;;;GAIG;AACH,wBAAsB,eAAe,CACnC,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAC3C,OAAO,CAAC,eAAe,CAAC,CAgC1B"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { createHash, createPrivateKey, createPublicKey, randomUUID, } from "node:crypto";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { usagePeriod } from "./UsagePeriod.js";
|
|
4
|
+
/** The JWS `typ` of a usage report, as Decionis ingestion checks it. */
|
|
5
|
+
export const USAGE_REPORT_TYPE = "decionis-edge-usage+jwt";
|
|
6
|
+
const identifier = z.string().min(1).max(200);
|
|
7
|
+
const count = z.number().int().nonnegative();
|
|
8
|
+
const sha256 = z.string().regex(/^sha256:[0-9a-f]{64}$/);
|
|
9
|
+
/** The claims of a usage report (Edge evaluator phase 4, section 3). */
|
|
10
|
+
export const UsageReportClaimsSchema = z.strictObject({
|
|
11
|
+
/** The installation: one executor's evidence chain. */
|
|
12
|
+
iss: identifier,
|
|
13
|
+
/** The Decionis organisation. */
|
|
14
|
+
aud: identifier,
|
|
15
|
+
iat: count,
|
|
16
|
+
jti: identifier,
|
|
17
|
+
period: z.string().regex(/^2\d{3}-(?:0[1-9]|1[0-2])$/),
|
|
18
|
+
period_start: z.string().datetime(),
|
|
19
|
+
period_end: z.string().datetime(),
|
|
20
|
+
counts: z.strictObject({
|
|
21
|
+
by_mode: z.strictObject({ ENFORCEMENT: count, SHADOW: count }),
|
|
22
|
+
by_verdict: z.strictObject({ ALLOW: count, ESCALATE: count, BLOCK: count }),
|
|
23
|
+
total: count,
|
|
24
|
+
}),
|
|
25
|
+
delegated: count,
|
|
26
|
+
chain: z.strictObject({
|
|
27
|
+
stream: identifier,
|
|
28
|
+
first_seq: count.nullable(),
|
|
29
|
+
last_seq: count.nullable(),
|
|
30
|
+
first_hash: sha256.nullable(),
|
|
31
|
+
last_hash: sha256.nullable(),
|
|
32
|
+
}),
|
|
33
|
+
bundles: z.array(identifier).max(10_000),
|
|
34
|
+
});
|
|
35
|
+
/** The usage report's claims for one period, as this installation counted it. */
|
|
36
|
+
export function usageReportClaims(input) {
|
|
37
|
+
const { usage } = input;
|
|
38
|
+
return {
|
|
39
|
+
iss: input.installationId,
|
|
40
|
+
aud: input.orgId,
|
|
41
|
+
iat: Math.floor(input.now / 1000),
|
|
42
|
+
jti: input.jti ?? randomUUID(),
|
|
43
|
+
period: input.period.period,
|
|
44
|
+
period_start: new Date(input.period.start).toISOString(),
|
|
45
|
+
period_end: new Date(input.period.end).toISOString(),
|
|
46
|
+
counts: usage.counts,
|
|
47
|
+
delegated: usage.delegated,
|
|
48
|
+
chain: {
|
|
49
|
+
stream: input.stream,
|
|
50
|
+
first_seq: usage.first_seq,
|
|
51
|
+
last_seq: usage.last_seq,
|
|
52
|
+
first_hash: usage.first_hash,
|
|
53
|
+
last_hash: usage.last_hash,
|
|
54
|
+
},
|
|
55
|
+
bundles: [...usage.bundles],
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/** The usage the claims state, in the tally's shape, for a recount to compare with. */
|
|
59
|
+
export function claimedUsage(claims) {
|
|
60
|
+
return {
|
|
61
|
+
counts: claims.counts,
|
|
62
|
+
delegated: claims.delegated,
|
|
63
|
+
first_seq: claims.chain.first_seq,
|
|
64
|
+
first_hash: claims.chain.first_hash,
|
|
65
|
+
last_seq: claims.chain.last_seq,
|
|
66
|
+
last_hash: claims.chain.last_hash,
|
|
67
|
+
bundles: claims.bundles,
|
|
68
|
+
stream: claims.chain.stream,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Whether the claims agree with themselves: the period's bounds are the
|
|
73
|
+
* period's, each breakdown sums to the total, no more were delegated than
|
|
74
|
+
* decided, and the range is named exactly when something was counted.
|
|
75
|
+
*/
|
|
76
|
+
export function consistentClaims(claims) {
|
|
77
|
+
const period = usagePeriod(claims.period);
|
|
78
|
+
const { by_mode, by_verdict, total } = claims.counts;
|
|
79
|
+
const range = [
|
|
80
|
+
claims.chain.first_seq,
|
|
81
|
+
claims.chain.last_seq,
|
|
82
|
+
claims.chain.first_hash,
|
|
83
|
+
claims.chain.last_hash,
|
|
84
|
+
];
|
|
85
|
+
return (Date.parse(claims.period_start) === period.start &&
|
|
86
|
+
Date.parse(claims.period_end) === period.end &&
|
|
87
|
+
by_mode.ENFORCEMENT + by_mode.SHADOW === total &&
|
|
88
|
+
by_verdict.ALLOW + by_verdict.ESCALATE + by_verdict.BLOCK === total &&
|
|
89
|
+
claims.delegated <= total &&
|
|
90
|
+
range.every((value) => (value === null) === (total === 0)));
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Reads a PKCS#8 PEM Ed25519 key. The `kid` is the one configured, or the
|
|
94
|
+
* key's RFC 7638 thumbprint, so the same key always has the same id.
|
|
95
|
+
*/
|
|
96
|
+
export function usageSigningKey(pem, kid) {
|
|
97
|
+
const privateKey = createPrivateKey(pem);
|
|
98
|
+
if (privateKey.asymmetricKeyType !== "ed25519")
|
|
99
|
+
throw new Error("USAGE_KEY_NOT_ED25519");
|
|
100
|
+
const jwk = createPublicKey(privateKey).export({ format: "jwk" });
|
|
101
|
+
const publicJwk = { kty: "OKP", crv: "Ed25519", x: String(jwk.x) };
|
|
102
|
+
const thumbprint = createHash("sha256")
|
|
103
|
+
.update(JSON.stringify({ crv: publicJwk.crv, kty: publicJwk.kty, x: publicJwk.x }))
|
|
104
|
+
.digest("base64url");
|
|
105
|
+
return { kid: kid ?? thumbprint, privateKey, publicJwk };
|
|
106
|
+
}
|
|
107
|
+
/** The compact JWS Decionis ingests: `alg` EdDSA, `typ` the usage report's, `kid` the key's. */
|
|
108
|
+
export async function signUsageReport(claims, key) {
|
|
109
|
+
const { CompactSign } = await import("jose");
|
|
110
|
+
return await new CompactSign(new TextEncoder().encode(JSON.stringify(claims)))
|
|
111
|
+
.setProtectedHeader({ alg: "EdDSA", typ: USAGE_REPORT_TYPE, kid: key.kid })
|
|
112
|
+
.sign(key.privateKey);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Checks a usage report's signature against a public key and its claims
|
|
116
|
+
* against the schema and themselves. It does not recount: `verifyUsage`
|
|
117
|
+
* does that against the chain.
|
|
118
|
+
*/
|
|
119
|
+
export async function readUsageReport(token, publicJwk) {
|
|
120
|
+
const { compactVerify, decodeProtectedHeader, importJWK } = await import("jose");
|
|
121
|
+
let header;
|
|
122
|
+
try {
|
|
123
|
+
header = decodeProtectedHeader(token);
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
return { ok: false, code: "USAGE_REPORT_MALFORMED" };
|
|
127
|
+
}
|
|
128
|
+
if (header.alg !== "EdDSA" ||
|
|
129
|
+
header.typ !== USAGE_REPORT_TYPE ||
|
|
130
|
+
typeof header.kid !== "string") {
|
|
131
|
+
return { ok: false, code: "USAGE_REPORT_MALFORMED" };
|
|
132
|
+
}
|
|
133
|
+
let payload;
|
|
134
|
+
try {
|
|
135
|
+
const key = await importJWK({ ...publicJwk, alg: "EdDSA" }, "EdDSA");
|
|
136
|
+
payload = (await compactVerify(token, key, { algorithms: ["EdDSA"] })).payload;
|
|
137
|
+
}
|
|
138
|
+
catch {
|
|
139
|
+
return { ok: false, code: "USAGE_REPORT_SIGNATURE_INVALID" };
|
|
140
|
+
}
|
|
141
|
+
let parsed;
|
|
142
|
+
try {
|
|
143
|
+
parsed = UsageReportClaimsSchema.safeParse(JSON.parse(new TextDecoder().decode(payload)));
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
return { ok: false, code: "USAGE_REPORT_MALFORMED" };
|
|
147
|
+
}
|
|
148
|
+
if (!parsed.success || !consistentClaims(parsed.data)) {
|
|
149
|
+
return { ok: false, code: "USAGE_REPORT_INCONSISTENT" };
|
|
150
|
+
}
|
|
151
|
+
return { ok: true, kid: header.kid, claims: parsed.data };
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=UsageReport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UsageReport.js","sourceRoot":"","sources":["../../src/edge/UsageReport.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,gBAAgB,EAChB,eAAe,EACf,UAAU,GAEX,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,WAAW,EAAoB,MAAM,kBAAkB,CAAC;AAGjE,wEAAwE;AACxE,MAAM,CAAC,MAAM,iBAAiB,GAAG,yBAAyB,CAAC;AAE3D,MAAM,UAAU,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAC9C,MAAM,KAAK,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC;AAC7C,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;AAEzD,wEAAwE;AACxE,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC,YAAY,CAAC;IACpD,uDAAuD;IACvD,GAAG,EAAE,UAAU;IACf,iCAAiC;IACjC,GAAG,EAAE,UAAU;IACf,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,UAAU;IACf,MAAM,EAAE,CAAC,CAAC,MA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AAE,wBAAwB,EAAE,CAAC;IACvD,CAAC;IACD,IAAI,OAAmB,CAAC;IACxB,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,SAAS,CAAC,EAAE,GAAG,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,OAAO,CAAC,CAAC;QACrE,OAAO,GAAG,CAAC,MAAM,aAAa,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,UAAU,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;IACjF,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,gCAAgC,EAAE,CAAC;IAC/D,CAAC;IACD,IAAI,MAAM,CAAC;IACX,IAAI,CAAC;QACH,MAAM,GAAG,uBAAuB,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAC5F,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,wBAAwB,EAAE,CAAC;IACvD,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;QACtD,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,2BAA2B,EAAE,CAAC;IAC1D,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;AAC5D,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { type UsagePeriod } from "./UsagePeriod.js";
|
|
2
|
+
export declare const USAGE_MODES: readonly ["ENFORCEMENT", "SHADOW"];
|
|
3
|
+
export declare const USAGE_VERDICTS: readonly ["ALLOW", "ESCALATE", "BLOCK"];
|
|
4
|
+
export type UsageMode = (typeof USAGE_MODES)[number];
|
|
5
|
+
export type UsageVerdict = (typeof USAGE_VERDICTS)[number];
|
|
6
|
+
/** One `EDGE_DECISION` line, as linked on the evidence chain. */
|
|
7
|
+
export interface UsageLine {
|
|
8
|
+
readonly at: string;
|
|
9
|
+
readonly mode: unknown;
|
|
10
|
+
readonly verdict: unknown;
|
|
11
|
+
readonly delegated: unknown;
|
|
12
|
+
readonly jti: unknown;
|
|
13
|
+
readonly seq: number;
|
|
14
|
+
readonly hash: string;
|
|
15
|
+
}
|
|
16
|
+
/** The chain range a period's counts were taken from; all null when nothing was counted. */
|
|
17
|
+
export interface UsageRange {
|
|
18
|
+
readonly first_seq: number | null;
|
|
19
|
+
readonly first_hash: string | null;
|
|
20
|
+
readonly last_seq: number | null;
|
|
21
|
+
readonly last_hash: string | null;
|
|
22
|
+
}
|
|
23
|
+
/** What one period counted: the usage report's `counts`, `delegated`, range and `bundles`. */
|
|
24
|
+
export interface PeriodUsage extends UsageRange {
|
|
25
|
+
readonly counts: {
|
|
26
|
+
readonly by_mode: Readonly<Record<UsageMode, number>>;
|
|
27
|
+
readonly by_verdict: Readonly<Record<UsageVerdict, number>>;
|
|
28
|
+
readonly total: number;
|
|
29
|
+
};
|
|
30
|
+
/** Decisions handed to Decionis (an enforcement `ESCALATE`), which Decionis meters itself. */
|
|
31
|
+
readonly delegated: number;
|
|
32
|
+
/** The bundle `jti`s decided on, sorted, each once. */
|
|
33
|
+
readonly bundles: readonly string[];
|
|
34
|
+
}
|
|
35
|
+
/** A period with nothing counted. */
|
|
36
|
+
export declare function emptyUsage(): PeriodUsage;
|
|
37
|
+
/**
|
|
38
|
+
* The count of `EDGE_DECISION` lines per UTC month, the same count whether
|
|
39
|
+
* it is kept as lines are written or recounted later from the chain. A line
|
|
40
|
+
* is counted in the period its `at` falls in; lines arrive in chain order,
|
|
41
|
+
* so the first and last counted lines are the period's range. Every edge
|
|
42
|
+
* decision is counted once in `total`; the delegated ones are also counted
|
|
43
|
+
* in `delegated`, which Decionis subtracts because it meters those itself.
|
|
44
|
+
*/
|
|
45
|
+
export declare class UsageTally {
|
|
46
|
+
private readonly periods;
|
|
47
|
+
constructor(initial?: Readonly<Record<string, PeriodUsage>>);
|
|
48
|
+
/**
|
|
49
|
+
* Counts `line` in its period and returns that period, or null for a line
|
|
50
|
+
* that is not a countable decision: an unknown mode or verdict, a
|
|
51
|
+
* `delegated` that is not a boolean, a `jti` that is not a string, an `at`
|
|
52
|
+
* that is not a time. A line outside `only`, when given, is not counted.
|
|
53
|
+
*/
|
|
54
|
+
add(line: UsageLine, only?: UsagePeriod): string | null;
|
|
55
|
+
/** What `period` counted; the empty usage when it counted nothing. */
|
|
56
|
+
usage(period: string): PeriodUsage;
|
|
57
|
+
/** The periods that counted anything, oldest first. */
|
|
58
|
+
counted(): readonly string[];
|
|
59
|
+
/** Forgets `period`, once its report is delivered and it is old enough to need no recount. */
|
|
60
|
+
forget(period: string): void;
|
|
61
|
+
snapshot(): Readonly<Record<string, PeriodUsage>>;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=UsageTally.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UsageTally.d.ts","sourceRoot":"","sources":["../../src/edge/UsageTally.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAExE,eAAO,MAAM,WAAW,oCAAqC,CAAC;AAC9D,eAAO,MAAM,cAAc,yCAA0C,CAAC;AAEtE,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AACrD,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC;AAE3D,iEAAiE;AACjE,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,E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AAE,IAAI,CAAC,EAAE,WAAW,GAAG,MAAM,GAAG,IAAI;IAiC9D,sEAAsE;IAC/D,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW;IAIzC,uDAAuD;IAChD,OAAO,IAAI,SAAS,MAAM,EAAE;IAInC,8FAA8F;IACvF,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAI5B,QAAQ,IAAI,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;CAGzD"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { inPeriod, periodOf } from "./UsagePeriod.js";
|
|
2
|
+
export const USAGE_MODES = ["ENFORCEMENT", "SHADOW"];
|
|
3
|
+
export const USAGE_VERDICTS = ["ALLOW", "ESCALATE", "BLOCK"];
|
|
4
|
+
/** A period with nothing counted. */
|
|
5
|
+
export function emptyUsage() {
|
|
6
|
+
return {
|
|
7
|
+
counts: {
|
|
8
|
+
by_mode: { ENFORCEMENT: 0, SHADOW: 0 },
|
|
9
|
+
by_verdict: { ALLOW: 0, ESCALATE: 0, BLOCK: 0 },
|
|
10
|
+
total: 0,
|
|
11
|
+
},
|
|
12
|
+
delegated: 0,
|
|
13
|
+
first_seq: null,
|
|
14
|
+
first_hash: null,
|
|
15
|
+
last_seq: null,
|
|
16
|
+
last_hash: null,
|
|
17
|
+
bundles: [],
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function isMember(values, value) {
|
|
21
|
+
return values.includes(value);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The count of `EDGE_DECISION` lines per UTC month, the same count whether
|
|
25
|
+
* it is kept as lines are written or recounted later from the chain. A line
|
|
26
|
+
* is counted in the period its `at` falls in; lines arrive in chain order,
|
|
27
|
+
* so the first and last counted lines are the period's range. Every edge
|
|
28
|
+
* decision is counted once in `total`; the delegated ones are also counted
|
|
29
|
+
* in `delegated`, which Decionis subtracts because it meters those itself.
|
|
30
|
+
*/
|
|
31
|
+
export class UsageTally {
|
|
32
|
+
periods = new Map();
|
|
33
|
+
constructor(initial = {}) {
|
|
34
|
+
for (const [period, usage] of Object.entries(initial))
|
|
35
|
+
this.periods.set(period, usage);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Counts `line` in its period and returns that period, or null for a line
|
|
39
|
+
* that is not a countable decision: an unknown mode or verdict, a
|
|
40
|
+
* `delegated` that is not a boolean, a `jti` that is not a string, an `at`
|
|
41
|
+
* that is not a time. A line outside `only`, when given, is not counted.
|
|
42
|
+
*/
|
|
43
|
+
add(line, only) {
|
|
44
|
+
const at = Date.parse(line.at);
|
|
45
|
+
if (Number.isNaN(at) ||
|
|
46
|
+
!isMember(USAGE_MODES, line.mode) ||
|
|
47
|
+
!isMember(USAGE_VERDICTS, line.verdict) ||
|
|
48
|
+
typeof line.delegated !== "boolean" ||
|
|
49
|
+
typeof line.jti !== "string" ||
|
|
50
|
+
(only !== undefined && !inPeriod(only, at))) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
const period = periodOf(at).period;
|
|
54
|
+
const usage = this.usage(period);
|
|
55
|
+
this.periods.set(period, {
|
|
56
|
+
counts: {
|
|
57
|
+
by_mode: { ...usage.counts.by_mode, [line.mode]: usage.counts.by_mode[line.mode] + 1 },
|
|
58
|
+
by_verdict: {
|
|
59
|
+
...usage.counts.by_verdict,
|
|
60
|
+
[line.verdict]: usage.counts.by_verdict[line.verdict] + 1,
|
|
61
|
+
},
|
|
62
|
+
total: usage.counts.total + 1,
|
|
63
|
+
},
|
|
64
|
+
delegated: usage.delegated + (line.delegated ? 1 : 0),
|
|
65
|
+
first_seq: usage.first_seq ?? line.seq,
|
|
66
|
+
first_hash: usage.first_hash ?? line.hash,
|
|
67
|
+
last_seq: line.seq,
|
|
68
|
+
last_hash: line.hash,
|
|
69
|
+
bundles: [...new Set([...usage.bundles, line.jti])].sort(),
|
|
70
|
+
});
|
|
71
|
+
return period;
|
|
72
|
+
}
|
|
73
|
+
/** What `period` counted; the empty usage when it counted nothing. */
|
|
74
|
+
usage(period) {
|
|
75
|
+
return this.periods.get(period) ?? emptyUsage();
|
|
76
|
+
}
|
|
77
|
+
/** The periods that counted anything, oldest first. */
|
|
78
|
+
counted() {
|
|
79
|
+
return [...this.periods.keys()].sort();
|
|
80
|
+
}
|
|
81
|
+
/** Forgets `period`, once its report is delivered and it is old enough to need no recount. */
|
|
82
|
+
forget(period) {
|
|
83
|
+
this.periods.delete(period);
|
|
84
|
+
}
|
|
85
|
+
snapshot() {
|
|
86
|
+
return Object.fromEntries(this.periods);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=UsageTally.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UsageTally.js","sourceRoot":"","sources":["../../src/edge/UsageTally.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAoB,MAAM,kBAAkB,CAAC;AAExE,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,aAAa,EAAE,QAAQ,CAAU,CAAC;AAC9D,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,OAAO,EAAE,UAAU,EAAE,OAAO,CAAU,CAAC;AAqCtE,qCAAqC;AACrC,MAAM,UAAU,UAAU;IACxB,OAAO;QACL,MAAM,EAAE;YACN,OAAO,EAAE,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE;YACtC,UAAU,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE;YAC/C,KAAK,EAAE,CAAC;SACT;QACD,SAAS,EAAE,CAAC;QACZ,SAAS,EAAE,IAAI;QACf,UAAU,EAAE,IAAI;QAChB,QAAQ,EAAE,IAAI;QACd,SAAS,EAAE,IAAI;QACf,OAAO,EAAE,EAAE;KACZ,CAAC;AACJ,CAAC;AAED,SAAS,QAAQ,CAAmB,MAAoB,EAA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OAAO,CAAC,CAAC;IAC1C,CAAC;CACF"}
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
/** Every way the sealed egress refuses a request, as a stable code. */
|
|
2
|
-
export type EgressCode = "EGRESS_SCHEME_NOT_ALLOWED" | "EGRESS_ORIGIN_NOT_ALLOWED" | "EGRESS_PATH_NOT_ALLOWED" | "EGRESS_ADDRESS_REFUSED" | "EGRESS_TLS_REJECTED" | "
|
|
2
|
+
export type EgressCode = "EGRESS_SCHEME_NOT_ALLOWED" | "EGRESS_ORIGIN_NOT_ALLOWED" | "EGRESS_PATH_NOT_ALLOWED" | "EGRESS_ADDRESS_REFUSED" | "EGRESS_TLS_REJECTED" | "EGRESS_TLS_CLIENT_CERT_REFUSED"
|
|
3
|
+
/**
|
|
4
|
+
* TLS failed once the peer was verified: reported on the security stream,
|
|
5
|
+
* never thrown, since the connection may have carried the request and its
|
|
6
|
+
* own error is what the caller gets.
|
|
7
|
+
*/
|
|
8
|
+
| "EGRESS_TLS_BROKEN" | "EGRESS_TLS_PIN_MISMATCH" | "EGRESS_BODY_TOO_LARGE" | "EGRESS_TIMEOUT" | "EGRESS_REDIRECT_REFUSED" | "EGRESS_RESPONSE_INVALID" | "EGRESS_INIT_UNSUPPORTED" | "EGRESS_GLOBAL_FETCH_LOCKED";
|
|
3
9
|
/**
|
|
4
10
|
* A refusal by the executor's own egress policy: the code, and the origin it
|
|
5
11
|
* concerned. Never the path, the headers, or anything from the request or
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EgressError.d.ts","sourceRoot":"","sources":["../../src/egress/EgressError.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,MAAM,MAAM,UAAU,GAClB,2BAA2B,GAC3B,2BAA2B,GAC3B,yBAAyB,GACzB,wBAAwB,GACxB,qBAAqB,GACrB,yBAAyB,GACzB,uBAAuB,GACvB,gBAAgB,GAChB,yBAAyB,GACzB,yBAAyB,GACzB,yBAAyB,GACzB,4BAA4B,CAAC;AAEjC;;;;GAIG;AACH,qBAAa,WAAY,SAAQ,KAAK;aAElB,IAAI,EAAE,UAAU;aAChB,MAAM,EAAE,MAAM,GAAG,IAAI;gBADrB,IAAI,EAAE,UAAU,EAChB,MAAM,GAAE,MAAM,GAAG,IAAW;CAK/C"}
|
|
1
|
+
{"version":3,"file":"EgressError.d.ts","sourceRoot":"","sources":["../../src/egress/EgressError.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,MAAM,MAAM,UAAU,GAClB,2BAA2B,GAC3B,2BAA2B,GAC3B,yBAAyB,GACzB,wBAAwB,GACxB,qBAAqB,GACrB,gCAAgC;AAClC;;;;GAIG;GACD,mBAAmB,GACnB,yBAAyB,GACzB,uBAAuB,GACvB,gBAAgB,GAChB,yBAAyB,GACzB,yBAAyB,GACzB,yBAAyB,GACzB,4BAA4B,CAAC;AAEjC;;;;GAIG;AACH,qBAAa,WAAY,SAAQ,KAAK;aAElB,IAAI,EAAE,UAAU;aAChB,MAAM,EAAE,MAAM,GAAG,IAAI;gBADrB,IAAI,EAAE,UAAU,EAChB,MAAM,GAAE,MAAM,GAAG,IAAW;CAK/C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EgressError.js","sourceRoot":"","sources":["../../src/egress/EgressError.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"EgressError.js","sourceRoot":"","sources":["../../src/egress/EgressError.ts"],"names":[],"mappings":"AAsBA;;;;GAIG;AACH,MAAM,OAAO,WAAY,SAAQ,KAAK;IAElB;IACA;IAFlB,YACkB,IAAgB,EAChB,SAAwB,IAAI;QAE5C,KAAK,CAAC,IAAI,CAAC,CAAC;QAHI,SAAI,GAAJ,IAAI,CAAY;QAChB,WAAM,GAAN,MAAM,CAAsB;QAG5C,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;IAC5B,CAAC;CACF"}
|
|
@@ -38,10 +38,23 @@ export declare class EgressPolicy {
|
|
|
38
38
|
/**
|
|
39
39
|
* Whether a resolved address may be connected to for an origin. A loopback
|
|
40
40
|
* origin must stay on this host; any other must never resolve to this
|
|
41
|
-
* host, the link, multicast, or nowhere.
|
|
42
|
-
*
|
|
41
|
+
* host, the link, multicast, or nowhere. `publicOnly` is for a destination
|
|
42
|
+
* someone other than the operator chose, as a hosted gateway's tenant
|
|
43
|
+
* chooses its upstream: it also refuses every private and shared range,
|
|
44
|
+
* the Azure platform address, and NAT64, so a name cannot reach inward.
|
|
45
|
+
* IPv4-mapped IPv6 addresses match the IPv4 ranges. The lists are built per
|
|
46
|
+
* call so that nothing about them is decided at module load.
|
|
43
47
|
*/
|
|
44
|
-
static addressRefused(address: string, loopbackOrigin: boolean): boolean;
|
|
48
|
+
static addressRefused(address: string, loopbackOrigin: boolean, publicOnly?: boolean): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Whether a URL's hostname is an address, written as the host, that the
|
|
51
|
+
* policy refuses. Connecting to such a host resolves nothing, so the
|
|
52
|
+
* resolver's check never sees it; this is that check. A name that is not an
|
|
53
|
+
* address is not refused here.
|
|
54
|
+
*/
|
|
55
|
+
static hostAddressRefused(hostname: string, publicOnly?: boolean): boolean;
|
|
56
|
+
/** A URL's hostname as the address it is, without an IPv6 address's brackets; null for a name. */
|
|
57
|
+
static addressOf(hostname: string): string | null;
|
|
45
58
|
/** The three loopback spellings the configuration accepts. */
|
|
46
59
|
static isLoopbackHost(hostname: string): boolean;
|
|
47
60
|
/** The origin the configuration named, exactly as the URL class spells it. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EgressPolicy.d.ts","sourceRoot":"","sources":["../../src/egress/EgressPolicy.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAe,MAAM,6BAA6B,CAAC;AAC/E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,oFAAoF;AACpF,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QA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C,GAAG,EAAE,MAAM,GAAG,MAAM;IAI3C,+FAA+F;WACjF,OAAO,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM;IAI/C,OAAO,CAAC,MAAM,CAAC,MAAM;CAMtB"}
|
|
@@ -86,10 +86,14 @@ export class EgressPolicy {
|
|
|
86
86
|
/**
|
|
87
87
|
* Whether a resolved address may be connected to for an origin. A loopback
|
|
88
88
|
* origin must stay on this host; any other must never resolve to this
|
|
89
|
-
* host, the link, multicast, or nowhere.
|
|
90
|
-
*
|
|
89
|
+
* host, the link, multicast, or nowhere. `publicOnly` is for a destination
|
|
90
|
+
* someone other than the operator chose, as a hosted gateway's tenant
|
|
91
|
+
* chooses its upstream: it also refuses every private and shared range,
|
|
92
|
+
* the Azure platform address, and NAT64, so a name cannot reach inward.
|
|
93
|
+
* IPv4-mapped IPv6 addresses match the IPv4 ranges. The lists are built per
|
|
94
|
+
* call so that nothing about them is decided at module load.
|
|
91
95
|
*/
|
|
92
|
-
static addressRefused(address, loopbackOrigin) {
|
|
96
|
+
static addressRefused(address, loopbackOrigin, publicOnly = false) {
|
|
93
97
|
const family = isIP(address);
|
|
94
98
|
if (family === 0)
|
|
95
99
|
return true;
|
|
@@ -109,8 +113,34 @@ export class EgressPolicy {
|
|
|
109
113
|
list.addAddress("::1", "ipv6");
|
|
110
114
|
list.addSubnet("fe80::", 10, "ipv6");
|
|
111
115
|
list.addSubnet("ff00::", 8, "ipv6");
|
|
116
|
+
if (publicOnly) {
|
|
117
|
+
list.addSubnet("10.0.0.0", 8, "ipv4");
|
|
118
|
+
list.addSubnet("100.64.0.0", 10, "ipv4");
|
|
119
|
+
list.addSubnet("172.16.0.0", 12, "ipv4");
|
|
120
|
+
list.addSubnet("192.168.0.0", 16, "ipv4");
|
|
121
|
+
list.addSubnet("198.18.0.0", 15, "ipv4");
|
|
122
|
+
list.addAddress("168.63.129.16", "ipv4");
|
|
123
|
+
list.addSubnet("fc00::", 7, "ipv6");
|
|
124
|
+
list.addSubnet("64:ff9b::", 96, "ipv6");
|
|
125
|
+
}
|
|
112
126
|
return list.check(address, type);
|
|
113
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* Whether a URL's hostname is an address, written as the host, that the
|
|
130
|
+
* policy refuses. Connecting to such a host resolves nothing, so the
|
|
131
|
+
* resolver's check never sees it; this is that check. A name that is not an
|
|
132
|
+
* address is not refused here.
|
|
133
|
+
*/
|
|
134
|
+
static hostAddressRefused(hostname, publicOnly = false) {
|
|
135
|
+
const literal = EgressPolicy.addressOf(hostname);
|
|
136
|
+
return (literal !== null &&
|
|
137
|
+
EgressPolicy.addressRefused(literal, EgressPolicy.isLoopbackHost(hostname), publicOnly));
|
|
138
|
+
}
|
|
139
|
+
/** A URL's hostname as the address it is, without an IPv6 address's brackets; null for a name. */
|
|
140
|
+
static addressOf(hostname) {
|
|
141
|
+
const literal = hostname.startsWith("[") ? hostname.slice(1, -1) : hostname;
|
|
142
|
+
return isIP(literal) === 0 ? null : literal;
|
|
143
|
+
}
|
|
114
144
|
/** The three loopback spellings the configuration accepts. */
|
|
115
145
|
static isLoopbackHost(hostname) {
|
|
116
146
|
return hostname === "localhost" || hostname === "127.0.0.1" || hostname === "[::1]";
|