@query-farm/vgi 0.48.4 → 0.48.5
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 +51 -0
- package/dist/attach-secret-keyfile.d.ts +11 -0
- package/dist/attach-secret-options.d.ts +96 -0
- package/dist/catalog/attach-option.d.ts +6 -0
- package/dist/catalog/interface.d.ts +15 -0
- package/dist/client-entry.js +1 -1
- package/dist/client-entry.js.map +4 -4
- package/dist/index.core.d.ts +2 -0
- package/dist/index.js +5700 -5276
- package/dist/index.js.map +24 -22
- package/dist/protocol/dispatch.d.ts +11 -0
- package/dist/protocol/handlers/catalog/admin.d.ts +1 -1
- package/dist/protocol/handlers/catalog/index.d.ts +1 -1
- package/dist/protocol/handlers/catalog/index_methods.d.ts +1 -1
- package/dist/protocol/handlers/catalog/macro.d.ts +1 -1
- package/dist/protocol/handlers/catalog/shared.d.ts +28 -3
- package/dist/protocol/handlers/catalog/table.d.ts +1 -1
- package/dist/protocol/handlers/catalog/view.d.ts +1 -1
- package/dist/protocol/handlers/function.d.ts +2 -0
- package/dist/protocol/handlers/table-buffering.d.ts +1 -1
- package/dist/serve-entry.d.ts +5 -0
- package/dist/serve-entry.js +475 -94
- package/dist/serve-entry.js.map +18 -16
- package/dist/worker-cf-entry.js +497 -93
- package/dist/worker-cf-entry.js.map +18 -16
- package/dist/worker.d.ts +10 -0
- package/package.json +1 -1
- package/src/attach-secret-keyfile.ts +185 -0
- package/src/attach-secret-options.ts +418 -0
- package/src/catalog/attach-option.ts +6 -0
- package/src/catalog/interface.ts +19 -0
- package/src/index.core.ts +10 -0
- package/src/protocol/dispatch.ts +14 -2
- package/src/protocol/handlers/catalog/admin.ts +33 -18
- package/src/protocol/handlers/catalog/index.ts +6 -5
- package/src/protocol/handlers/catalog/index_methods.ts +5 -3
- package/src/protocol/handlers/catalog/macro.ts +7 -5
- package/src/protocol/handlers/catalog/shared.ts +52 -6
- package/src/protocol/handlers/catalog/table.ts +24 -22
- package/src/protocol/handlers/catalog/view.ts +9 -7
- package/src/protocol/handlers/function.ts +11 -5
- package/src/protocol/handlers/table-buffering.ts +2 -1
- package/src/serve-entry.ts +6 -1
- package/src/worker.ts +12 -0
package/README.md
CHANGED
|
@@ -709,6 +709,57 @@ $ VGI_RPC_GRANT_KEYS="$(openssl rand -base64 32)" bun run scripts/serve.ts
|
|
|
709
709
|
- Sealed grants are not individually revocable: keep the lifetime short; removing a
|
|
710
710
|
key revokes every grant it minted.
|
|
711
711
|
|
|
712
|
+
### ATTACH options in functions and transaction hooks (secret ones included)
|
|
713
|
+
|
|
714
|
+
A catalog declares its ATTACH options (`attachOptions` on the descriptor, or
|
|
715
|
+
`attachOptionSpecs()`); a credential is declared `secret: true`. Every function call
|
|
716
|
+
and transaction hook of an attach reads the options with **`attachOptions()`**, secret
|
|
717
|
+
values included. The framework carries them for you, so you never pack options (and
|
|
718
|
+
never a credential) into your own `attach_opaque_data`:
|
|
719
|
+
|
|
720
|
+
```ts
|
|
721
|
+
import { attachOptions, ReadOnlyCatalogInterface, type CatalogAttachResult } from "@query-farm/vgi";
|
|
722
|
+
|
|
723
|
+
// In any function (bind, or init/process via params.initCall.bind_call):
|
|
724
|
+
const { api_key, region } = attachOptions(params.bindCall.attach_opaque_data);
|
|
725
|
+
|
|
726
|
+
// In a catalog method or transaction hook:
|
|
727
|
+
class MyCatalog extends ReadOnlyCatalogInterface {
|
|
728
|
+
override async attach(name: string, options?: Record<string, unknown>): Promise<CatalogAttachResult> {
|
|
729
|
+
const result = await super.attach(name, options);
|
|
730
|
+
return { ...result, supports_transactions: options?.transactional === true }; // no options in the bytes
|
|
731
|
+
}
|
|
732
|
+
override async transactionCommit(attach: Uint8Array, tx: Uint8Array) {
|
|
733
|
+
const { api_key } = this.attachOptions(attach);
|
|
734
|
+
// ...
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
```
|
|
738
|
+
|
|
739
|
+
How it works: `catalog_attach` appends the options to the catalog's attach bytes and
|
|
740
|
+
encrypts the secret ones (XChaCha20-Poly1305, a fresh random nonce each time) under
|
|
741
|
+
`HKDF-SHA256(root, info "vgi.attach_secret_options.v1")`, with the attach's
|
|
742
|
+
framework UUID as associated data — a blob copied into another attach value does not
|
|
743
|
+
open (`attach_opaque_data not recognized`). The framework strips all of it before
|
|
744
|
+
your code sees the attach bytes. A secret value is never in plaintext in any opaque
|
|
745
|
+
value, on any transport (the sealing spec's rule 5).
|
|
746
|
+
|
|
747
|
+
The root key is, in order:
|
|
748
|
+
|
|
749
|
+
1. `attachSecretKey` (`Worker`, `serveVgiWorker`, or `protocol` on `createVgiFetch`),
|
|
750
|
+
2. the HTTP signing key (`VGI_SIGNING_KEY`, or the one the worker minted at startup),
|
|
751
|
+
3. on stdio / AF_UNIX / launcher pools, the **host-local key file**, shared by every
|
|
752
|
+
VGI worker of the user on the host whatever its SDK:
|
|
753
|
+
`$VGI_ATTACH_SECRET_KEY_FILE`, else `$XDG_RUNTIME_DIR/vgi/attach-secret-options.key`,
|
|
754
|
+
else `<tmpdir>/vgi-<user>/attach-secret-options.key` — 32 random bytes, created
|
|
755
|
+
atomically on first use with mode 0600 in a 0700 directory, refused if anyone else
|
|
756
|
+
can read it. It is read only when a secret option actually has a value.
|
|
757
|
+
|
|
758
|
+
Every process that may receive a given attach must have the same root key (a
|
|
759
|
+
multi-instance HTTP deployment sets `VGI_SIGNING_KEY`). A runtime with no filesystem
|
|
760
|
+
(browser, Workers) and no signing key cannot accept a secret option: the ATTACH fails
|
|
761
|
+
and says so. Secret values, the key and the blob are never logged.
|
|
762
|
+
|
|
712
763
|
### Attach tickets: reattach as a user without their options (`vgi.attach_tickets.v1`)
|
|
713
764
|
|
|
714
765
|
A grant says *who* attaches; an **attach ticket** says *what*. While a user is
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const ATTACH_SECRET_KEY_FILE_ENV = "VGI_ATTACH_SECRET_KEY_FILE";
|
|
2
|
+
/** The key file path this process uses, per the cross-SDK rules above. */
|
|
3
|
+
export declare function hostLocalAttachSecretKeyPath(env?: Record<string, string | undefined>): string;
|
|
4
|
+
/**
|
|
5
|
+
* Read (creating on first use) the host-local key file at `path`
|
|
6
|
+
* (default {@link hostLocalAttachSecretKeyPath}). Synchronous and uncached;
|
|
7
|
+
* see {@link hostLocalAttachSecretKey} for the cached form the framework uses.
|
|
8
|
+
*/
|
|
9
|
+
export declare function loadHostLocalAttachSecretKey(path?: string): Uint8Array;
|
|
10
|
+
/** The host-local root key, read once per process (per resolved path). */
|
|
11
|
+
export declare function hostLocalAttachSecretKey(): Promise<Uint8Array>;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/** HKDF `info`, and the AAD prefix (before the 0x00 and the attach uuid). */
|
|
2
|
+
export declare const ATTACH_SECRET_OPTIONS_INFO = "vgi.attach_secret_options.v1";
|
|
3
|
+
/** First byte of the secret blob: XChaCha20-Poly1305 with a 24-byte nonce. */
|
|
4
|
+
export declare const ATTACH_SECRET_OPTIONS_VERSION = 1;
|
|
5
|
+
/** A decoded ATTACH options record: option name → value, as `attach()` got it. */
|
|
6
|
+
export type AttachOptionValues = Readonly<Record<string, unknown>>;
|
|
7
|
+
/**
|
|
8
|
+
* Where the secret-options root key comes from. `explicit` is the optional
|
|
9
|
+
* `attachSecretKey` configuration; `signingKey` the HTTP sealing key.
|
|
10
|
+
* `hostLocal` is resolved lazily, and only when a secret option has a value.
|
|
11
|
+
*/
|
|
12
|
+
export interface AttachSecretKeySource {
|
|
13
|
+
explicit?: Uint8Array | undefined;
|
|
14
|
+
signingKey?: Uint8Array | undefined;
|
|
15
|
+
/** Override for tests; defaults to the host-local key file. */
|
|
16
|
+
hostLocal?: (() => Promise<Uint8Array>) | undefined;
|
|
17
|
+
}
|
|
18
|
+
/** Raised when a secret option has a value but no key can be obtained. */
|
|
19
|
+
export declare class AttachSecretKeyUnavailableError extends Error {
|
|
20
|
+
constructor(message: string);
|
|
21
|
+
}
|
|
22
|
+
/** Raised by {@link attachOptions} for bytes the framework did not hand out. */
|
|
23
|
+
export declare class AttachOptionsUnavailableError extends Error {
|
|
24
|
+
constructor();
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The AEAD key for secret ATTACH options derived from `root`:
|
|
28
|
+
* HKDF-SHA256(ikm = root, salt = empty, info = "vgi.attach_secret_options.v1", L = 32).
|
|
29
|
+
* The root itself is never used as the cipher key.
|
|
30
|
+
*/
|
|
31
|
+
export declare function deriveAttachSecretKey(root: Uint8Array): Promise<Uint8Array>;
|
|
32
|
+
/**
|
|
33
|
+
* The trailer the framework appends to `uuid || catalog_bytes` for an attach
|
|
34
|
+
* with options, or an empty array when there are none. Encrypts the secret
|
|
35
|
+
* options (obtaining the key only if there is one); never logs anything.
|
|
36
|
+
*
|
|
37
|
+
* @throws {AttachSecretKeyUnavailableError} A secret option has a value and no key can be obtained.
|
|
38
|
+
*/
|
|
39
|
+
export declare function packAttachOptionsTrailer(uuid: Uint8Array, optionsIpc: Uint8Array | null | undefined, secretNames: ReadonlySet<string>, keys: AttachSecretKeySource, fixedNonce?: Uint8Array): Promise<Uint8Array>;
|
|
40
|
+
/**
|
|
41
|
+
* Turn a FULL framework attach plaintext (`uuid || catalog_bytes [|| trailer]`,
|
|
42
|
+
* already unsealed on HTTP) into the catalog's own bytes, decrypting any
|
|
43
|
+
* secret options and recording all options for {@link attachOptions}.
|
|
44
|
+
*
|
|
45
|
+
* Returns a view of a private copy, so the record cannot be confused with
|
|
46
|
+
* other bytes of the request. A value shorter than a UUID passes through
|
|
47
|
+
* as-is (with no options), as before.
|
|
48
|
+
*
|
|
49
|
+
* @throws {OpaqueDataRejectedError} The trailer is malformed or the secret blob
|
|
50
|
+
* does not open (wrong key, tampered, or moved from another attach).
|
|
51
|
+
*/
|
|
52
|
+
export declare function openFrameworkAttach(full: Uint8Array, keys: AttachSecretKeySource): Promise<Uint8Array>;
|
|
53
|
+
/**
|
|
54
|
+
* The ATTACH options of the attach a call belongs to — every supplied option,
|
|
55
|
+
* secret ones included, decoded exactly as `CatalogInterface.attach()`
|
|
56
|
+
* received them.
|
|
57
|
+
*
|
|
58
|
+
* Pass the attach value the framework handed the call: `bindCall.attach_opaque_data`
|
|
59
|
+
* (bind, and `initCall.bind_call` at init/process, for every function kind), a
|
|
60
|
+
* table-buffering function's `attachId`, or the `attachOpaqueData` argument of
|
|
61
|
+
* a catalog method or transaction hook (`transactionBegin` / `transactionCommit`
|
|
62
|
+
* / `transactionRollback`). Any subarray of those bytes works too; a copy does
|
|
63
|
+
* not.
|
|
64
|
+
*
|
|
65
|
+
* Secret options (declared `secret: true`) reach this accessor on every
|
|
66
|
+
* transport without ever being in plaintext in `attach_opaque_data`: the
|
|
67
|
+
* framework encrypts them inside the attach value with a worker-held key. A
|
|
68
|
+
* catalog therefore never needs to pack options into its own attach bytes,
|
|
69
|
+
* and must not put a secret there.
|
|
70
|
+
*
|
|
71
|
+
* Returns `{}` for a null attach value (a call outside any attach) and for
|
|
72
|
+
* an attach that had no options.
|
|
73
|
+
*
|
|
74
|
+
* @throws {AttachOptionsUnavailableError} The bytes were not handed out by the framework.
|
|
75
|
+
*/
|
|
76
|
+
export declare function attachOptions(attachOpaqueData: Uint8Array | null | undefined): AttachOptionValues;
|
|
77
|
+
/**
|
|
78
|
+
* One option from {@link attachOptions}, looked up case-insensitively (DuckDB
|
|
79
|
+
* option names are case-insensitive). `undefined` when it was not supplied.
|
|
80
|
+
*/
|
|
81
|
+
export declare function attachOption(attachOpaqueData: Uint8Array | null | undefined, name: string): unknown;
|
|
82
|
+
/**
|
|
83
|
+
* Names (lower-cased) of the options `catalog` declares `secret: true` for
|
|
84
|
+
* catalog `name`, read from what it advertises in `catalogsInfo()` — the same
|
|
85
|
+
* specs the extension redacts by — or its `attachOptionSpecs(name)`.
|
|
86
|
+
*/
|
|
87
|
+
export declare function secretAttachOptionNames(catalog: {
|
|
88
|
+
catalogsInfo?(): unknown;
|
|
89
|
+
attachOptionSpecs?(name: string): Array<{
|
|
90
|
+
name: string;
|
|
91
|
+
secret?: boolean;
|
|
92
|
+
}>;
|
|
93
|
+
}, name: string, deserialize: (bytes: Uint8Array) => {
|
|
94
|
+
name: string;
|
|
95
|
+
secret?: boolean;
|
|
96
|
+
}): Promise<Set<string>>;
|
|
@@ -50,6 +50,12 @@ export interface AttachOptionSpec {
|
|
|
50
50
|
* api_key getenv('SALES_API_KEY'));
|
|
51
51
|
* ```
|
|
52
52
|
*
|
|
53
|
+
* Functions and transaction hooks read the value with `attachOptions()`
|
|
54
|
+
* (`CatalogInterface.attachOptions()` in hooks), like any other option: the
|
|
55
|
+
* framework carries it to them encrypted inside `attach_opaque_data` with a
|
|
56
|
+
* worker-held key, so it is never in plaintext in any opaque value. Never
|
|
57
|
+
* put a secret into your catalog's own attach bytes.
|
|
58
|
+
*
|
|
53
59
|
* Combines with `required` (a credential the catalog cannot attach without,
|
|
54
60
|
* which a client can then ask for before attaching). It is allowed together
|
|
55
61
|
* with `default`, but a secret option normally has none: a default would be
|
|
@@ -520,6 +520,21 @@ export declare abstract class CatalogInterface {
|
|
|
520
520
|
* worker cache. `this`, except for a composite, which routes to its backend.
|
|
521
521
|
*/
|
|
522
522
|
catalogContentsOwner(_attachOpaqueData: AttachOpaqueData): CatalogInterface;
|
|
523
|
+
/**
|
|
524
|
+
* The ATTACH options of the attach `attachOpaqueData` belongs to — every
|
|
525
|
+
* supplied option, secret ones (`AttachOptionSpec.secret`) included, as
|
|
526
|
+
* `attach()` received them. Works in every catalog method and transaction
|
|
527
|
+
* hook (`transactionBegin` / `transactionCommit` / `transactionRollback`)
|
|
528
|
+
* on the `attachOpaqueData` argument it was given; functions use the
|
|
529
|
+
* standalone {@link attachOptions} on `bindCall.attach_opaque_data`.
|
|
530
|
+
*
|
|
531
|
+
* The framework carries the options inside `attach_opaque_data` itself and
|
|
532
|
+
* encrypts the secret ones with a worker-held key, so they never appear in
|
|
533
|
+
* plaintext in any opaque value on any transport. An `attach()` override
|
|
534
|
+
* therefore never needs to pack options into its own attach bytes, and must
|
|
535
|
+
* not put a credential there.
|
|
536
|
+
*/
|
|
537
|
+
attachOptions(attachOpaqueData: AttachOpaqueData): Readonly<Record<string, unknown>>;
|
|
523
538
|
transactionBegin(attachOpaqueData: AttachOpaqueData): Awaitable<Uint8Array | null>;
|
|
524
539
|
transactionCommit(attachOpaqueData: AttachOpaqueData, transactionOpaqueData: TransactionOpaqueData): Awaitable<void>;
|
|
525
540
|
transactionRollback(attachOpaqueData: AttachOpaqueData, transactionOpaqueData: TransactionOpaqueData): Awaitable<void>;
|
package/dist/client-entry.js
CHANGED