@astram/guard 0.35.2 → 0.36.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/dist/config/app-config.d.ts +16 -4
- package/dist/config/app-config.d.ts.map +1 -1
- package/dist/config/app-config.js +47 -5
- package/dist/storage/object-store-boot-check.d.ts +6 -3
- package/dist/storage/object-store-boot-check.d.ts.map +1 -1
- package/dist/storage/object-store-boot-check.js +37 -4
- package/dist/storage/object-store-probe-error.d.ts +42 -0
- package/dist/storage/object-store-probe-error.d.ts.map +1 -0
- package/dist/storage/object-store-probe-error.js +82 -0
- package/dist/storage/s3-object-store.d.ts +37 -2
- package/dist/storage/s3-object-store.d.ts.map +1 -1
- package/dist/storage/s3-object-store.js +189 -58
- package/package.json +3 -3
|
@@ -408,8 +408,17 @@ export interface ObjectStorageConfig {
|
|
|
408
408
|
readonly region: string;
|
|
409
409
|
readonly accessKeyId: string;
|
|
410
410
|
readonly secretAccessKey: string;
|
|
411
|
-
/**
|
|
412
|
-
|
|
411
|
+
/**
|
|
412
|
+
* Server-side encryption mode (`OBJECT_STORAGE_SSE`): SSE-S3 `AES256` (default) or `SSE-C`, a
|
|
413
|
+
* customer-provided key sent on every object request (object-storage-sse-c SPEC §5 A).
|
|
414
|
+
*/
|
|
415
|
+
readonly sse: 'AES256' | 'SSE-C';
|
|
416
|
+
/**
|
|
417
|
+
* The 32-byte SSE-C key (`OBJECT_STORAGE_SSE_C_KEY`), present only with `sse: 'SSE-C'`. The
|
|
418
|
+
* loader defines it NON-ENUMERABLE: it is absent from `JSON.stringify`, `Object.keys`, spread
|
|
419
|
+
* copies and default `util.inspect` output. Never log it.
|
|
420
|
+
*/
|
|
421
|
+
readonly sseCustomerKey?: Uint8Array;
|
|
413
422
|
/** `OBJECT_STORAGE_MAX_BYTES` (default 10 MiB), at most `FILE_MAX_BYTES_CEILING` (50 MiB). */
|
|
414
423
|
readonly maxBytes: number;
|
|
415
424
|
/**
|
|
@@ -439,11 +448,14 @@ export declare const DEFAULT_OBJECT_STORAGE_MAX_BYTES: number;
|
|
|
439
448
|
* - endpoint or either credential missing/blank;
|
|
440
449
|
* - endpoint not a URL, carrying userinfo, or not `https:` outside development/test unless the
|
|
441
450
|
* host is loopback (the raw `NODE_ENV`; unset is not dev);
|
|
442
|
-
* - a credential still holding an unresolved `secret-ref:` value;
|
|
451
|
+
* - a credential (or the SSE-C key) still holding an unresolved `secret-ref:` value;
|
|
443
452
|
* - outside development/test, a credential not resolved from a `secret-ref:` per
|
|
444
453
|
* `options.resolvedFromSecretRef` (`ShieldModule.forRoot({ storage: 'env' })` passes
|
|
445
454
|
* `wasResolvedFromSecretRef`); without the option every credential there is refused;
|
|
446
|
-
* - `OBJECT_STORAGE_SSE` other than `AES256`;
|
|
455
|
+
* - `OBJECT_STORAGE_SSE` other than `AES256` / `SSE-C`; with `SSE-C`: a non-`https:` endpoint (any
|
|
456
|
+
* environment) or `OBJECT_STORAGE_SSE_C_KEY` missing, not standard base64 of 32 bytes, or (outside
|
|
457
|
+
* development/test) not resolved from a `secret-ref:`; without `SSE-C`: that key set at all
|
|
458
|
+
* (object-storage-sse-c SPEC §5 A);
|
|
447
459
|
* - `OBJECT_STORAGE_MAX_BYTES` not a plain positive decimal without leading zeros, or above the
|
|
448
460
|
* 50 MiB ceiling.
|
|
449
461
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-config.d.ts","sourceRoot":"","sources":["../../src/config/app-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAWtE,MAAM,WAAW,SAAS;IACxB,yCAAyC;IACzC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,oEAAoE;IACpE,QAAQ,CAAC,WAAW,EAAE,aAAa,GAAG,MAAM,GAAG,YAAY,CAAC;IAC5D,wEAAwE;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B,CAAC,EAAE,OAAO,CAAC;CACrC;AAED,mDAAmD;AACnD,MAAM,WAAW,8BAA8B;IAC7C;;;;;;OAMG;IACH,QAAQ,CAAC,qBAAqB,CAAC,EAAE,CAC/B,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,KAC9C,OAAO,CAAC;CACd;AAED,wFAAwF;AACxF,eAAO,MAAM,gCAAgC,QAAmB,CAAC;AAsBjE;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,uBAAuB,CACrC,GAAG,GAAE,MAAM,CAAC,UAAwB,EACpC,OAAO,GAAE,8BAAmC,GAC3C,mBAAmB,GAAG,SAAS,CA+FjC;AA0BD,mFAAmF;AACnF,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,QAAQ,CAAC,oBAAoB,EAAE,MAAM,CAAC;IACtC,+EAA+E;IAC/E,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;IACpC,0EAA0E;IAC1E,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAC;IACrC,qEAAqE;IACrE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,qDAAqD;IACrD,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;IAC/B,0EAA0E;IAC1E,QAAQ,CAAC,sBAAsB,EAAE,OAAO,CAAC;IACzC;;;OAGG;IACH,QAAQ,CAAC,gBAAgB,EAAE,OAAO,CAAC;CACpC;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,gBAAgB,GAAG,oBAAoB,CA6B9E"}
|
|
@@ -440,6 +440,20 @@ async function loadAppConfigAsync(provider, env = process.env) {
|
|
|
440
440
|
}
|
|
441
441
|
/** Default per-file cap when `OBJECT_STORAGE_MAX_BYTES` is unset (10 MiB, SPEC §10). */
|
|
442
442
|
exports.DEFAULT_OBJECT_STORAGE_MAX_BYTES = 10 * 1024 * 1024;
|
|
443
|
+
/** Standard base64 of 32 bytes: 43 characters, then at most the one `=` of padding. */
|
|
444
|
+
const SSE_C_KEY_BASE64 = /^[A-Za-z0-9+/]{43}=?$/;
|
|
445
|
+
/** Decode an SSE-C key, or `undefined` unless it is canonical standard base64 of 32 bytes. */
|
|
446
|
+
function decodeSseCustomerKey(value) {
|
|
447
|
+
if (!SSE_C_KEY_BASE64.test(value))
|
|
448
|
+
return undefined;
|
|
449
|
+
const bytes = Buffer.from(value, 'base64');
|
|
450
|
+
// Round trip: refuses non-canonical trailing bits (a second spelling of the same key).
|
|
451
|
+
if (bytes.length !== 32 ||
|
|
452
|
+
bytes.toString('base64').replace(/=+$/, '') !== value.replace(/=$/, '')) {
|
|
453
|
+
return undefined;
|
|
454
|
+
}
|
|
455
|
+
return new Uint8Array(bytes);
|
|
456
|
+
}
|
|
443
457
|
/**
|
|
444
458
|
* Read the object-storage config (FILE_STORAGE SPEC §5 F). Returns `undefined` when
|
|
445
459
|
* `OBJECT_STORAGE_BUCKET` is unset or blank (storage off). Otherwise every bad value is a boot
|
|
@@ -447,11 +461,14 @@ exports.DEFAULT_OBJECT_STORAGE_MAX_BYTES = 10 * 1024 * 1024;
|
|
|
447
461
|
* - endpoint or either credential missing/blank;
|
|
448
462
|
* - endpoint not a URL, carrying userinfo, or not `https:` outside development/test unless the
|
|
449
463
|
* host is loopback (the raw `NODE_ENV`; unset is not dev);
|
|
450
|
-
* - a credential still holding an unresolved `secret-ref:` value;
|
|
464
|
+
* - a credential (or the SSE-C key) still holding an unresolved `secret-ref:` value;
|
|
451
465
|
* - outside development/test, a credential not resolved from a `secret-ref:` per
|
|
452
466
|
* `options.resolvedFromSecretRef` (`ShieldModule.forRoot({ storage: 'env' })` passes
|
|
453
467
|
* `wasResolvedFromSecretRef`); without the option every credential there is refused;
|
|
454
|
-
* - `OBJECT_STORAGE_SSE` other than `AES256`;
|
|
468
|
+
* - `OBJECT_STORAGE_SSE` other than `AES256` / `SSE-C`; with `SSE-C`: a non-`https:` endpoint (any
|
|
469
|
+
* environment) or `OBJECT_STORAGE_SSE_C_KEY` missing, not standard base64 of 32 bytes, or (outside
|
|
470
|
+
* development/test) not resolved from a `secret-ref:`; without `SSE-C`: that key set at all
|
|
471
|
+
* (object-storage-sse-c SPEC §5 A);
|
|
455
472
|
* - `OBJECT_STORAGE_MAX_BYTES` not a plain positive decimal without leading zeros, or above the
|
|
456
473
|
* 50 MiB ceiling.
|
|
457
474
|
*/
|
|
@@ -496,10 +513,25 @@ function loadObjectStorageConfig(env = process.env, options = {}) {
|
|
|
496
513
|
const accessKeyId = credential('OBJECT_STORAGE_ACCESS_KEY_ID');
|
|
497
514
|
const secretAccessKey = credential('OBJECT_STORAGE_SECRET_ACCESS_KEY');
|
|
498
515
|
const sse = env.OBJECT_STORAGE_SSE?.trim() || 'AES256';
|
|
499
|
-
if (sse !== 'AES256') {
|
|
500
|
-
throw new Error("OBJECT_STORAGE_SSE must be 'AES256' (SSE-S3)
|
|
516
|
+
if (sse !== 'AES256' && sse !== 'SSE-C') {
|
|
517
|
+
throw new Error("OBJECT_STORAGE_SSE must be 'AES256' (SSE-S3) or 'SSE-C' (customer-provided key)");
|
|
501
518
|
}
|
|
502
|
-
|
|
519
|
+
let sseCustomerKey;
|
|
520
|
+
if (sse === 'SSE-C') {
|
|
521
|
+
if (url.protocol !== 'https:') {
|
|
522
|
+
// Every environment, loopback included: the key travels in a request header.
|
|
523
|
+
throw new Error('OBJECT_STORAGE_SSE=SSE-C requires an https: OBJECT_STORAGE_ENDPOINT ' +
|
|
524
|
+
'(the key is sent in a request header)');
|
|
525
|
+
}
|
|
526
|
+
sseCustomerKey = decodeSseCustomerKey(credential('OBJECT_STORAGE_SSE_C_KEY'));
|
|
527
|
+
if (sseCustomerKey === undefined) {
|
|
528
|
+
throw new Error('OBJECT_STORAGE_SSE_C_KEY must be base64 of exactly 32 bytes (a 256-bit key)');
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
else if (env.OBJECT_STORAGE_SSE_C_KEY?.trim()) {
|
|
532
|
+
throw new Error("OBJECT_STORAGE_SSE_C_KEY is set but OBJECT_STORAGE_SSE is not 'SSE-C'");
|
|
533
|
+
}
|
|
534
|
+
const config = {
|
|
503
535
|
endpoint,
|
|
504
536
|
bucket,
|
|
505
537
|
region: env.OBJECT_STORAGE_REGION?.trim() || 'us-east-1',
|
|
@@ -509,6 +541,16 @@ function loadObjectStorageConfig(env = process.env, options = {}) {
|
|
|
509
541
|
maxBytes: parseStorageMaxBytes(env.OBJECT_STORAGE_MAX_BYTES),
|
|
510
542
|
maxBytesExplicit: Boolean(env.OBJECT_STORAGE_MAX_BYTES?.trim()),
|
|
511
543
|
};
|
|
544
|
+
if (sseCustomerKey !== undefined) {
|
|
545
|
+
// Non-enumerable: never serialised, spread or printed with the rest of the config.
|
|
546
|
+
Object.defineProperty(config, 'sseCustomerKey', {
|
|
547
|
+
value: sseCustomerKey,
|
|
548
|
+
enumerable: false,
|
|
549
|
+
writable: false,
|
|
550
|
+
configurable: false,
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
return config;
|
|
512
554
|
}
|
|
513
555
|
function requireStorageVar(env, name) {
|
|
514
556
|
const value = env[name]?.trim();
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Boot check for the bound `ObjectStore` (FILE_STORAGE SPEC §5 H, §12). Registered by
|
|
3
3
|
* `ShieldModule` only when a `storage` option is given; pings once at bootstrap and aborts the
|
|
4
|
-
* boot (Shield #1) when the bucket is unreachable, not writable,
|
|
4
|
+
* boot (Shield #1) when the bucket is unreachable, not writable, refuses the encryption headers,
|
|
5
|
+
* or (SSE-C) the key does not open the key canary.
|
|
5
6
|
*
|
|
6
|
-
* The message names the bucket (`OBJECT_STORAGE_BUCKET`)
|
|
7
|
-
*
|
|
7
|
+
* The message names the bucket (`OBJECT_STORAGE_BUCKET`), the failing probe step and, when the
|
|
8
|
+
* store reports them, the provider's error NAME and HTTP status (object-storage-sse-c SPEC §5 F),
|
|
9
|
+
* plus the variables to check. Never a credential, the key, the endpoint or the underlying error
|
|
10
|
+
* text (Shield #10).
|
|
8
11
|
*/
|
|
9
12
|
import { type OnApplicationBootstrap } from '@nestjs/common';
|
|
10
13
|
import type { ObjectStore } from '@astram/core';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object-store-boot-check.d.ts","sourceRoot":"","sources":["../../src/storage/object-store-boot-check.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"object-store-boot-check.d.ts","sourceRoot":"","sources":["../../src/storage/object-store-boot-check.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAgC,KAAK,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAC3F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAahD,qBACa,oBAAqB,YAAW,sBAAsB;IAEtB,OAAO,CAAC,QAAQ,CAAC,KAAK;gBAAL,KAAK,EAAE,WAAW,GAAG,IAAI;IAG/E,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC;CAe9C"}
|
|
@@ -16,13 +16,22 @@ exports.ObjectStoreBootCheck = void 0;
|
|
|
16
16
|
/**
|
|
17
17
|
* Boot check for the bound `ObjectStore` (FILE_STORAGE SPEC §5 H, §12). Registered by
|
|
18
18
|
* `ShieldModule` only when a `storage` option is given; pings once at bootstrap and aborts the
|
|
19
|
-
* boot (Shield #1) when the bucket is unreachable, not writable,
|
|
19
|
+
* boot (Shield #1) when the bucket is unreachable, not writable, refuses the encryption headers,
|
|
20
|
+
* or (SSE-C) the key does not open the key canary.
|
|
20
21
|
*
|
|
21
|
-
* The message names the bucket (`OBJECT_STORAGE_BUCKET`)
|
|
22
|
-
*
|
|
22
|
+
* The message names the bucket (`OBJECT_STORAGE_BUCKET`), the failing probe step and, when the
|
|
23
|
+
* store reports them, the provider's error NAME and HTTP status (object-storage-sse-c SPEC §5 F),
|
|
24
|
+
* plus the variables to check. Never a credential, the key, the endpoint or the underlying error
|
|
25
|
+
* text (Shield #10).
|
|
23
26
|
*/
|
|
24
27
|
const common_1 = require("@nestjs/common");
|
|
25
28
|
const shield_tokens_js_1 = require("../module/shield-tokens.js");
|
|
29
|
+
const object_store_probe_error_js_1 = require("./object-store-probe-error.js");
|
|
30
|
+
const GENERIC_HINT = 'Check OBJECT_STORAGE_ENDPOINT, OBJECT_STORAGE_ACCESS_KEY_ID, OBJECT_STORAGE_SECRET_ACCESS_KEY ' +
|
|
31
|
+
'and the bucket policy.';
|
|
32
|
+
const KEY_MISMATCH_HINT = 'OBJECT_STORAGE_SSE_C_KEY does not open the key canary _shield/sse-c-canary: it is not the key ' +
|
|
33
|
+
'this bucket was first used with, or the app key lacks s3:ListBucket on the bucket (SSE-C needs ' +
|
|
34
|
+
'ListBucket plus GetObject, PutObject and DeleteObject).';
|
|
26
35
|
let ObjectStoreBootCheck = class ObjectStoreBootCheck {
|
|
27
36
|
store;
|
|
28
37
|
constructor(store) {
|
|
@@ -34,9 +43,11 @@ let ObjectStoreBootCheck = class ObjectStoreBootCheck {
|
|
|
34
43
|
try {
|
|
35
44
|
await this.store.ping();
|
|
36
45
|
}
|
|
37
|
-
catch {
|
|
46
|
+
catch (e) {
|
|
38
47
|
const bucket = process.env.OBJECT_STORAGE_BUCKET?.trim();
|
|
39
48
|
const named = bucket ? `bucket '${bucket}' (OBJECT_STORAGE_BUCKET)` : 'the configured bucket';
|
|
49
|
+
if (e instanceof object_store_probe_error_js_1.ObjectStoreProbeError)
|
|
50
|
+
throw new Error(probeMessage(e, named));
|
|
40
51
|
throw new Error(`Object storage boot check failed: ${named} is not reachable, not writable or refused ` +
|
|
41
52
|
'server-side encryption with the configured key. Check OBJECT_STORAGE_ENDPOINT, ' +
|
|
42
53
|
'OBJECT_STORAGE_ACCESS_KEY_ID, OBJECT_STORAGE_SECRET_ACCESS_KEY and the bucket policy.');
|
|
@@ -50,3 +61,25 @@ exports.ObjectStoreBootCheck = ObjectStoreBootCheck = __decorate([
|
|
|
50
61
|
__param(0, (0, common_1.Inject)(shield_tokens_js_1.SHIELD_OBJECT_STORE)),
|
|
51
62
|
__metadata("design:paramtypes", [Object])
|
|
52
63
|
], ObjectStoreBootCheck);
|
|
64
|
+
/** The SSE mode as a printable value name, only when it is one of the two known modes. */
|
|
65
|
+
function sseMode() {
|
|
66
|
+
const raw = process.env.OBJECT_STORAGE_SSE?.trim() || 'AES256';
|
|
67
|
+
return raw === 'AES256' || raw === 'SSE-C' ? raw : undefined;
|
|
68
|
+
}
|
|
69
|
+
function probeMessage(e, named) {
|
|
70
|
+
const detail = [e.errorName, e.httpStatus].filter((v) => v !== undefined).join(' ');
|
|
71
|
+
const mode = sseMode();
|
|
72
|
+
const where = `${named}${mode ? ` (OBJECT_STORAGE_SSE=${mode})` : ''}`;
|
|
73
|
+
let hint;
|
|
74
|
+
if (e.op === 'canary' && e.keyMismatch === true)
|
|
75
|
+
hint = KEY_MISMATCH_HINT;
|
|
76
|
+
else if (mode === 'SSE-C') {
|
|
77
|
+
hint =
|
|
78
|
+
'Check OBJECT_STORAGE_ENDPOINT, OBJECT_STORAGE_ACCESS_KEY_ID, ' +
|
|
79
|
+
'OBJECT_STORAGE_SECRET_ACCESS_KEY, OBJECT_STORAGE_SSE, OBJECT_STORAGE_SSE_C_KEY and the ' +
|
|
80
|
+
'bucket policy.';
|
|
81
|
+
}
|
|
82
|
+
else
|
|
83
|
+
hint = GENERIC_HINT;
|
|
84
|
+
return `Object storage boot check failed at ${e.op}${detail ? ` (${detail})` : ''}: ${where}. ${hint}`;
|
|
85
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The storage boot probe's failure (object-storage-sse-c SPEC §5 D): which probe step failed,
|
|
3
|
+
* plus the provider's error NAME and HTTP status when they are safe to print, so an operator can
|
|
4
|
+
* read `failed at put (InvalidArgument 400)` without a separate probe.
|
|
5
|
+
*
|
|
6
|
+
* It extends core's `ObjectStoreUnavailableError` (same fixed message, same `name`, no `cause`), so
|
|
7
|
+
* every existing `instanceof ObjectStoreUnavailableError` check still matches. Only `e.name` and
|
|
8
|
+
* `e.$metadata.httpStatusCode` of an SDK error are ever read: never its message, `Code`, request
|
|
9
|
+
* id, response, endpoint or cause (Shield #10).
|
|
10
|
+
*
|
|
11
|
+
* Kept apart from `s3-object-store.ts` so `ObjectStoreBootCheck` can import it without loading the
|
|
12
|
+
* store module (whose SDK load is lazy by design).
|
|
13
|
+
*/
|
|
14
|
+
import { ObjectStoreUnavailableError } from '@astram/core';
|
|
15
|
+
/** The probe steps (SPEC §10), in the order `S3ObjectStore.ping` runs them. */
|
|
16
|
+
export type ObjectStoreProbeOp = 'head-bucket' | 'put' | 'get' | 'verify' | 'canary';
|
|
17
|
+
export interface ObjectStoreProbeFailure {
|
|
18
|
+
readonly op: ObjectStoreProbeOp;
|
|
19
|
+
readonly errorName?: string;
|
|
20
|
+
readonly httpStatus?: number;
|
|
21
|
+
/** Set only by the SSE-C key canary when the key could not open it (SPEC §5 E). */
|
|
22
|
+
readonly keyMismatch?: true;
|
|
23
|
+
}
|
|
24
|
+
export declare class ObjectStoreProbeError extends ObjectStoreUnavailableError {
|
|
25
|
+
readonly op: ObjectStoreProbeOp;
|
|
26
|
+
readonly errorName?: string;
|
|
27
|
+
readonly httpStatus?: number;
|
|
28
|
+
readonly keyMismatch?: true;
|
|
29
|
+
constructor(failure: ObjectStoreProbeFailure);
|
|
30
|
+
}
|
|
31
|
+
/** The SDK error's name, when it is a plain identifier (else `undefined`). Never throws. */
|
|
32
|
+
export declare function safeErrorName(e: unknown): string | undefined;
|
|
33
|
+
/** The SDK error's HTTP status, when it is an integer 100-599 (else `undefined`). Never throws. */
|
|
34
|
+
export declare function safeHttpStatus(e: unknown): number | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* The probe failure for step `op` caused by `e`. An `ObjectStoreProbeError` passes through
|
|
37
|
+
* unchanged (an inner step already named itself).
|
|
38
|
+
*/
|
|
39
|
+
export declare function probeFailure(op: ObjectStoreProbeOp, e: unknown, opts?: {
|
|
40
|
+
readonly keyMismatch?: boolean;
|
|
41
|
+
}): ObjectStoreProbeError;
|
|
42
|
+
//# sourceMappingURL=object-store-probe-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object-store-probe-error.d.ts","sourceRoot":"","sources":["../../src/storage/object-store-probe-error.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAE3D,+EAA+E;AAC/E,MAAM,MAAM,kBAAkB,GAAG,aAAa,GAAG,KAAK,GAAG,KAAK,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAErF,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,EAAE,EAAE,kBAAkB,CAAC;IAChC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,mFAAmF;IACnF,QAAQ,CAAC,WAAW,CAAC,EAAE,IAAI,CAAC;CAC7B;AAKD,qBAAa,qBAAsB,SAAQ,2BAA2B;IACpE,QAAQ,CAAC,EAAE,EAAE,kBAAkB,CAAC;IAEhC,SAAiB,SAAS,CAAC,EAAE,MAAM,CAAC;IACpC,SAAiB,UAAU,CAAC,EAAE,MAAM,CAAC;IACrC,SAAiB,WAAW,CAAC,EAAE,IAAI,CAAC;gBAExB,OAAO,EAAE,uBAAuB;CAQ7C;AAED,4FAA4F;AAC5F,wBAAgB,aAAa,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAQ5D;AAED,mGAAmG;AACnG,wBAAgB,cAAc,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAY7D;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAC1B,EAAE,EAAE,kBAAkB,EACtB,CAAC,EAAE,OAAO,EACV,IAAI,GAAE;IAAE,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAA;CAAO,GAC5C,qBAAqB,CAUvB"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ObjectStoreProbeError = void 0;
|
|
4
|
+
exports.safeErrorName = safeErrorName;
|
|
5
|
+
exports.safeHttpStatus = safeHttpStatus;
|
|
6
|
+
exports.probeFailure = probeFailure;
|
|
7
|
+
/**
|
|
8
|
+
* The storage boot probe's failure (object-storage-sse-c SPEC §5 D): which probe step failed,
|
|
9
|
+
* plus the provider's error NAME and HTTP status when they are safe to print, so an operator can
|
|
10
|
+
* read `failed at put (InvalidArgument 400)` without a separate probe.
|
|
11
|
+
*
|
|
12
|
+
* It extends core's `ObjectStoreUnavailableError` (same fixed message, same `name`, no `cause`), so
|
|
13
|
+
* every existing `instanceof ObjectStoreUnavailableError` check still matches. Only `e.name` and
|
|
14
|
+
* `e.$metadata.httpStatusCode` of an SDK error are ever read: never its message, `Code`, request
|
|
15
|
+
* id, response, endpoint or cause (Shield #10).
|
|
16
|
+
*
|
|
17
|
+
* Kept apart from `s3-object-store.ts` so `ObjectStoreBootCheck` can import it without loading the
|
|
18
|
+
* store module (whose SDK load is lazy by design).
|
|
19
|
+
*/
|
|
20
|
+
const core_1 = require("@astram/core");
|
|
21
|
+
/** A provider error name we print: an identifier, nothing that could carry a URL, key or text. */
|
|
22
|
+
const SAFE_ERROR_NAME = /^[A-Za-z][A-Za-z0-9]{0,63}$/;
|
|
23
|
+
class ObjectStoreProbeError extends core_1.ObjectStoreUnavailableError {
|
|
24
|
+
op;
|
|
25
|
+
constructor(failure) {
|
|
26
|
+
super();
|
|
27
|
+
this.op = failure.op;
|
|
28
|
+
// Own properties only when present, so a serialised error carries nothing undefined.
|
|
29
|
+
if (failure.errorName !== undefined)
|
|
30
|
+
this.errorName = failure.errorName;
|
|
31
|
+
if (failure.httpStatus !== undefined)
|
|
32
|
+
this.httpStatus = failure.httpStatus;
|
|
33
|
+
if (failure.keyMismatch === true)
|
|
34
|
+
this.keyMismatch = true;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.ObjectStoreProbeError = ObjectStoreProbeError;
|
|
38
|
+
/** The SDK error's name, when it is a plain identifier (else `undefined`). Never throws. */
|
|
39
|
+
function safeErrorName(e) {
|
|
40
|
+
try {
|
|
41
|
+
if (typeof e !== 'object' || e === null)
|
|
42
|
+
return undefined;
|
|
43
|
+
const name = e.name;
|
|
44
|
+
return typeof name === 'string' && SAFE_ERROR_NAME.test(name) ? name : undefined;
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/** The SDK error's HTTP status, when it is an integer 100-599 (else `undefined`). Never throws. */
|
|
51
|
+
function safeHttpStatus(e) {
|
|
52
|
+
try {
|
|
53
|
+
if (typeof e !== 'object' || e === null)
|
|
54
|
+
return undefined;
|
|
55
|
+
const meta = e.$metadata;
|
|
56
|
+
if (typeof meta !== 'object' || meta === null)
|
|
57
|
+
return undefined;
|
|
58
|
+
const status = meta.httpStatusCode;
|
|
59
|
+
return typeof status === 'number' && Number.isInteger(status) && status >= 100 && status <= 599
|
|
60
|
+
? status
|
|
61
|
+
: undefined;
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The probe failure for step `op` caused by `e`. An `ObjectStoreProbeError` passes through
|
|
69
|
+
* unchanged (an inner step already named itself).
|
|
70
|
+
*/
|
|
71
|
+
function probeFailure(op, e, opts = {}) {
|
|
72
|
+
if (e instanceof ObjectStoreProbeError)
|
|
73
|
+
return e;
|
|
74
|
+
const errorName = safeErrorName(e);
|
|
75
|
+
const httpStatus = safeHttpStatus(e);
|
|
76
|
+
return new ObjectStoreProbeError({
|
|
77
|
+
op,
|
|
78
|
+
...(errorName !== undefined ? { errorName } : {}),
|
|
79
|
+
...(httpStatus !== undefined ? { httpStatus } : {}),
|
|
80
|
+
...(opts.keyMismatch === true ? { keyMismatch: true } : {}),
|
|
81
|
+
});
|
|
82
|
+
}
|
|
@@ -3,8 +3,9 @@ import type { ObjectStorageConfig } from '../config/app-config.js';
|
|
|
3
3
|
/**
|
|
4
4
|
* The connection fields `S3ObjectStore` needs (the {@link ObjectStorageConfig} result).
|
|
5
5
|
* `maxBytes` caps what `get` will buffer (default and maximum: `FILE_MAX_BYTES_CEILING`).
|
|
6
|
+
* `sseCustomerKey` is required with `sse: 'SSE-C'` (exactly 32 bytes) and refused otherwise.
|
|
6
7
|
*/
|
|
7
|
-
export type S3ObjectStoreConfig = Pick<ObjectStorageConfig, 'endpoint' | 'bucket' | 'region' | 'accessKeyId' | 'secretAccessKey' | 'sse'> & {
|
|
8
|
+
export type S3ObjectStoreConfig = Pick<ObjectStorageConfig, 'endpoint' | 'bucket' | 'region' | 'accessKeyId' | 'secretAccessKey' | 'sse' | 'sseCustomerKey'> & {
|
|
8
9
|
readonly maxBytes?: number;
|
|
9
10
|
};
|
|
10
11
|
export interface S3ObjectStoreOptions {
|
|
@@ -18,7 +19,10 @@ export interface S3ObjectStoreOptions {
|
|
|
18
19
|
*/
|
|
19
20
|
readonly noOverwrite?: 'if-none-match' | 'head-first' | 'none';
|
|
20
21
|
}
|
|
22
|
+
/** The SSE-C key canary (SPEC §5 E, §10): outside `_probe/`, never deleted or overwritten. */
|
|
23
|
+
export declare const SSE_C_CANARY_KEY = "_shield/sse-c-canary";
|
|
21
24
|
export declare class S3ObjectStore implements ObjectStore {
|
|
25
|
+
#private;
|
|
22
26
|
private readonly config;
|
|
23
27
|
private readonly bucket;
|
|
24
28
|
private readonly sse;
|
|
@@ -28,17 +32,48 @@ export declare class S3ObjectStore implements ObjectStore {
|
|
|
28
32
|
constructor(config: S3ObjectStoreConfig, options?: S3ObjectStoreOptions);
|
|
29
33
|
/** The SDK and the client, built on first use. */
|
|
30
34
|
private connect;
|
|
35
|
+
/**
|
|
36
|
+
* SSE-C fields for put/get/head. The key goes as padded standard base64 of its 32 bytes: the
|
|
37
|
+
* SDK's ssec middleware (`@aws-sdk/middleware-sdk-s3`) keeps a valid base64 32-byte key as is and
|
|
38
|
+
* derives `SSECustomerKeyMD5` from the decoded bytes.
|
|
39
|
+
*/
|
|
40
|
+
private sseCustomer;
|
|
31
41
|
put(key: string, bytes: Uint8Array, meta: ObjectPutMeta): Promise<void>;
|
|
42
|
+
/** One PutObject; rethrows the raw SDK error (callers map it). */
|
|
43
|
+
private sendPut;
|
|
32
44
|
get(key: string): Promise<StoredObject>;
|
|
45
|
+
/**
|
|
46
|
+
* One GetObject under the size cap; rethrows the raw SDK error (callers map it), or a fixed
|
|
47
|
+
* `ObjectStoreUnavailableError` for a missing body or an unknown / over-cap length.
|
|
48
|
+
*/
|
|
49
|
+
private fetchObject;
|
|
33
50
|
head(key: string): Promise<StoredObjectHead | null>;
|
|
34
51
|
delete(key: string): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* The boot probe (SPEC §5 B, E): head-bucket, put, get, verify, then (SSE-C) the key canary.
|
|
54
|
+
* Throws an {@link ObjectStoreProbeError} naming the failing step.
|
|
55
|
+
*/
|
|
35
56
|
ping(): Promise<void>;
|
|
36
57
|
/**
|
|
37
58
|
* A write-only boot check (ai-debug-trace SPEC §5 A, §8): `HeadBucket`, then one small probe
|
|
38
59
|
* object under `_probe/` that is NOT read back or deleted (the trace credential is put-only;
|
|
39
|
-
* the bucket's lifecycle rule expires the probe).
|
|
60
|
+
* the bucket's lifecycle rule expires the probe). Throws an {@link ObjectStoreProbeError}.
|
|
40
61
|
*/
|
|
41
62
|
pingWriteOnly(): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* `HeadBucket` as the `head-bucket` probe step. An SDK load failure is NOT this step: it
|
|
65
|
+
* propagates as is, so the boot check prints its generic message rather than blaming the bucket.
|
|
66
|
+
*/
|
|
67
|
+
private probeBucket;
|
|
68
|
+
/** The probe put under this store's overwrite mode, as the `put` probe step. */
|
|
69
|
+
private probePut;
|
|
70
|
+
/**
|
|
71
|
+
* The SSE-C key canary (SPEC §5 E): read `_shield/sse-c-canary` with the configured key. Missing ⇒
|
|
72
|
+
* create it (always `If-None-Match: *`; a 412 means another worker won, so read again). A 400 or
|
|
73
|
+
* 403, or other bytes ⇒ the key does not open it (`keyMismatch`). Never deleted or overwritten.
|
|
74
|
+
*/
|
|
75
|
+
private checkKeyCanary;
|
|
76
|
+
private readCanary;
|
|
42
77
|
/**
|
|
43
78
|
* Whether the bucket has a lifecycle (expiry) rule: `'rules'`, `'none'` (the backend says no
|
|
44
79
|
* configuration exists) or `'unknown'` (not readable with this credential, or an error). Never
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"s3-object-store.d.ts","sourceRoot":"","sources":["../../src/storage/s3-object-store.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"s3-object-store.d.ts","sourceRoot":"","sources":["../../src/storage/s3-object-store.ts"],"names":[],"mappings":"AA2BA,OAAO,EAIL,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACtB,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAkBnE;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,GAAG,IAAI,CACpC,mBAAmB,EACnB,UAAU,GAAG,QAAQ,GAAG,QAAQ,GAAG,aAAa,GAAG,iBAAiB,GAAG,KAAK,GAAG,gBAAgB,CAChG,GAAG;IAAE,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAEnC,MAAM,WAAW,oBAAoB;IACnC;;;;;;;OAOG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,eAAe,GAAG,YAAY,GAAG,MAAM,CAAC;CAChE;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
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.S3ObjectStore = void 0;
|
|
36
|
+
exports.S3ObjectStore = exports.SSE_C_CANARY_KEY = void 0;
|
|
37
37
|
/**
|
|
38
38
|
* `ObjectStore` over the S3 API (FILE_STORAGE SPEC §5 E) for MinIO and S3-compatible hosts.
|
|
39
39
|
*
|
|
40
40
|
* - Path-style addressing (`forcePathStyle`), region and credentials from {@link ObjectStorageConfig}.
|
|
41
|
-
* -
|
|
42
|
-
* (`
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
41
|
+
* - Server-side encryption (object-storage-sse-c SPEC §5 B): `sse: 'AES256'` sends SSE-S3
|
|
42
|
+
* (`ServerSideEncryption: 'AES256'`) on every put. `sse: 'SSE-C'` sends the customer-provided
|
|
43
|
+
* 256-bit key (`SSECustomerAlgorithm: 'AES256'` + `SSECustomerKey`; the SDK adds the key MD5) on
|
|
44
|
+
* every put, get and head, and no `ServerSideEncryption`. The key is held in a private field,
|
|
45
|
+
* copied from the caller, never logged and never in an error. SSE-C needs an `https:` endpoint.
|
|
46
|
+
* - `put`: no overwrite (`IfNoneMatch: '*'`), content type, and the sha256 both as
|
|
47
|
+
* `ChecksumSHA256` (the server verifies the bytes) and as `x-amz-meta-sha256`, in both modes.
|
|
48
|
+
* - `get`/`head`/`delete`: a missing key maps to `ObjectNotFoundError` / `null` / no-op. Only a 404
|
|
49
|
+
* (`NoSuchKey` / `NotFound`) is "missing": a 400 or 403 (a wrong or missing SSE-C key) is
|
|
50
|
+
* `ObjectStoreUnavailableError`, fail closed (SPEC §5 C2). `get` refuses an object whose
|
|
51
|
+
* `ContentLength` is missing or above the configured cap (at most the 50 MiB
|
|
52
|
+
* `FILE_MAX_BYTES_CEILING`) before reading any body byte.
|
|
47
53
|
* - Every other SDK failure becomes `ObjectStoreUnavailableError` with its fixed message and NO
|
|
48
54
|
* `cause`: SDK errors can carry the endpoint, request id or credentials (Shield #10).
|
|
49
|
-
* - `ping`: `HeadBucket`, then put/get/delete of one probe object under `_probe/`,
|
|
50
|
-
*
|
|
55
|
+
* - `ping`: `HeadBucket`, then put/get/verify/delete of one probe object under `_probe/`, then (SSE-C
|
|
56
|
+
* only) the key canary `_shield/sse-c-canary` (SPEC §5 E). Each failing step throws an
|
|
57
|
+
* `ObjectStoreProbeError` naming the step and the sanitised provider error name and status.
|
|
51
58
|
*
|
|
52
59
|
* `@aws-sdk/client-s3` is imported here as TYPES only. The runtime module is loaded on the first
|
|
53
60
|
* operation (one cached load per process), so `require('@astram/guard')` never loads the SDK.
|
|
54
61
|
*/
|
|
55
62
|
const node_crypto_1 = require("node:crypto");
|
|
56
63
|
const core_1 = require("@astram/core");
|
|
64
|
+
const object_store_probe_error_js_1 = require("./object-store-probe-error.js");
|
|
57
65
|
let sdkLoad;
|
|
58
66
|
/** Load `@aws-sdk/client-s3` once, on first use (a failed load is retried next time). */
|
|
59
67
|
function loadSdk() {
|
|
@@ -65,13 +73,21 @@ function loadSdk() {
|
|
|
65
73
|
}
|
|
66
74
|
return sdkLoad;
|
|
67
75
|
}
|
|
76
|
+
/** SSE-C key length: AES-256 (SPEC §10). */
|
|
77
|
+
const SSE_C_KEY_BYTES = 32;
|
|
68
78
|
const SHA256_HEX = /^[0-9a-f]{64}$/;
|
|
69
79
|
const PROBE_BYTES = new TextEncoder().encode('shield object store probe');
|
|
70
80
|
const PROBE_CONTENT_TYPE = 'application/octet-stream';
|
|
81
|
+
/** The SSE-C key canary (SPEC §5 E, §10): outside `_probe/`, never deleted or overwritten. */
|
|
82
|
+
exports.SSE_C_CANARY_KEY = '_shield/sse-c-canary';
|
|
83
|
+
const CANARY_BYTES = new TextEncoder().encode('shield sse-c canary v1');
|
|
84
|
+
const CANARY_SHA256 = (0, node_crypto_1.createHash)('sha256').update(CANARY_BYTES).digest('hex');
|
|
71
85
|
class S3ObjectStore {
|
|
72
86
|
config;
|
|
73
87
|
bucket;
|
|
74
88
|
sse;
|
|
89
|
+
/** The SSE-C key (a private copy; unreachable by inspection or enumeration). */
|
|
90
|
+
#sseCustomerKey;
|
|
75
91
|
noOverwrite;
|
|
76
92
|
maxGetBytes;
|
|
77
93
|
connection;
|
|
@@ -80,7 +96,29 @@ class S3ObjectStore {
|
|
|
80
96
|
if (!Number.isInteger(maxBytes) || maxBytes <= 0 || maxBytes > core_1.FILE_MAX_BYTES_CEILING) {
|
|
81
97
|
throw new Error(`S3ObjectStore: maxBytes must be a positive integer of at most ${core_1.FILE_MAX_BYTES_CEILING}`);
|
|
82
98
|
}
|
|
83
|
-
|
|
99
|
+
const key = config.sseCustomerKey;
|
|
100
|
+
if (config.sse === 'SSE-C') {
|
|
101
|
+
if (!(key instanceof Uint8Array) || key.length !== SSE_C_KEY_BYTES) {
|
|
102
|
+
throw new Error('S3ObjectStore: sse SSE-C needs a 32-byte sseCustomerKey');
|
|
103
|
+
}
|
|
104
|
+
if (!isHttpsUrl(config.endpoint)) {
|
|
105
|
+
throw new Error('S3ObjectStore: sse SSE-C needs an https: endpoint');
|
|
106
|
+
}
|
|
107
|
+
this.#sseCustomerKey = new Uint8Array(key);
|
|
108
|
+
}
|
|
109
|
+
else if (config.sse === 'AES256') {
|
|
110
|
+
if (key !== undefined) {
|
|
111
|
+
throw new Error("S3ObjectStore: sseCustomerKey is only valid with sse 'SSE-C'");
|
|
112
|
+
}
|
|
113
|
+
this.#sseCustomerKey = undefined;
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
throw new Error("S3ObjectStore: sse must be 'AES256' or 'SSE-C'");
|
|
117
|
+
}
|
|
118
|
+
// The stored config never holds the key (only the private field does).
|
|
119
|
+
const { sseCustomerKey: _omit, ...rest } = config;
|
|
120
|
+
void _omit;
|
|
121
|
+
this.config = rest;
|
|
84
122
|
this.bucket = config.bucket;
|
|
85
123
|
this.sse = config.sse;
|
|
86
124
|
this.noOverwrite = options.noOverwrite ?? 'if-none-match';
|
|
@@ -105,12 +143,33 @@ class S3ObjectStore {
|
|
|
105
143
|
}
|
|
106
144
|
return this.connection;
|
|
107
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* SSE-C fields for put/get/head. The key goes as padded standard base64 of its 32 bytes: the
|
|
148
|
+
* SDK's ssec middleware (`@aws-sdk/middleware-sdk-s3`) keeps a valid base64 32-byte key as is and
|
|
149
|
+
* derives `SSECustomerKeyMD5` from the decoded bytes.
|
|
150
|
+
*/
|
|
151
|
+
sseCustomer() {
|
|
152
|
+
const key = this.#sseCustomerKey;
|
|
153
|
+
if (key === undefined)
|
|
154
|
+
return {};
|
|
155
|
+
return { SSECustomerAlgorithm: 'AES256', SSECustomerKey: Buffer.from(key).toString('base64') };
|
|
156
|
+
}
|
|
108
157
|
async put(key, bytes, meta) {
|
|
109
158
|
if (!SHA256_HEX.test(meta.sha256))
|
|
110
159
|
throw new core_1.ObjectStoreUnavailableError();
|
|
111
160
|
if (this.noOverwrite === 'head-first' && (await this.head(key)) !== null) {
|
|
112
161
|
throw new core_1.ObjectStoreUnavailableError();
|
|
113
162
|
}
|
|
163
|
+
try {
|
|
164
|
+
await this.sendPut(key, bytes, meta, this.noOverwrite === 'if-none-match');
|
|
165
|
+
}
|
|
166
|
+
catch {
|
|
167
|
+
// A 412 (key exists) is a refusal too: never overwrite. Fixed message, no cause.
|
|
168
|
+
throw new core_1.ObjectStoreUnavailableError();
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
/** One PutObject; rethrows the raw SDK error (callers map it). */
|
|
172
|
+
async sendPut(key, bytes, meta, ifNoneMatch) {
|
|
114
173
|
const { sdk, client } = await this.connect();
|
|
115
174
|
const input = {
|
|
116
175
|
Bucket: this.bucket,
|
|
@@ -118,53 +177,52 @@ class S3ObjectStore {
|
|
|
118
177
|
Body: bytes,
|
|
119
178
|
ContentType: meta.contentType,
|
|
120
179
|
ContentLength: bytes.length,
|
|
121
|
-
ServerSideEncryption:
|
|
180
|
+
...(this.sse === 'AES256' ? { ServerSideEncryption: 'AES256' } : {}),
|
|
181
|
+
...this.sseCustomer(),
|
|
122
182
|
ChecksumSHA256: Buffer.from(meta.sha256, 'hex').toString('base64'),
|
|
123
183
|
Metadata: { sha256: meta.sha256 },
|
|
124
|
-
...(
|
|
184
|
+
...(ifNoneMatch ? { IfNoneMatch: '*' } : {}),
|
|
125
185
|
};
|
|
126
|
-
|
|
127
|
-
await client.send(new sdk.PutObjectCommand(input));
|
|
128
|
-
}
|
|
129
|
-
catch {
|
|
130
|
-
// A 412 (key exists) is a refusal too: never overwrite. Fixed message, no cause.
|
|
131
|
-
throw new core_1.ObjectStoreUnavailableError();
|
|
132
|
-
}
|
|
186
|
+
await client.send(new sdk.PutObjectCommand(input));
|
|
133
187
|
}
|
|
134
188
|
async get(key) {
|
|
135
|
-
const { sdk, client } = await this.connect();
|
|
136
|
-
let bytes;
|
|
137
|
-
let contentType;
|
|
138
189
|
try {
|
|
139
|
-
|
|
140
|
-
if (!out.Body)
|
|
141
|
-
throw new core_1.ObjectStoreUnavailableError();
|
|
142
|
-
const length = out.ContentLength;
|
|
143
|
-
if (typeof length !== 'number' || length < 0 || length > this.maxGetBytes) {
|
|
144
|
-
// Unknown or over the cap: refuse before buffering, and release the socket.
|
|
145
|
-
discardBody(out.Body);
|
|
146
|
-
throw new core_1.ObjectStoreUnavailableError();
|
|
147
|
-
}
|
|
148
|
-
bytes = await out.Body.transformToByteArray();
|
|
149
|
-
if (bytes.length > this.maxGetBytes)
|
|
150
|
-
throw new core_1.ObjectStoreUnavailableError();
|
|
151
|
-
contentType = out.ContentType;
|
|
190
|
+
return await this.fetchObject(key);
|
|
152
191
|
}
|
|
153
192
|
catch (e) {
|
|
154
193
|
if (isNotFound(e))
|
|
155
194
|
throw new core_1.ObjectNotFoundError();
|
|
156
195
|
throw new core_1.ObjectStoreUnavailableError();
|
|
157
196
|
}
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* One GetObject under the size cap; rethrows the raw SDK error (callers map it), or a fixed
|
|
200
|
+
* `ObjectStoreUnavailableError` for a missing body or an unknown / over-cap length.
|
|
201
|
+
*/
|
|
202
|
+
async fetchObject(key) {
|
|
203
|
+
const { sdk, client } = await this.connect();
|
|
204
|
+
const out = await client.send(new sdk.GetObjectCommand({ Bucket: this.bucket, Key: key, ...this.sseCustomer() }));
|
|
205
|
+
if (!out.Body)
|
|
206
|
+
throw new core_1.ObjectStoreUnavailableError();
|
|
207
|
+
const length = out.ContentLength;
|
|
208
|
+
if (typeof length !== 'number' || length < 0 || length > this.maxGetBytes) {
|
|
209
|
+
// Unknown or over the cap: refuse before buffering, and release the socket.
|
|
210
|
+
discardBody(out.Body);
|
|
211
|
+
throw new core_1.ObjectStoreUnavailableError();
|
|
212
|
+
}
|
|
213
|
+
const bytes = await out.Body.transformToByteArray();
|
|
214
|
+
if (bytes.length > this.maxGetBytes)
|
|
215
|
+
throw new core_1.ObjectStoreUnavailableError();
|
|
158
216
|
return {
|
|
159
217
|
bytes,
|
|
160
|
-
contentType:
|
|
218
|
+
contentType: out.ContentType ?? PROBE_CONTENT_TYPE,
|
|
161
219
|
sizeBytes: bytes.length,
|
|
162
220
|
};
|
|
163
221
|
}
|
|
164
222
|
async head(key) {
|
|
165
223
|
const { sdk, client } = await this.connect();
|
|
166
224
|
try {
|
|
167
|
-
const out = await client.send(new sdk.HeadObjectCommand({ Bucket: this.bucket, Key: key }));
|
|
225
|
+
const out = await client.send(new sdk.HeadObjectCommand({ Bucket: this.bucket, Key: key, ...this.sseCustomer() }));
|
|
168
226
|
return {
|
|
169
227
|
sizeBytes: out.ContentLength ?? 0,
|
|
170
228
|
contentType: out.ContentType ?? PROBE_CONTENT_TYPE,
|
|
@@ -187,47 +245,102 @@ class S3ObjectStore {
|
|
|
187
245
|
throw new core_1.ObjectStoreUnavailableError();
|
|
188
246
|
}
|
|
189
247
|
}
|
|
248
|
+
/**
|
|
249
|
+
* The boot probe (SPEC §5 B, E): head-bucket, put, get, verify, then (SSE-C) the key canary.
|
|
250
|
+
* Throws an {@link ObjectStoreProbeError} naming the failing step.
|
|
251
|
+
*/
|
|
190
252
|
async ping() {
|
|
191
|
-
|
|
192
|
-
try {
|
|
193
|
-
await client.send(new sdk.HeadBucketCommand({ Bucket: this.bucket }));
|
|
194
|
-
}
|
|
195
|
-
catch {
|
|
196
|
-
throw new core_1.ObjectStoreUnavailableError();
|
|
197
|
-
}
|
|
253
|
+
await this.probeBucket();
|
|
198
254
|
const key = `_probe/${(0, node_crypto_1.randomUUID)()}`;
|
|
199
255
|
const sha256 = (0, node_crypto_1.createHash)('sha256').update(PROBE_BYTES).digest('hex');
|
|
200
|
-
|
|
256
|
+
// A refused put leaves nothing to delete (as before this change: same requests on AES256).
|
|
257
|
+
await this.probePut(key, PROBE_BYTES, sha256);
|
|
201
258
|
try {
|
|
202
|
-
|
|
259
|
+
let got;
|
|
260
|
+
try {
|
|
261
|
+
got = await this.fetchObject(key);
|
|
262
|
+
}
|
|
263
|
+
catch (e) {
|
|
264
|
+
throw (0, object_store_probe_error_js_1.probeFailure)('get', e);
|
|
265
|
+
}
|
|
203
266
|
if (!sameBytes(got.bytes, PROBE_BYTES))
|
|
204
|
-
throw new
|
|
205
|
-
}
|
|
206
|
-
catch {
|
|
207
|
-
throw new core_1.ObjectStoreUnavailableError();
|
|
267
|
+
throw new object_store_probe_error_js_1.ObjectStoreProbeError({ op: 'verify' });
|
|
208
268
|
}
|
|
209
269
|
finally {
|
|
210
270
|
await this.delete(key).catch(() => undefined);
|
|
211
271
|
}
|
|
272
|
+
if (this.sse === 'SSE-C')
|
|
273
|
+
await this.checkKeyCanary();
|
|
212
274
|
}
|
|
213
275
|
/**
|
|
214
276
|
* A write-only boot check (ai-debug-trace SPEC §5 A, §8): `HeadBucket`, then one small probe
|
|
215
277
|
* object under `_probe/` that is NOT read back or deleted (the trace credential is put-only;
|
|
216
|
-
* the bucket's lifecycle rule expires the probe).
|
|
278
|
+
* the bucket's lifecycle rule expires the probe). Throws an {@link ObjectStoreProbeError}.
|
|
217
279
|
*/
|
|
218
280
|
async pingWriteOnly() {
|
|
281
|
+
await this.probeBucket();
|
|
282
|
+
const sha256 = (0, node_crypto_1.createHash)('sha256').update(PROBE_BYTES).digest('hex');
|
|
283
|
+
await this.probePut(`_probe/${(0, node_crypto_1.randomUUID)()}`, PROBE_BYTES, sha256);
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* `HeadBucket` as the `head-bucket` probe step. An SDK load failure is NOT this step: it
|
|
287
|
+
* propagates as is, so the boot check prints its generic message rather than blaming the bucket.
|
|
288
|
+
*/
|
|
289
|
+
async probeBucket() {
|
|
219
290
|
const { sdk, client } = await this.connect();
|
|
220
291
|
try {
|
|
221
292
|
await client.send(new sdk.HeadBucketCommand({ Bucket: this.bucket }));
|
|
222
293
|
}
|
|
223
|
-
catch {
|
|
224
|
-
throw
|
|
294
|
+
catch (e) {
|
|
295
|
+
throw (0, object_store_probe_error_js_1.probeFailure)('head-bucket', e);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
/** The probe put under this store's overwrite mode, as the `put` probe step. */
|
|
299
|
+
async probePut(key, bytes, sha256) {
|
|
300
|
+
try {
|
|
301
|
+
if (this.noOverwrite === 'head-first' && (await this.head(key)) !== null) {
|
|
302
|
+
throw new core_1.ObjectStoreUnavailableError();
|
|
303
|
+
}
|
|
304
|
+
await this.sendPut(key, bytes, { contentType: PROBE_CONTENT_TYPE, sha256 }, this.noOverwrite === 'if-none-match');
|
|
305
|
+
}
|
|
306
|
+
catch (e) {
|
|
307
|
+
throw (0, object_store_probe_error_js_1.probeFailure)('put', e);
|
|
225
308
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* The SSE-C key canary (SPEC §5 E): read `_shield/sse-c-canary` with the configured key. Missing ⇒
|
|
312
|
+
* create it (always `If-None-Match: *`; a 412 means another worker won, so read again). A 400 or
|
|
313
|
+
* 403, or other bytes ⇒ the key does not open it (`keyMismatch`). Never deleted or overwritten.
|
|
314
|
+
*/
|
|
315
|
+
async checkKeyCanary() {
|
|
316
|
+
if ((await this.readCanary()) === 'match')
|
|
317
|
+
return;
|
|
318
|
+
try {
|
|
319
|
+
await this.sendPut(exports.SSE_C_CANARY_KEY, CANARY_BYTES, { contentType: PROBE_CONTENT_TYPE, sha256: CANARY_SHA256 }, true);
|
|
320
|
+
}
|
|
321
|
+
catch (e) {
|
|
322
|
+
if (!isPreconditionFailed(e))
|
|
323
|
+
throw (0, object_store_probe_error_js_1.probeFailure)('canary', e);
|
|
324
|
+
}
|
|
325
|
+
if ((await this.readCanary()) !== 'match') {
|
|
326
|
+
// Created (or raced) yet still not readable: fail closed.
|
|
327
|
+
throw new object_store_probe_error_js_1.ObjectStoreProbeError({ op: 'canary' });
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
async readCanary() {
|
|
331
|
+
let got;
|
|
332
|
+
try {
|
|
333
|
+
got = await this.fetchObject(exports.SSE_C_CANARY_KEY);
|
|
334
|
+
}
|
|
335
|
+
catch (e) {
|
|
336
|
+
if (isNotFound(e))
|
|
337
|
+
return 'missing';
|
|
338
|
+
throw (0, object_store_probe_error_js_1.probeFailure)('canary', e, { keyMismatch: isKeyRefusal(e) });
|
|
339
|
+
}
|
|
340
|
+
if (!sameBytes(got.bytes, CANARY_BYTES)) {
|
|
341
|
+
throw new object_store_probe_error_js_1.ObjectStoreProbeError({ op: 'canary', keyMismatch: true });
|
|
342
|
+
}
|
|
343
|
+
return 'match';
|
|
231
344
|
}
|
|
232
345
|
/**
|
|
233
346
|
* Whether the bucket has a lifecycle (expiry) rule: `'rules'`, `'none'` (the backend says no
|
|
@@ -250,6 +363,14 @@ class S3ObjectStore {
|
|
|
250
363
|
}
|
|
251
364
|
}
|
|
252
365
|
exports.S3ObjectStore = S3ObjectStore;
|
|
366
|
+
function isHttpsUrl(raw) {
|
|
367
|
+
try {
|
|
368
|
+
return new URL(raw).protocol === 'https:';
|
|
369
|
+
}
|
|
370
|
+
catch {
|
|
371
|
+
return false;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
253
374
|
/** Best-effort release of an unread response body (a Node stream in the SDK's Node runtime). */
|
|
254
375
|
function discardBody(body) {
|
|
255
376
|
const destroy = body.destroy;
|
|
@@ -271,6 +392,16 @@ function isNotFound(e) {
|
|
|
271
392
|
return true;
|
|
272
393
|
return err.$metadata?.httpStatusCode === 404 && err.name !== 'NoSuchBucket';
|
|
273
394
|
}
|
|
395
|
+
/** A key refusal on an SSE-C object: 400 (Hetzner `InvalidArgument`, MinIO no key) or 403. */
|
|
396
|
+
function isKeyRefusal(e) {
|
|
397
|
+
const status = (0, object_store_probe_error_js_1.safeHttpStatus)(e);
|
|
398
|
+
return status === 400 || status === 403;
|
|
399
|
+
}
|
|
400
|
+
/** A conditional PUT refused because the object exists. */
|
|
401
|
+
function isPreconditionFailed(e) {
|
|
402
|
+
return ((0, object_store_probe_error_js_1.safeHttpStatus)(e) === 412 ||
|
|
403
|
+
(typeof e === 'object' && e !== null && e.name === 'PreconditionFailed'));
|
|
404
|
+
}
|
|
274
405
|
function sameBytes(a, b) {
|
|
275
406
|
return a.length === b.length && Buffer.from(a).equals(Buffer.from(b));
|
|
276
407
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astram/guard",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.36.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Astram framework — the enforcement guard + real-world adapters (the 'hands'). One global deny-by-default gate every request passes through (ADR-0002), classification decorators, boot-pool assertion (ADR-0018), the forRoot() registration seam, and the DB/Redis/crypto adapters that connect the sealed core to a real backend. Depends on @astram/core (ADR-0003, ADR-0023).",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"@nestjs/platform-express": "^11",
|
|
46
46
|
"reflect-metadata": "^0.2",
|
|
47
47
|
"rxjs": "^7",
|
|
48
|
-
"@astram/messaging": "^0.1.
|
|
48
|
+
"@astram/messaging": "^0.1.27"
|
|
49
49
|
},
|
|
50
50
|
"peerDependenciesMeta": {
|
|
51
51
|
"@astram/messaging": {
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"typescript": "^5.7.0",
|
|
69
69
|
"unplugin-swc": "^1.5.1",
|
|
70
70
|
"vitest": "^2.1.8",
|
|
71
|
-
"@astram/messaging": "0.1.
|
|
71
|
+
"@astram/messaging": "0.1.27"
|
|
72
72
|
},
|
|
73
73
|
"repository": {
|
|
74
74
|
"type": "git",
|