axiam-sdk 1.3.1 → 1.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 +130 -14
- package/dist/amqp/index.d.cts +384 -17
- package/dist/amqp/index.d.ts +384 -17
- package/dist/amqp/index.js +639 -66
- package/dist/amqp/index.js.map +1 -1
- package/dist/amqp/index.mjs +631 -67
- package/dist/amqp/index.mjs.map +1 -1
- package/dist/{authzCore-D-hquWSI.d.ts → authzCore-Ced9zDIV.d.ts} +49 -12
- package/dist/{authzCore-CqXzLNmT.d.cts → authzCore-Des2NcKA.d.cts} +49 -12
- package/dist/browser/index.d.cts +1 -1
- package/dist/browser/index.d.ts +1 -1
- package/dist/{client-CaurIxje.d.ts → client-C1kRISf8.d.ts} +15 -1
- package/dist/{client-Bp7riC4k.d.cts → client-Dpd864N9.d.cts} +15 -1
- package/dist/{cookieJar-oKazfbN1.d.cts → cookieJar-CeH2FZIT.d.cts} +3 -3
- package/dist/{cookieJar-DC4GLKrJ.d.ts → cookieJar-DPx9Qtcf.d.ts} +3 -3
- package/dist/grpc/index.d.cts +5 -5
- package/dist/grpc/index.d.ts +5 -5
- package/dist/grpc/index.js +249 -18
- package/dist/grpc/index.js.map +1 -1
- package/dist/grpc/index.mjs +249 -18
- package/dist/grpc/index.mjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +29 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +29 -3
- package/dist/index.mjs.map +1 -1
- package/dist/{jwks-CTVpOWzI.d.cts → jwks-CQtWokVd.d.cts} +62 -7
- package/dist/{jwks-CTVpOWzI.d.ts → jwks-CQtWokVd.d.ts} +62 -7
- package/dist/middleware/index.d.cts +220 -43
- package/dist/middleware/index.d.ts +220 -43
- package/dist/middleware/index.js +587 -149
- package/dist/middleware/index.js.map +1 -1
- package/dist/middleware/index.mjs +579 -150
- package/dist/middleware/index.mjs.map +1 -1
- package/dist/nestjs/index.d.cts +18 -4
- package/dist/nestjs/index.d.ts +18 -4
- package/dist/nestjs/index.js +20 -1
- package/dist/nestjs/index.js.map +1 -1
- package/dist/nestjs/index.mjs +19 -2
- package/dist/nestjs/index.mjs.map +1 -1
- package/dist/node/index.d.cts +5 -5
- package/dist/node/index.d.ts +5 -5
- package/dist/node/index.js +351 -66
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +348 -67
- package/dist/node/index.mjs.map +1 -1
- package/dist/{oidcState-CZhj0MBP.d.ts → oidcState-CzpXPAHF.d.ts} +54 -14
- package/dist/{oidcState-EnEJmoF5.d.cts → oidcState-XOYEMQP6.d.cts} +54 -14
- package/dist/rest/index.d.cts +3 -3
- package/dist/rest/index.d.ts +3 -3
- package/dist/rest/index.js +29 -3
- package/dist/rest/index.js.map +1 -1
- package/dist/rest/index.mjs +29 -3
- package/dist/rest/index.mjs.map +1 -1
- package/dist/{session-CeIUXgpE.d.cts → session-DoQzoChX.d.cts} +1 -1
- package/dist/{session-Beo11VT_.d.ts → session-Z-6IyaSU.d.ts} +1 -1
- package/package.json +9 -9
package/dist/amqp/index.d.cts
CHANGED
|
@@ -20,6 +20,13 @@ declare function signPayload(key: Buffer, payloadJson: Buffer): string;
|
|
|
20
20
|
* both return `false`.
|
|
21
21
|
*/
|
|
22
22
|
declare function verifyPayload(key: Buffer, payloadJson: Buffer, signatureHex: string): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Decode `bytes` as UTF-8, throwing on an invalid sequence. A leading byte-order
|
|
25
|
+
* mark is kept (`ignoreBOM`), so the decoded text and the raw bytes always
|
|
26
|
+
* agree; a BOM then makes the body fail to parse as JSON instead of being
|
|
27
|
+
* silently dropped from one view of the message only.
|
|
28
|
+
*/
|
|
29
|
+
declare function decodeUtf8Strict(bytes: Uint8Array): string;
|
|
23
30
|
|
|
24
31
|
/**
|
|
25
32
|
* Authorization check request received from `axiam.authz.request`.
|
|
@@ -62,20 +69,32 @@ interface AuthzRequest {
|
|
|
62
69
|
* HMAC-SHA256 of the JSON-serialized message body (this field removed
|
|
63
70
|
* before signing). Computed with the per-tenant AMQP signing key
|
|
64
71
|
* (CONTRACT.md §8). The consumer MUST verify this before processing; a
|
|
65
|
-
* missing signature is rejected
|
|
72
|
+
* missing signature is always rejected (no lenient mode).
|
|
66
73
|
*/
|
|
67
74
|
hmac_signature?: string;
|
|
68
75
|
}
|
|
69
76
|
/**
|
|
70
|
-
* Authorization decision published to `
|
|
77
|
+
* Authorization decision published to the request's `reply_to` queue, else
|
|
78
|
+
* `axiam.authz.response`.
|
|
71
79
|
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
80
|
+
* Server-signed from contract 1.68 (CONTRACT.md §8, "Signed authorization
|
|
81
|
+
* responses"): it carries `tenant_id`, `nonce` and `hmac_signature`, bound to
|
|
82
|
+
* the request it answers. Through 1.67 it carried none of them, so all three
|
|
83
|
+
* are optional here. Never verify one by re-serializing this object — verify
|
|
84
|
+
* the received bytes with {@link AuthzResponseVerifier}.
|
|
74
85
|
*/
|
|
75
86
|
interface AuthzResponse {
|
|
76
87
|
correlation_id: string;
|
|
77
88
|
allowed: boolean;
|
|
78
89
|
reason?: string;
|
|
90
|
+
/** `allowed`, `no_grant`, `denied_by_rule`, `tenant_suspended`, or a code this SDK does not know (verbatim). */
|
|
91
|
+
reason_code?: string;
|
|
92
|
+
/** The `tenant_id` of the request this answers (contract 1.68). */
|
|
93
|
+
tenant_id?: string;
|
|
94
|
+
/** The `nonce` of the request this answers, echoed (contract 1.68). */
|
|
95
|
+
nonce?: string;
|
|
96
|
+
/** HMAC-SHA256 over the received bytes minus this trailing member, under the tenant subkey (contract 1.68). */
|
|
97
|
+
hmac_signature?: string;
|
|
79
98
|
}
|
|
80
99
|
/**
|
|
81
100
|
* Audit event received from external services via `axiam.audit.events`.
|
|
@@ -136,9 +155,10 @@ interface NotificationEvent {
|
|
|
136
155
|
/**
|
|
137
156
|
* Message type names subject to HMAC verification per CONTRACT.md §8's
|
|
138
157
|
* message-types table (`axiam.authz.request` -> AuthzRequest,
|
|
139
|
-
* `axiam.audit.events` -> AuditEventMessage)
|
|
140
|
-
* `
|
|
141
|
-
*
|
|
158
|
+
* `axiam.audit.events` -> AuditEventMessage) — the messages a producer
|
|
159
|
+
* signs. `AuthzResponse` is server-signed from contract 1.68 but verified over
|
|
160
|
+
* its received bytes by {@link AuthzResponseVerifier}, not by this path;
|
|
161
|
+
* `NotificationEvent` carries no `hmac_signature`.
|
|
142
162
|
*/
|
|
143
163
|
declare const HMAC_SIGNED_MESSAGE_TYPES: readonly ["AuthzRequest", "AuditEventMessage"];
|
|
144
164
|
type HmacSignedMessageType = (typeof HMAC_SIGNED_MESSAGE_TYPES)[number];
|
|
@@ -264,6 +284,10 @@ declare class InMemoryNonceStore implements NonceStore {
|
|
|
264
284
|
checkAndRecord(nonce: string, ttlMs: number): boolean;
|
|
265
285
|
private prune;
|
|
266
286
|
}
|
|
287
|
+
/** The two signed event types an event consumer can be configured for (CONTRACT.md §8 step 2c, D-9). */
|
|
288
|
+
type EventType = 'AuthzRequest' | 'AuditEventMessage';
|
|
289
|
+
/** The closed vocabulary of the discard event's `reason` (CONTRACT.md §8 rule 4, D-8). */
|
|
290
|
+
type EventDiscardReason = 'malformed' | 'unsigned' | 'signature' | 'key_version' | 'stale' | 'replay';
|
|
267
291
|
/**
|
|
268
292
|
* Minimal seam over the channel operations this module needs
|
|
269
293
|
* (ack/nack/consume). `amqplib`'s `Channel` implements this directly;
|
|
@@ -282,14 +306,20 @@ interface ConsumeLogger {
|
|
|
282
306
|
warn(event: string, message: string, context?: Record<string, unknown>): void;
|
|
283
307
|
}
|
|
284
308
|
interface ConsumeOptions {
|
|
285
|
-
logger?: ConsumeLogger;
|
|
286
309
|
/**
|
|
287
|
-
*
|
|
288
|
-
*
|
|
289
|
-
*
|
|
290
|
-
* deployment measure only — strict MUST remain the default.
|
|
310
|
+
* The consumer's OWN tenant: the tenant whose signing subkey `signingKey`
|
|
311
|
+
* is (CONTRACT.md §8 rule 1). Every discard event names it as `tenantId`;
|
|
312
|
+
* a `tenant_id` read from a message body is never logged (D-8).
|
|
291
313
|
*/
|
|
292
|
-
|
|
314
|
+
tenantId: string;
|
|
315
|
+
/**
|
|
316
|
+
* The ONE signed type this consumer consumes (CONTRACT.md §8 step 2c, D-9).
|
|
317
|
+
* A body with the layout of any other signed type — the other event type, an
|
|
318
|
+
* `AuthzResponse`, a reactor message — is refused as `malformed` before the
|
|
319
|
+
* HMAC is computed. An application consuming both types runs two consumers.
|
|
320
|
+
*/
|
|
321
|
+
eventType: EventType;
|
|
322
|
+
logger?: ConsumeLogger;
|
|
293
323
|
/**
|
|
294
324
|
* Freshness skew window for `issued_at` validation (NEW-4), in
|
|
295
325
|
* milliseconds. Defaults to {@link DEFAULT_REPLAY_SKEW_MS} (5 minutes),
|
|
@@ -326,7 +356,7 @@ interface ConsumeOptions {
|
|
|
326
356
|
* unit backing `consume`'s per-message loop, mirroring the Rust SDK's
|
|
327
357
|
* `verify_and_dispatch`.
|
|
328
358
|
*/
|
|
329
|
-
declare function verifyAndDispatch(channel: ConsumeChannel, msg: ConsumeMessage, signingKey: Buffer, handler: (event: Record<string, unknown>) => Promise<void>, options
|
|
359
|
+
declare function verifyAndDispatch(channel: ConsumeChannel, msg: ConsumeMessage, signingKey: Buffer, handler: (event: Record<string, unknown>) => Promise<void>, options: ConsumeOptions): Promise<void>;
|
|
330
360
|
/**
|
|
331
361
|
* Connect to the AMQP broker at `amqpUrl`, declare `queue` as durable, and
|
|
332
362
|
* consume from it — verifying each delivery's HMAC-SHA256 signature
|
|
@@ -346,7 +376,344 @@ declare function verifyAndDispatch(channel: ConsumeChannel, msg: ConsumeMessage,
|
|
|
346
376
|
* rather than connecting and quietly putting signed-but-readable authorization
|
|
347
377
|
* requests and audit events on the wire.
|
|
348
378
|
*/
|
|
349
|
-
declare function consume(amqpUrl: string, queue: string, signingKey: Sensitive<Buffer>, handler: (event: Record<string, unknown>) => Promise<void>, options
|
|
379
|
+
declare function consume(amqpUrl: string, queue: string, signingKey: Sensitive<Buffer>, handler: (event: Record<string, unknown>) => Promise<void>, options: ConsumeOptions): Promise<void>;
|
|
380
|
+
|
|
381
|
+
/** The members of a request that its response must echo (§8 rule 3). */
|
|
382
|
+
interface OutstandingAuthzRequest {
|
|
383
|
+
/** The request's `correlation_id`. */
|
|
384
|
+
correlation_id: string;
|
|
385
|
+
/** The request's `nonce`, which a 1.68 response echoes. */
|
|
386
|
+
nonce: string;
|
|
387
|
+
/** The request's `tenant_id`; MUST be the verifier's own tenant. */
|
|
388
|
+
tenant_id: string;
|
|
389
|
+
}
|
|
390
|
+
/** A response that passed §8 rules 1–3, parsed from the bytes that were verified. */
|
|
391
|
+
interface VerifiedAuthzResponse {
|
|
392
|
+
/** Echo of the request's `correlation_id`. */
|
|
393
|
+
correlation_id: string;
|
|
394
|
+
/** The decision. */
|
|
395
|
+
allowed: boolean;
|
|
396
|
+
/** Human-readable reason, when the server gave one. */
|
|
397
|
+
reason?: string;
|
|
398
|
+
/** Machine-readable reason (`allowed`, `no_grant`, `denied_by_rule`, `tenant_suspended`, or a code this SDK does not know, verbatim). */
|
|
399
|
+
reason_code?: string;
|
|
400
|
+
/** The tenant the response answers for; equals the verifier's tenant. */
|
|
401
|
+
tenant_id: string;
|
|
402
|
+
/** Echo of the request's `nonce`. */
|
|
403
|
+
nonce: string;
|
|
404
|
+
}
|
|
405
|
+
/** Why a response was discarded. Never carries a signature value. */
|
|
406
|
+
type AuthzResponseRejection =
|
|
407
|
+
/**
|
|
408
|
+
* Not JSON, or missing / ill-typed `correlation_id`, `allowed`, `tenant_id`,
|
|
409
|
+
* `nonce`, or an `hmac_signature` member that does not end the body or is
|
|
410
|
+
* not 64 hex digits (rule 1).
|
|
411
|
+
*/
|
|
412
|
+
'malformed'
|
|
413
|
+
/** No `hmac_signature` member at all: no AXIAM server sends one to a reply queue (CONTRACT.md §8, contract 1.69). */
|
|
414
|
+
| 'unsigned'
|
|
415
|
+
/** The HMAC does not verify under this tenant's subkey (rule 2). */
|
|
416
|
+
| 'signature'
|
|
417
|
+
/** `tenant_id` is not this verifier's tenant (rule 3). */
|
|
418
|
+
| 'tenant'
|
|
419
|
+
/** No outstanding request has this `correlation_id` and `nonce` (rule 3). */
|
|
420
|
+
| 'unknown_request';
|
|
421
|
+
/** The outcome of {@link AuthzResponseVerifier.verify}. */
|
|
422
|
+
type AuthzResponseVerdict = {
|
|
423
|
+
/** The response passed every rule; its request has been retired. */
|
|
424
|
+
accepted: true;
|
|
425
|
+
/** The verified response. */
|
|
426
|
+
response: VerifiedAuthzResponse;
|
|
427
|
+
} | {
|
|
428
|
+
/** The response was discarded: never an allow, and its request stays outstanding. */
|
|
429
|
+
accepted: false;
|
|
430
|
+
/** Which rule failed. */
|
|
431
|
+
reason: AuthzResponseRejection;
|
|
432
|
+
};
|
|
433
|
+
/** Configuration for an {@link AuthzResponseVerifier}. */
|
|
434
|
+
interface AuthzResponseVerifierOptions {
|
|
435
|
+
/**
|
|
436
|
+
* The requester's own tenant subkey — the HKDF-derived per-tenant AMQP key
|
|
437
|
+
* for `tenantId` and the `key_version` the requests were signed with
|
|
438
|
+
* (currently `2`), never the master key (§8.1: provisioned out of band).
|
|
439
|
+
*/
|
|
440
|
+
subkey: Sensitive<Buffer>;
|
|
441
|
+
/** The requester's own tenant; every accepted response names it. */
|
|
442
|
+
tenantId: string;
|
|
443
|
+
/**
|
|
444
|
+
* The requester's private reply queue (the `amq.gen-…` name it declared and
|
|
445
|
+
* sent as `reply_to`). The discard event's routing key when
|
|
446
|
+
* {@link AuthzResponseVerifier.verify} is called without a delivery: the
|
|
447
|
+
* transport cannot report one, and every answer the requester can receive
|
|
448
|
+
* arrives on this queue (§8 consumer obligation 4).
|
|
449
|
+
*/
|
|
450
|
+
replyQueue?: string;
|
|
451
|
+
/** Receives security events. Never receives a signature value or the key. */
|
|
452
|
+
logger?: ConsumeLogger;
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Where a response was read from, for the security event a discarded response
|
|
456
|
+
* logs (CONTRACT.md §8 rule 4 and consumer obligation 4: timestamp, exchange,
|
|
457
|
+
* routing key, tenant, reason). {@link AuthzResponseVerifier.settle} takes
|
|
458
|
+
* it from the delivery's `msg.fields`.
|
|
459
|
+
*/
|
|
460
|
+
interface AuthzResponseDelivery {
|
|
461
|
+
/** The exchange the response was published to (`''` for the default exchange). */
|
|
462
|
+
exchange: string;
|
|
463
|
+
/** The routing key it was published with (the reply queue's name on the default exchange). */
|
|
464
|
+
routingKey: string;
|
|
465
|
+
}
|
|
466
|
+
/** The ack/nack subset of an amqplib `Channel` that {@link AuthzResponseVerifier.settle} needs. */
|
|
467
|
+
interface SettleChannel {
|
|
468
|
+
/** `channel.ack(msg)`. */
|
|
469
|
+
ack(msg: ConsumeMessage): void;
|
|
470
|
+
/** `channel.nack(msg, allUpTo, requeue)`. */
|
|
471
|
+
nack(msg: ConsumeMessage, allUpTo: boolean, requeue: boolean): void;
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Verifies signed `AuthzResponse` messages for one tenant and matches them to
|
|
475
|
+
* the caller's outstanding requests (CONTRACT.md §8 rules 1–4, contract 1.68).
|
|
476
|
+
*
|
|
477
|
+
* @example
|
|
478
|
+
* ```ts
|
|
479
|
+
* const verifier = new AuthzResponseVerifier({ subkey, tenantId });
|
|
480
|
+
* // when publishing a request (with an exclusive reply_to queue):
|
|
481
|
+
* verifier.expect({ correlation_id, nonce, tenant_id: tenantId });
|
|
482
|
+
* // for every delivery on that queue:
|
|
483
|
+
* const verdict = verifier.settle(channel, msg);
|
|
484
|
+
* if (verdict.accepted) resolvePending(verdict.response);
|
|
485
|
+
* ```
|
|
486
|
+
*/
|
|
487
|
+
declare class AuthzResponseVerifier {
|
|
488
|
+
#private;
|
|
489
|
+
/** @param options the tenant, its subkey, and the reply queue's name. */
|
|
490
|
+
constructor(options: AuthzResponseVerifierOptions);
|
|
491
|
+
/**
|
|
492
|
+
* Register a published request whose answer is awaited. Its `tenant_id`
|
|
493
|
+
* must be this verifier's tenant.
|
|
494
|
+
*
|
|
495
|
+
* @throws RangeError when the request names another tenant.
|
|
496
|
+
*/
|
|
497
|
+
expect(request: OutstandingAuthzRequest): void;
|
|
498
|
+
/** Stop waiting for `correlationId` (for example on the caller's own timeout). */
|
|
499
|
+
forget(correlationId: string): void;
|
|
500
|
+
/** Number of requests still awaiting an answer. */
|
|
501
|
+
get pending(): number;
|
|
502
|
+
/**
|
|
503
|
+
* Verify one received response body (CONTRACT.md §8 rules 1–4). On
|
|
504
|
+
* acceptance the matching request is retired, so a second response for it
|
|
505
|
+
* is dropped. On any failure nothing is retired — the genuine answer may
|
|
506
|
+
* still arrive — and a security event is logged without either signature.
|
|
507
|
+
*
|
|
508
|
+
* @param delivery where the body was read from; the security event names
|
|
509
|
+
* its exchange and routing key (§8 rule 4). {@link settle} passes it.
|
|
510
|
+
* Without it the event reports `''` and `options.replyQueue` (`''` when
|
|
511
|
+
* that is not set either).
|
|
512
|
+
*/
|
|
513
|
+
verify(body: Buffer, delivery?: AuthzResponseDelivery): AuthzResponseVerdict;
|
|
514
|
+
/**
|
|
515
|
+
* {@link verify} a delivery read from a queue, then ack it when accepted
|
|
516
|
+
* and nack it **without requeue** when discarded (§8 rule 4).
|
|
517
|
+
*/
|
|
518
|
+
settle(channel: SettleChannel, msg: ConsumeMessage): AuthzResponseVerdict;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
/** The queue the server consumes `AuthzRequest` from (CONTRACT.md §8). */
|
|
522
|
+
declare const AUTHZ_REQUEST_QUEUE = "axiam.authz.request";
|
|
523
|
+
/** Default bound on one {@link AuthzRequester.check}, in milliseconds. */
|
|
524
|
+
declare const DEFAULT_AUTHZ_TIMEOUT_MS = 10000;
|
|
525
|
+
/** Thrown by {@link AuthzRequester.check} once the requester is closed or its reply queue went away. */
|
|
526
|
+
declare class AuthzRequesterClosedError extends Error {
|
|
527
|
+
constructor();
|
|
528
|
+
}
|
|
529
|
+
/** A verified answer to one `AuthzRequest`. */
|
|
530
|
+
interface AuthzDecision {
|
|
531
|
+
/** The decision; `true` only for a response that verified. */
|
|
532
|
+
allowed: boolean;
|
|
533
|
+
/** The server's human-readable reason, when it gave one. */
|
|
534
|
+
reason?: string;
|
|
535
|
+
/** `allowed`, `no_grant`, `denied_by_rule`, `tenant_suspended`, or a code this SDK does not know (verbatim). */
|
|
536
|
+
reasonCode?: string;
|
|
537
|
+
}
|
|
538
|
+
/** One authorization question (CONTRACT.md §8 `AuthzRequest`). */
|
|
539
|
+
interface AuthzCheckInput {
|
|
540
|
+
/** The subject (user or service account) UUID. */
|
|
541
|
+
subjectId: string;
|
|
542
|
+
/** The action, e.g. `documents:read`. */
|
|
543
|
+
action: string;
|
|
544
|
+
/** The resource UUID. */
|
|
545
|
+
resourceId: string;
|
|
546
|
+
/** Optional sub-resource scope. */
|
|
547
|
+
scope?: string;
|
|
548
|
+
/** Aborts the wait (the request stays published; its answer is then dropped). */
|
|
549
|
+
signal?: AbortSignal;
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* The subset of an amqplib `Channel` the requester uses. A real `Channel`
|
|
553
|
+
* satisfies it; tests supply a fake.
|
|
554
|
+
*/
|
|
555
|
+
interface AuthzRequesterChannel {
|
|
556
|
+
/** `channel.assertQueue('', { exclusive: true, autoDelete: true, durable: false })` — a broker-named private queue. */
|
|
557
|
+
assertQueue(queue: string, options: {
|
|
558
|
+
exclusive: boolean;
|
|
559
|
+
autoDelete: boolean;
|
|
560
|
+
durable: boolean;
|
|
561
|
+
}): Promise<{
|
|
562
|
+
queue: string;
|
|
563
|
+
}>;
|
|
564
|
+
/** `channel.consume(queue, onMessage, { noAck: false, exclusive: true })`. */
|
|
565
|
+
consume(queue: string, onMessage: (msg: ConsumeMessage | null) => void, options: {
|
|
566
|
+
noAck: boolean;
|
|
567
|
+
exclusive: boolean;
|
|
568
|
+
}): Promise<{
|
|
569
|
+
consumerTag: string;
|
|
570
|
+
}>;
|
|
571
|
+
/** `channel.sendToQueue(queue, content, options)` — a publish on the default exchange. */
|
|
572
|
+
sendToQueue(queue: string, content: Buffer, options: {
|
|
573
|
+
correlationId: string;
|
|
574
|
+
replyTo: string;
|
|
575
|
+
contentType: string;
|
|
576
|
+
}): boolean;
|
|
577
|
+
/** `channel.ack(msg)`. */
|
|
578
|
+
ack(msg: ConsumeMessage): void;
|
|
579
|
+
/** `channel.nack(msg, allUpTo, requeue)`. */
|
|
580
|
+
nack(msg: ConsumeMessage, allUpTo: boolean, requeue: boolean): void;
|
|
581
|
+
/** `channel.cancel(consumerTag)`; optional. */
|
|
582
|
+
cancel?(consumerTag: string): Promise<unknown>;
|
|
583
|
+
}
|
|
584
|
+
/** Configuration for {@link createAuthzRequester}. */
|
|
585
|
+
interface AuthzRequesterOptions {
|
|
586
|
+
/** The requester's OWN tenant (UUID); the only tenant an answer is accepted for. */
|
|
587
|
+
tenantId: string;
|
|
588
|
+
/** The tenant's HKDF-derived AMQP subkey for `key_version` 2 (§8.1, provisioned out of band) — never the master key. */
|
|
589
|
+
subkey: Sensitive<Buffer>;
|
|
590
|
+
/**
|
|
591
|
+
* Bound on each {@link AuthzRequester.check}, in milliseconds. Defaults to
|
|
592
|
+
* {@link DEFAULT_AUTHZ_TIMEOUT_MS}. A value that is not finite, not
|
|
593
|
+
* positive, or above 2³¹−1 is refused with a `RangeError` when the
|
|
594
|
+
* requester is created.
|
|
595
|
+
*/
|
|
596
|
+
timeoutMs?: number;
|
|
597
|
+
/** Security-event logger. Never receives a signature value or the key. */
|
|
598
|
+
logger?: ConsumeLogger;
|
|
599
|
+
/** Clock for `issued_at`; injectable for tests. */
|
|
600
|
+
now?: () => Date;
|
|
601
|
+
}
|
|
602
|
+
/** The fields of a request, for {@link buildAuthzRequest}. */
|
|
603
|
+
interface AuthzRequestFields {
|
|
604
|
+
/** Request correlation id (UUID). */
|
|
605
|
+
correlationId: string;
|
|
606
|
+
/** The requester's tenant (UUID). */
|
|
607
|
+
tenantId: string;
|
|
608
|
+
/** Subject UUID. */
|
|
609
|
+
subjectId: string;
|
|
610
|
+
/** Action. */
|
|
611
|
+
action: string;
|
|
612
|
+
/** Resource UUID. */
|
|
613
|
+
resourceId: string;
|
|
614
|
+
/** Optional scope. */
|
|
615
|
+
scope?: string;
|
|
616
|
+
/** Fresh per-request nonce (UUID). */
|
|
617
|
+
nonce: string;
|
|
618
|
+
/** Send time. */
|
|
619
|
+
issuedAt: Date;
|
|
620
|
+
}
|
|
621
|
+
/**
|
|
622
|
+
* Serialize and sign an `AuthzRequest` exactly as the server verifies it
|
|
623
|
+
* (CONTRACT.md §8 v2): compact JSON in the fixed field order
|
|
624
|
+
* `correlation_id, tenant_id, subject_id, action, resource_id, scope?,
|
|
625
|
+
* key_version, nonce, issued_at`, then `,"hmac_signature":"<hex>"` appended as
|
|
626
|
+
* the trailing member. `JSON.stringify` escapes strings as serde_json does
|
|
627
|
+
* (`"`, `\`, the short escapes, other controls as lower-case `\u00XX`; all
|
|
628
|
+
* else raw), so the bytes match — except for a lone surrogate, which serde
|
|
629
|
+
* cannot represent and is refused.
|
|
630
|
+
*
|
|
631
|
+
* @throws TypeError on a non-UUID id or an action/scope that is not well-formed UTF-16.
|
|
632
|
+
*/
|
|
633
|
+
declare function buildAuthzRequest(subkey: Buffer, fields: AuthzRequestFields): Buffer;
|
|
634
|
+
/**
|
|
635
|
+
* Publishes `AuthzRequest` messages and verifies their answers. Many checks
|
|
636
|
+
* may be outstanding at once. Build it with {@link createAuthzRequester} or
|
|
637
|
+
* {@link connectAuthzRequester}.
|
|
638
|
+
*
|
|
639
|
+
* The AMQP authorization requester requires an AXIAM server of 1.68 or later
|
|
640
|
+
* (contract 1.68). Such a server signs every authorization response with the
|
|
641
|
+
* tenant's AMQP subkey and answers on the requester's private `reply_to`
|
|
642
|
+
* queue. A server older than 1.68 ignores `reply_to` and answers, unsigned,
|
|
643
|
+
* only on the shared `axiam.authz.response` queue, which this requester never
|
|
644
|
+
* reads: against it every check times out. There is no option to accept
|
|
645
|
+
* unsigned responses (CONTRACT.md §8, contract 1.69): no AXIAM server sends
|
|
646
|
+
* one to a reply queue, so an unsigned response can only have been published
|
|
647
|
+
* by someone else, and it is discarded and logged. During a rolling upgrade
|
|
648
|
+
* from a pre-1.68 server, use REST or gRPC authorization until every replica
|
|
649
|
+
* runs 1.68 or later.
|
|
650
|
+
*/
|
|
651
|
+
declare class AuthzRequester {
|
|
652
|
+
#private;
|
|
653
|
+
/** @internal Use {@link createAuthzRequester}. */
|
|
654
|
+
constructor(channel: AuthzRequesterChannel, options: AuthzRequesterOptions, tenantId: string, replyTo: string);
|
|
655
|
+
/** The private reply queue every request names in `reply_to`. */
|
|
656
|
+
get replyTo(): string;
|
|
657
|
+
/** Number of checks still awaiting an answer. */
|
|
658
|
+
get pending(): number;
|
|
659
|
+
/** @internal Start consuming the reply queue. */
|
|
660
|
+
start(onClose?: () => Promise<void>): Promise<void>;
|
|
661
|
+
/**
|
|
662
|
+
* Ask whether `subjectId` may perform `action` on `resourceId` and wait for
|
|
663
|
+
* the verified answer. A response that fails verification or binding is
|
|
664
|
+
* discarded and the check keeps waiting for the genuine one: a failed
|
|
665
|
+
* verification is never an allow and never completes the request.
|
|
666
|
+
*
|
|
667
|
+
* @throws AuthzRequesterClosedError once {@link close} was called or the reply queue went away.
|
|
668
|
+
* @throws NetworkError on a publish failure or when no verified answer arrives in time.
|
|
669
|
+
*/
|
|
670
|
+
check(input: AuthzCheckInput): Promise<AuthzDecision>;
|
|
671
|
+
/**
|
|
672
|
+
* Stop accepting answers: every outstanding and later check rejects with
|
|
673
|
+
* {@link AuthzRequesterClosedError}. The reply queue is exclusive and
|
|
674
|
+
* auto-delete, so the broker removes it with its consumer. Idempotent.
|
|
675
|
+
*/
|
|
676
|
+
close(): Promise<void>;
|
|
677
|
+
}
|
|
678
|
+
/**
|
|
679
|
+
* Open a private reply queue on `channel` and return a requester for
|
|
680
|
+
* `options.tenantId` (CONTRACT.md §8, contract 1.68).
|
|
681
|
+
*
|
|
682
|
+
* The reply queue is declared with an EMPTY name (the broker names it
|
|
683
|
+
* `amq.gen-…`), `exclusive`, `autoDelete` and non-durable, and consumed
|
|
684
|
+
* exclusively with manual acknowledgement. A returned name that is empty or
|
|
685
|
+
* starts with `axiam.` is refused: the server would answer such a request on
|
|
686
|
+
* the shared `axiam.authz.response` queue (§8 rule 5).
|
|
687
|
+
*
|
|
688
|
+
* The caller owns `channel` and its connection, and therefore their error
|
|
689
|
+
* handling: attach `'error'` listeners to both (an amqplib connection or
|
|
690
|
+
* channel that emits `'error'` with no listener throws an uncaught exception
|
|
691
|
+
* and ends the process), and call {@link AuthzRequester.close} when either
|
|
692
|
+
* closes, so outstanding checks are released at once instead of waiting for
|
|
693
|
+
* their timeout. {@link connectAuthzRequester} does both itself.
|
|
694
|
+
*
|
|
695
|
+
* @throws TypeError on a non-UUID tenant or an empty subkey; RangeError on an
|
|
696
|
+
* invalid `timeoutMs`; Error on a non-private reply queue.
|
|
697
|
+
*/
|
|
698
|
+
declare function createAuthzRequester(channel: AuthzRequesterChannel, options: AuthzRequesterOptions): Promise<AuthzRequester>;
|
|
699
|
+
/**
|
|
700
|
+
* Connect to the broker at `amqpUrl` (MUST be `amqps://`, CONTRACT.md §8b) and
|
|
701
|
+
* return a requester on its own channel; {@link AuthzRequester.close} also
|
|
702
|
+
* closes that connection.
|
|
703
|
+
*
|
|
704
|
+
* The connection and channel are private to the requester, so it handles
|
|
705
|
+
* their events itself: an `'error'` on either (a socket error, a missed
|
|
706
|
+
* heartbeat, a channel-level exception) is logged through `options.logger`
|
|
707
|
+
* — the error's message only, never the URL's credentials or a key (a
|
|
708
|
+
* socket error's message can name the broker host and port) — instead of
|
|
709
|
+
* escaping as an uncaught exception, and a `'close'` of either closes the requester:
|
|
710
|
+
* every outstanding check rejects at once with
|
|
711
|
+
* {@link AuthzRequesterClosedError}, and so does every later one. Reconnect
|
|
712
|
+
* by building a new requester.
|
|
713
|
+
*/
|
|
714
|
+
declare function connectAuthzRequester(amqpUrl: string, options: AuthzRequesterOptions & {
|
|
715
|
+
tls?: AmqpTlsOptions;
|
|
716
|
+
}): Promise<AuthzRequester>;
|
|
350
717
|
|
|
351
718
|
/**
|
|
352
719
|
* What the server does when an interceptor produces no usable reply
|
|
@@ -1010,5 +1377,5 @@ declare function hookableEvents(): readonly string[];
|
|
|
1010
1377
|
*/
|
|
1011
1378
|
declare function reactorHandlers(...groups: readonly ReactorHandlerMap[]): ReactorHandler;
|
|
1012
1379
|
|
|
1013
|
-
export { DEFAULT_REACTOR_MAX_IN_FLIGHT, DEFAULT_REACTOR_TIMEOUT_MS, DEFAULT_REPLAY_SKEW_MS, EVENT_REGISTRY, HMAC_SIGNED_MESSAGE_TYPES, InMemoryNonceStore, MAX_REACTOR_TIMEOUT_MS, MIN_REACTOR_TIMEOUT_MS, REACTOR_EVENTS, REACTOR_EXCHANGE, REACTOR_FRESHNESS_SKEW_MS, REACTOR_KEY_VERSION, Sensitive, abstain, allow, assertAmqpsUrl, buildAmqpConnectOptions, buildReactorReply, canonicalEventBytes, canonicalReplyBytes, chainedPatch, consume, defaultFailurePolicyFor, deny, dispatchReactorDelivery, eventSpec, hookableEvents, isFresh, mutate, patchFieldAllowed, reactorHandlers, reactorQueueName, reactorReplySignatureValid, reactorRoutingKey, reactorServe, requireStepUp, signPayload, signReactorReply, signingKeyFingerprint, specForEvent, toChronoRfc3339, verifyAndDispatch, verifyEvent, verifyPayload };
|
|
1014
|
-
export type { AmqpTlsOptions, AuditEventMessage, AuthzRequest, AuthzResponse, ConsumeChannel, ConsumeLogger, ConsumeOptions, EventRejection, FailurePolicy, HmacSignedMessageType, NonceStore, NotificationEvent, ReactorChannel, ReactorConfig, ReactorDecision, ReactorDispatchContext, ReactorEvent, ReactorEventName, ReactorEventSpec, ReactorHandler, ReactorHandlerMap, ReactorLogger, ReactorMode, ReactorReply, ReplyDecision, ReplyInput, ReplyRejection, VerifyEventResult };
|
|
1380
|
+
export { AUTHZ_REQUEST_QUEUE, AuthzRequester, AuthzRequesterClosedError, AuthzResponseVerifier, DEFAULT_AUTHZ_TIMEOUT_MS, DEFAULT_REACTOR_MAX_IN_FLIGHT, DEFAULT_REACTOR_TIMEOUT_MS, DEFAULT_REPLAY_SKEW_MS, EVENT_REGISTRY, HMAC_SIGNED_MESSAGE_TYPES, InMemoryNonceStore, MAX_REACTOR_TIMEOUT_MS, MIN_REACTOR_TIMEOUT_MS, REACTOR_EVENTS, REACTOR_EXCHANGE, REACTOR_FRESHNESS_SKEW_MS, REACTOR_KEY_VERSION, Sensitive, abstain, allow, assertAmqpsUrl, buildAmqpConnectOptions, buildAuthzRequest, buildReactorReply, canonicalEventBytes, canonicalReplyBytes, chainedPatch, connectAuthzRequester, consume, createAuthzRequester, decodeUtf8Strict, defaultFailurePolicyFor, deny, dispatchReactorDelivery, eventSpec, hookableEvents, isFresh, mutate, patchFieldAllowed, reactorHandlers, reactorQueueName, reactorReplySignatureValid, reactorRoutingKey, reactorServe, requireStepUp, signPayload, signReactorReply, signingKeyFingerprint, specForEvent, toChronoRfc3339, verifyAndDispatch, verifyEvent, verifyPayload };
|
|
1381
|
+
export type { AmqpTlsOptions, AuditEventMessage, AuthzCheckInput, AuthzDecision, AuthzRequest, AuthzRequestFields, AuthzRequesterChannel, AuthzRequesterOptions, AuthzResponse, AuthzResponseDelivery, AuthzResponseRejection, AuthzResponseVerdict, AuthzResponseVerifierOptions, ConsumeChannel, ConsumeLogger, ConsumeOptions, EventDiscardReason, EventRejection, EventType, FailurePolicy, HmacSignedMessageType, NonceStore, NotificationEvent, OutstandingAuthzRequest, ReactorChannel, ReactorConfig, ReactorDecision, ReactorDispatchContext, ReactorEvent, ReactorEventName, ReactorEventSpec, ReactorHandler, ReactorHandlerMap, ReactorLogger, ReactorMode, ReactorReply, ReplyDecision, ReplyInput, ReplyRejection, SettleChannel, VerifiedAuthzResponse, VerifyEventResult };
|