@coffre/db 0.14.3 → 0.14.4
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/connect.d.ts +1 -1
- package/dist/{database-Ds1Y79h6.d.ts → database-CFhTnnzM.d.ts} +1 -1
- package/dist/dialect.d.ts +1 -1
- package/dist/grants.d.ts +1 -1
- package/dist/hyperdrive.d.ts +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/log.d.ts +1 -1
- package/dist/migrations/postgres/0020_vault_releases.sql +36 -0
- package/dist/migrations/postgres/meta/0020_snapshot.json +3334 -0
- package/dist/migrations/postgres/meta/_journal.json +7 -0
- package/dist/migrations/sqlite/0017_vault_releases.sql +26 -0
- package/dist/migrations/sqlite/meta/0017_snapshot.json +3037 -0
- package/dist/migrations/sqlite/meta/_journal.json +7 -0
- package/dist/portable.d.ts +2 -2
- package/dist/schema-sqlite.d.ts +75 -1
- package/dist/schema-sqlite.js +21 -1
- package/dist/schema-version.d.ts +1 -1
- package/dist/schema-version.js +14 -0
- package/dist/{schema-DcVkJhCf.d.ts → schema-z8GcN_Xu.d.ts} +72 -2
- package/dist/schema.d.ts +2 -2
- package/dist/schema.js +23 -2
- package/package.json +2 -2
- package/src/migrations/postgres/0020_vault_releases.sql +36 -0
- package/src/migrations/postgres/meta/0020_snapshot.json +3334 -0
- package/src/migrations/postgres/meta/_journal.json +7 -0
- package/src/migrations/sqlite/0017_vault_releases.sql +26 -0
- package/src/migrations/sqlite/meta/0017_snapshot.json +3037 -0
- package/src/migrations/sqlite/meta/_journal.json +7 -0
- package/src/schema.sqlite.ts +22 -0
- package/src/schema.ts +24 -0
package/dist/connect.d.ts
CHANGED
package/dist/dialect.d.ts
CHANGED
package/dist/grants.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as Queryable } from "./database-
|
|
1
|
+
import { i as Queryable } from "./database-CFhTnnzM.js";
|
|
2
2
|
import { Authenticity, Newest } from "./log.js";
|
|
3
3
|
import { StoredEntry } from "@coffre/core/audit";
|
|
4
4
|
import { Conversion, ConversionInput, InstanceRole, Scope } from "@coffre/core/access";
|
package/dist/hyperdrive.d.ts
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { g as schema_d_exports } from "./schema-
|
|
2
|
-
import { a as Transaction, c as tablesOf, i as Queryable, l as prepared, n as PoolLike, o as createDatabase, r as QueryOutsideTransaction, s as own, t as Database } from "./database-
|
|
1
|
+
import { g as schema_d_exports } from "./schema-z8GcN_Xu.js";
|
|
2
|
+
import { a as Transaction, c as tablesOf, i as Queryable, l as prepared, n as PoolLike, o as createDatabase, r as QueryOutsideTransaction, s as own, t as Database } from "./database-CFhTnnzM.js";
|
|
3
3
|
export { Database, PoolLike, QueryOutsideTransaction, Queryable, Transaction, createDatabase, own, prepared, schema_d_exports as schema, tablesOf };
|
package/dist/log.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as Transaction, i as Queryable } from "./database-
|
|
1
|
+
import { a as Transaction, i as Queryable } from "./database-CFhTnnzM.js";
|
|
2
2
|
import { Placeholder, SQL } from "drizzle-orm";
|
|
3
3
|
import { LogKey, StoredEntry } from "@coffre/core/audit";
|
|
4
4
|
//#region src/log.d.ts
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
-- Releases (W199): each key the vault released to a principal, and when last, so that its bulk limit counts the keys released within a window from a row per key, not from every read the principal ever made. The database keeps it, from each vault `secret.read` allowed, in the append's own transaction; the release before neither reads it nor knows it is kept, and its appends keep it too.
|
|
2
|
+
CREATE TABLE "vault_releases" (
|
|
3
|
+
"principal" text NOT NULL,
|
|
4
|
+
"key" text NOT NULL,
|
|
5
|
+
"released_at" bigint NOT NULL,
|
|
6
|
+
CONSTRAINT "vault_releases_pkey" PRIMARY KEY("principal","key")
|
|
7
|
+
);
|
|
8
|
+
--> statement-breakpoint
|
|
9
|
+
-- Room in each page for the next version of its rows: a read moves its keys' times on in place (a HOT update), so the
|
|
10
|
+
-- table and its key stay a row a key, however often each is read: the page prunes the versions before as it is read.
|
|
11
|
+
ALTER TABLE vault_releases SET (fillfactor = 50);--> statement-breakpoint
|
|
12
|
+
-- Each key the entry names, as the count read them before: the secret, or each item of a read's list at one place, or, for an entry that names none, which only a forged one is, the entry itself. As the owner, so that no login may write the table: the vault's appends reach it only through the log.
|
|
13
|
+
CREATE FUNCTION vault_releases_keep() RETURNS trigger
|
|
14
|
+
LANGUAGE plpgsql SECURITY DEFINER SET search_path = pg_catalog, pg_temp AS $$
|
|
15
|
+
BEGIN
|
|
16
|
+
INSERT INTO public.vault_releases AS kept (principal, key, released_at)
|
|
17
|
+
SELECT DISTINCT NEW.actor, coalesce(NEW.secret_id::text, CASE jsonb_typeof(one -> 'secretId') WHEN 'string' THEN one ->> 'secretId' END, 'entry:' || NEW.seq), NEW.occurred_at
|
|
18
|
+
FROM (SELECT) AS entry
|
|
19
|
+
LEFT JOIN LATERAL jsonb_path_query(CASE WHEN NEW.secret_id IS NULL THEN NEW.metadata::jsonb END, 'strict $.secrets ? (@.type() == "array")[*]', '{}', true) AS one ON true
|
|
20
|
+
ON CONFLICT (principal, key) DO UPDATE SET released_at = greatest(kept.released_at, excluded.released_at);
|
|
21
|
+
RETURN NULL;
|
|
22
|
+
END
|
|
23
|
+
$$;--> statement-breakpoint
|
|
24
|
+
-- A trigger runs its function whoever may execute it: no login may call it otherwise.
|
|
25
|
+
REVOKE ALL ON FUNCTION vault_releases_keep() FROM PUBLIC;--> statement-breakpoint
|
|
26
|
+
CREATE TRIGGER audit_log_releases AFTER INSERT ON audit_log FOR EACH ROW
|
|
27
|
+
WHEN (NEW.author = 'vault' AND NEW.action = 'secret.read' AND NEW.decision = 'allow')
|
|
28
|
+
EXECUTE FUNCTION vault_releases_keep();--> statement-breakpoint
|
|
29
|
+
-- Then the releases already in the log, in the same transaction: an append waits from the trigger to the commit, and none is missed.
|
|
30
|
+
INSERT INTO vault_releases (principal, key, released_at)
|
|
31
|
+
SELECT e.actor, coalesce(e.secret_id::text, CASE jsonb_typeof(one -> 'secretId') WHEN 'string' THEN one ->> 'secretId' END, 'entry:' || e.seq), max(e.occurred_at)
|
|
32
|
+
FROM audit_log e
|
|
33
|
+
LEFT JOIN LATERAL jsonb_path_query(CASE WHEN e.secret_id IS NULL THEN e.metadata::jsonb END, 'strict $.secrets ? (@.type() == "array")[*]', '{}', true) AS one ON true
|
|
34
|
+
WHERE e.author = 'vault' AND e.action = 'secret.read' AND e.decision = 'allow'
|
|
35
|
+
GROUP BY 1, 2;--> statement-breakpoint
|
|
36
|
+
GRANT SELECT ON vault_releases TO coffre_vault, coffre_backup;
|