@oatscenter/trellis 0.100.0-rc.37 → 0.100.0-rc.39
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/auth/authority.d.ts +6 -0
- package/auth/authority.js +46 -10
- package/auth/connection.js +53 -1
- package/auth/issuer_trust.js +10 -1
- package/auth/protocol_wasm/client/trellis_protocol_wasm_bg.wasm +0 -0
- package/auth/protocol_wasm/provider/trellis_protocol_wasm_bg.wasm +0 -0
- package/internal_sdk/generated/apis/auth/mod.d.ts +1 -1
- package/internal_sdk/generated/apis/auth/mod.js +5 -5
- package/internal_sdk/generated/apis/core/mod.js +4 -4
- package/internal_sdk/generated/apis/events/mod.js +4 -4
- package/internal_sdk/generated/apis/health/mod.js +4 -4
- package/internal_sdk/generated/apis/jobs/mod.js +4 -4
- package/internal_sdk/generated/apis/state/mod.js +4 -4
- package/internal_sdk/generated/package.json +2 -2
- package/internal_sdk/generated/participants/eventsRuntime/mod.js +4 -4
- package/internal_sdk/generated/participants/healthRuntime/mod.js +4 -4
- package/internal_sdk/generated/participants/jobsRuntime/mod.js +4 -4
- package/internal_sdk/generated/participants/platform/mod.d.ts +1 -1
- package/internal_sdk/generated/participants/platform/mod.js +6 -6
- package/internal_sdk/generated/types/_internal/p0.d.ts +1 -0
- package/internal_sdk/generated/types/_internal/p0.js +1 -0
- package/live/client_open.js +23 -7
- package/package.json +2 -2
- package/session/wire.d.ts +2 -0
- package/session/wire.js +2 -0
- package/session.js +22 -3
package/auth/authority.d.ts
CHANGED
|
@@ -160,6 +160,12 @@ export declare class SessionAuthorityOwner {
|
|
|
160
160
|
stop(): void;
|
|
161
161
|
/** Read public verification material using a fresh, pinned-issuer authenticated exchange. */
|
|
162
162
|
readIssuerMetadata(query: IssuerMetadataQuery): Promise<IssuerMetadataResponse>;
|
|
163
|
+
/**
|
|
164
|
+
* Re-read each rotated-out key still inside its live overlap. Auth sends
|
|
165
|
+
* the issuer notice on revocation too, and a revoked key then stops
|
|
166
|
+
* authorizing live use at once instead of at its signed deadline.
|
|
167
|
+
*/
|
|
168
|
+
recheckRetiringIssuers(): Promise<void>;
|
|
163
169
|
/** Authenticate one signed successor from this owner's existing durable pin. */
|
|
164
170
|
acceptIssuerRotation(bytes: Uint8Array): Promise<void>;
|
|
165
171
|
}
|
package/auth/authority.js
CHANGED
|
@@ -128,6 +128,7 @@ export class SessionAuthorityOwner {
|
|
|
128
128
|
instanceId;
|
|
129
129
|
account;
|
|
130
130
|
#keys = new Map();
|
|
131
|
+
#liveUntil = new Map();
|
|
131
132
|
#peers = new Map();
|
|
132
133
|
#materials = new Map();
|
|
133
134
|
#pending = new Map();
|
|
@@ -468,7 +469,7 @@ export class SessionAuthorityOwner {
|
|
|
468
469
|
const issuer = await this.#issuer(keyId);
|
|
469
470
|
const verified = await verifyAdmissionContextWasm(bytes, issuer, request, subject, reply, this.account, this.#now());
|
|
470
471
|
if (this.#stopped ||
|
|
471
|
-
this.#
|
|
472
|
+
this.#liveIssuer(issuer.keyId)?.state !== "active" ||
|
|
472
473
|
verified.expiresAt <= this.#now())
|
|
473
474
|
throw new Error("Unavailable");
|
|
474
475
|
return verified;
|
|
@@ -840,7 +841,7 @@ export class SessionAuthorityOwner {
|
|
|
840
841
|
assertCurrent(entry) {
|
|
841
842
|
if (this.#stopped || this.#overloaded || !this.#mirrorCovered)
|
|
842
843
|
throw new Error("authority owner unavailable");
|
|
843
|
-
const issuer = this.#
|
|
844
|
+
const issuer = this.#liveIssuer(entry.authority.issuerKeyId);
|
|
844
845
|
if (issuer?.state !== "active")
|
|
845
846
|
throw new Error("issuer unavailable for live authority");
|
|
846
847
|
assertSessionAuthorityHandleCurrentWasm(entry.handle, this.policy(), this.#revocations.has(entry.authority.authorizationSessionId));
|
|
@@ -1003,8 +1004,10 @@ export class SessionAuthorityOwner {
|
|
|
1003
1004
|
assertCurrent,
|
|
1004
1005
|
});
|
|
1005
1006
|
if (query.kind === "issuerKey" && response.result.kind === "value") {
|
|
1006
|
-
// The shared verifier checked the exact requested key
|
|
1007
|
-
|
|
1007
|
+
// The shared verifier checked the exact requested key, its non-live
|
|
1008
|
+
// state, and that only a retired key carries a live deadline.
|
|
1009
|
+
const answer = JSON.parse(response.result.payload);
|
|
1010
|
+
const historical = answer.key;
|
|
1008
1011
|
const previous = this.#keys.get(historical.keyId);
|
|
1009
1012
|
if (previous && previous.publicKey !== historical.publicKey)
|
|
1010
1013
|
throw new Error("historical issuer conflict");
|
|
@@ -1012,8 +1015,15 @@ export class SessionAuthorityOwner {
|
|
|
1012
1015
|
throw new Error("historical issuer is a live pin");
|
|
1013
1016
|
if (!previous && this.#keys.size >= 128)
|
|
1014
1017
|
throw new Error("issuer history budget exceeded");
|
|
1015
|
-
if (previous?.state !== "revoked")
|
|
1018
|
+
if (previous?.state !== "revoked") {
|
|
1016
1019
|
this.#keys.set(historical.keyId, historical);
|
|
1020
|
+
// A key Auth reports inside its overlap is live until the signed
|
|
1021
|
+
// deadline, as if this owner had followed the chain.
|
|
1022
|
+
if (!previous &&
|
|
1023
|
+
answer.liveUntil !== undefined &&
|
|
1024
|
+
answer.liveUntil > this.#now())
|
|
1025
|
+
this.#liveUntil.set(historical.keyId, answer.liveUntil);
|
|
1026
|
+
}
|
|
1017
1027
|
}
|
|
1018
1028
|
if (query.kind === "authorityStatus" &&
|
|
1019
1029
|
response.result.kind === "value") {
|
|
@@ -1052,16 +1062,38 @@ export class SessionAuthorityOwner {
|
|
|
1052
1062
|
throw new Error("authority material unavailable");
|
|
1053
1063
|
return entry.value;
|
|
1054
1064
|
}
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1065
|
+
/**
|
|
1066
|
+
* Re-read each rotated-out key still inside its live overlap. Auth sends
|
|
1067
|
+
* the issuer notice on revocation too, and a revoked key then stops
|
|
1068
|
+
* authorizing live use at once instead of at its signed deadline.
|
|
1069
|
+
*/
|
|
1070
|
+
async recheckRetiringIssuers() {
|
|
1071
|
+
for (const [keyId, until] of this.#liveUntil) {
|
|
1072
|
+
if (until <= this.#now()) {
|
|
1073
|
+
this.#liveUntil.delete(keyId);
|
|
1074
|
+
continue;
|
|
1075
|
+
}
|
|
1076
|
+
// A failed read leaves the key to its signed deadline.
|
|
1077
|
+
await this.#readIssuerMetadata({ kind: "issuerKey", keyId }, false).catch(() => undefined);
|
|
1059
1078
|
}
|
|
1079
|
+
}
|
|
1080
|
+
/** A rotated-out key stays live until its signed deadline, as in the Rust owner. */
|
|
1081
|
+
#liveIssuer(keyId) {
|
|
1082
|
+
const issuer = this.#keys.get(keyId);
|
|
1083
|
+
return issuer?.state === "retired" &&
|
|
1084
|
+
(this.#liveUntil.get(keyId) ?? 0) > this.#now()
|
|
1085
|
+
? { ...issuer, state: "active" }
|
|
1086
|
+
: issuer;
|
|
1087
|
+
}
|
|
1088
|
+
async #issuer(keyId) {
|
|
1089
|
+
let issuer = this.#liveIssuer(keyId);
|
|
1090
|
+
if (!issuer && (await this.#forwardIssuer(keyId)))
|
|
1091
|
+
issuer = this.#liveIssuer(keyId);
|
|
1060
1092
|
if (!issuer) {
|
|
1061
1093
|
const response = await this.#readIssuerMetadata({ kind: "issuerKey", keyId }, false);
|
|
1062
1094
|
if (response.result.kind !== "value")
|
|
1063
1095
|
throw new Error("historical authority issuer unavailable");
|
|
1064
|
-
issuer = this.#
|
|
1096
|
+
issuer = this.#liveIssuer(keyId);
|
|
1065
1097
|
}
|
|
1066
1098
|
if (!issuer || issuer.state === "revoked")
|
|
1067
1099
|
throw new Error("untrusted authority issuer");
|
|
@@ -1110,7 +1142,11 @@ export class SessionAuthorityOwner {
|
|
|
1110
1142
|
const existing = this.#keys.get(verified.successor.keyId);
|
|
1111
1143
|
if (existing)
|
|
1112
1144
|
throw new Error("issuer rotation conflict");
|
|
1145
|
+
const retiredAt = verified.record.previousRetiredAt;
|
|
1146
|
+
if (typeof retiredAt !== "number")
|
|
1147
|
+
throw new Error("invalid rotation");
|
|
1113
1148
|
this.#keys.set(previous.keyId, { ...previous, state: "retired" });
|
|
1149
|
+
this.#liveUntil.set(previous.keyId, retiredAt);
|
|
1114
1150
|
this.#keys.set(verified.successor.keyId, verified.successor);
|
|
1115
1151
|
this.#rotationSequence++;
|
|
1116
1152
|
this.#authenticatedIssuerSequences.set(verified.successor.keyId, this.#rotationSequence.toString());
|
package/auth/connection.js
CHANGED
|
@@ -8,6 +8,9 @@ import { base64urlDecode, base64urlEncode, sha256, utf8 } from "./utils.js";
|
|
|
8
8
|
import { initializeProtocolWasm, signProvisionedAdmissionWasm, verifyOAuthAdmissionWasm, createSessionAuthorityHandleWasm, assertSessionAuthorityHandleCurrentWasm, transportAuthorizationDigestWasm, classifyTransportAuthorizationWasm, } from "./protocol_wasm.js";
|
|
9
9
|
import { loadDefaultRuntimeTransport, } from "../runtime_transport.js";
|
|
10
10
|
import { TransportGenerationManager, } from "../transport/generations.js";
|
|
11
|
+
/** Subjects on which Auth announces a new provider of an API the session calls. */
|
|
12
|
+
const PROVIDERS_NOTICE_SUBJECT_PREFIX = "trellis.auth.providers.";
|
|
13
|
+
const ISSUER_NOTICE_SUBJECT = "trellis.auth.issuers";
|
|
11
14
|
const policySchema = z.object({
|
|
12
15
|
format: z.literal("trellis.transport-authorization.v1"),
|
|
13
16
|
account: z.string(),
|
|
@@ -87,8 +90,12 @@ export async function connectAdmitted(options) {
|
|
|
87
90
|
let renewalTimer;
|
|
88
91
|
let renewalAbort;
|
|
89
92
|
let renewalTask;
|
|
93
|
+
// Set by a notice that arrives while a renewal is in flight: that renewal
|
|
94
|
+
// may already hold Auth's answer from before the change it announces.
|
|
95
|
+
let renewalNoticed = false;
|
|
90
96
|
let mirrorRecovery;
|
|
91
97
|
const credentials = new WeakMap();
|
|
98
|
+
const noticed = new WeakSet();
|
|
92
99
|
const preparedCredentials = new WeakMap();
|
|
93
100
|
const pendingAdmissions = new WeakMap();
|
|
94
101
|
const candidates = new WeakMap();
|
|
@@ -337,6 +344,33 @@ export async function connectAdmitted(options) {
|
|
|
337
344
|
const value = candidates.get(generation.nc);
|
|
338
345
|
if (!value)
|
|
339
346
|
throw new Error("AdmissionUnavailable");
|
|
347
|
+
if (!noticed.has(generation.nc)) {
|
|
348
|
+
noticed.add(generation.nc);
|
|
349
|
+
// Routes name the providers that existed at admission. Auth announces
|
|
350
|
+
// one added since, and renewing adopts the route to it at once. Auth
|
|
351
|
+
// also announces an issuer key rotation or revocation: renewing moves
|
|
352
|
+
// this session onto authority the current key signed, and the re-check
|
|
353
|
+
// ends a revoked key's overlap.
|
|
354
|
+
for (const subject of value.admission.policy.subscribeAllow) {
|
|
355
|
+
if (!subject.startsWith(PROVIDERS_NOTICE_SUBJECT_PREFIX) &&
|
|
356
|
+
subject !== ISSUER_NOTICE_SUBJECT)
|
|
357
|
+
continue;
|
|
358
|
+
generation.nc.subscribe(subject, {
|
|
359
|
+
callback: (error) => {
|
|
360
|
+
if (error || manager.isClosed())
|
|
361
|
+
return;
|
|
362
|
+
if (renewalTask)
|
|
363
|
+
renewalNoticed = true;
|
|
364
|
+
else
|
|
365
|
+
void refreshAuthority().catch(() => {
|
|
366
|
+
/* typed failure is retained by closed() */
|
|
367
|
+
});
|
|
368
|
+
if (subject === ISSUER_NOTICE_SUBJECT)
|
|
369
|
+
void owner.recheckRetiringIssuers();
|
|
370
|
+
},
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
}
|
|
340
374
|
if (value.committed)
|
|
341
375
|
return;
|
|
342
376
|
if (!value.candidate)
|
|
@@ -393,6 +427,9 @@ export async function connectAdmitted(options) {
|
|
|
393
427
|
const signal = options.signal
|
|
394
428
|
? AbortSignal.any([options.signal, renewalAbort.signal])
|
|
395
429
|
: renewalAbort.signal;
|
|
430
|
+
// Set when the attachment this renewal leased closed under it: ordinary
|
|
431
|
+
// transport recovery then owns readmission, and this failure ends nothing.
|
|
432
|
+
let withdrawn = false;
|
|
396
433
|
const task = (async () => {
|
|
397
434
|
// A reduction can withdraw the attachment while the existing admission
|
|
398
435
|
// pipeline is preparing its replacement. Explicit renewal must join that
|
|
@@ -451,13 +488,18 @@ export async function connectAdmitted(options) {
|
|
|
451
488
|
manager.authorizationPromoted();
|
|
452
489
|
scheduleRenewal();
|
|
453
490
|
}
|
|
491
|
+
catch (error) {
|
|
492
|
+
if (lease.nc.isClosed())
|
|
493
|
+
withdrawn = true;
|
|
494
|
+
throw error;
|
|
495
|
+
}
|
|
454
496
|
finally {
|
|
455
497
|
lease.release();
|
|
456
498
|
}
|
|
457
499
|
})();
|
|
458
500
|
renewalTask = task
|
|
459
501
|
.catch(async (error) => {
|
|
460
|
-
if (!signal.aborted && !manager.isClosed()) {
|
|
502
|
+
if (!signal.aborted && !manager.isClosed() && !withdrawn) {
|
|
461
503
|
await manager.terminate(error instanceof AuthError || error instanceof TransportError
|
|
462
504
|
? error
|
|
463
505
|
: new TransportError({
|
|
@@ -474,6 +516,16 @@ export async function connectAdmitted(options) {
|
|
|
474
516
|
renewalTask = undefined;
|
|
475
517
|
renewalAbort = undefined;
|
|
476
518
|
}
|
|
519
|
+
// One trailing renewal covers every notice received meanwhile.
|
|
520
|
+
if (renewalNoticed &&
|
|
521
|
+
!renewalTask &&
|
|
522
|
+
!manager.isClosed() &&
|
|
523
|
+
!options.signal?.aborted) {
|
|
524
|
+
renewalNoticed = false;
|
|
525
|
+
void refreshAuthority().catch(() => {
|
|
526
|
+
/* typed failure is retained by closed() */
|
|
527
|
+
});
|
|
528
|
+
}
|
|
477
529
|
});
|
|
478
530
|
return renewalTask;
|
|
479
531
|
};
|
package/auth/issuer_trust.js
CHANGED
|
@@ -55,8 +55,17 @@ export async function authenticateIssuerChain(issuer, anchor, target, signal, ex
|
|
|
55
55
|
offset += chunk.length;
|
|
56
56
|
}
|
|
57
57
|
const chain = issuerChainSchema.parse(JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(bytes)));
|
|
58
|
-
for (const rotation of chain.rotations)
|
|
58
|
+
for (const rotation of chain.rotations) {
|
|
59
|
+
// A connected session sharing this owner may already have installed
|
|
60
|
+
// the link, on Auth's issuer notice. The sequence is only a lookup
|
|
61
|
+
// hint; the final trust check below still requires the target.
|
|
62
|
+
const { sequence } = JSON.parse(rotation);
|
|
63
|
+
if (typeof sequence === "string" &&
|
|
64
|
+
/^[0-9]{1,20}$/.test(sequence) &&
|
|
65
|
+
BigInt(sequence) <= BigInt(owner.trustSnapshot.rotationSequence))
|
|
66
|
+
continue;
|
|
59
67
|
await owner.acceptIssuerRotation(signedBytes(rotation));
|
|
68
|
+
}
|
|
60
69
|
}
|
|
61
70
|
const verified = owner.trustForCredential(anchor);
|
|
62
71
|
if (verified.issuer.keyId !== target.issuer.keyId ||
|
|
Binary file
|
|
Binary file
|
|
@@ -1296,5 +1296,5 @@ declare const __api: {
|
|
|
1296
1296
|
readonly packageEvidence: unknown;
|
|
1297
1297
|
};
|
|
1298
1298
|
export declare const API: typeof __api;
|
|
1299
|
-
export declare const API_DIGEST: "
|
|
1299
|
+
export declare const API_DIGEST: "OaeRlYQE6oQeGu8eaRiCz12jLLtNIheWt2dUW2ArdAk";
|
|
1300
1300
|
export {};
|