@coffre/db 0.10.2 → 0.12.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/connect.d.ts +1 -1
- package/dist/{database-DBtn3jqp.d.ts → database-Ds1Y79h6.d.ts} +1 -1
- package/dist/dialect.d.ts +1 -1
- package/dist/grants.d.ts +12 -5
- package/dist/grants.js +13 -8
- package/dist/hyperdrive.d.ts +9 -2
- package/dist/hyperdrive.js +16 -2
- package/dist/index.d.ts +2 -2
- package/dist/log.d.ts +1 -1
- package/dist/migrations/postgres/0015_workload_access.sql +43 -0
- package/dist/migrations/postgres/0016_spent_tokens.sql +12 -0
- package/dist/migrations/postgres/0017_capped_alerts.sql +10 -0
- package/dist/migrations/postgres/meta/0015_snapshot.json +3256 -0
- package/dist/migrations/postgres/meta/0016_snapshot.json +3256 -0
- package/dist/migrations/postgres/meta/0017_snapshot.json +3295 -0
- package/dist/migrations/postgres/meta/_journal.json +21 -0
- package/dist/migrations/sqlite/0015_workload_access.sql +70 -0
- package/dist/migrations/sqlite/0016_capped_alerts.sql +7 -0
- package/dist/migrations/sqlite/meta/0015_snapshot.json +2959 -0
- package/dist/migrations/sqlite/meta/0016_snapshot.json +2998 -0
- package/dist/migrations/sqlite/meta/_journal.json +14 -0
- package/dist/portable.d.ts +2 -2
- package/dist/{schema-NBVA9q-s.d.ts → schema-DcVkJhCf.d.ts} +393 -2
- package/dist/schema-sqlite.d.ts +408 -1
- package/dist/schema-sqlite.js +61 -5
- package/dist/schema-version.d.ts +1 -1
- package/dist/schema-version.js +35 -0
- package/dist/schema.d.ts +2 -2
- package/dist/schema.js +71 -5
- package/package.json +2 -2
- package/src/grants.ts +18 -9
- package/src/hyperdrive.ts +16 -2
- package/src/migrations/postgres/0015_workload_access.sql +43 -0
- package/src/migrations/postgres/0016_spent_tokens.sql +12 -0
- package/src/migrations/postgres/0017_capped_alerts.sql +10 -0
- package/src/migrations/postgres/meta/0015_snapshot.json +3256 -0
- package/src/migrations/postgres/meta/0016_snapshot.json +3256 -0
- package/src/migrations/postgres/meta/0017_snapshot.json +3295 -0
- package/src/migrations/postgres/meta/_journal.json +21 -0
- package/src/migrations/sqlite/0015_workload_access.sql +70 -0
- package/src/migrations/sqlite/0016_capped_alerts.sql +7 -0
- package/src/migrations/sqlite/meta/0015_snapshot.json +2959 -0
- package/src/migrations/sqlite/meta/0016_snapshot.json +2998 -0
- package/src/migrations/sqlite/meta/_journal.json +14 -0
- package/src/schema.sqlite.ts +83 -2
- package/src/schema.ts +91 -2
|
@@ -106,6 +106,27 @@
|
|
|
106
106
|
"when": 1792345776262,
|
|
107
107
|
"tag": "0014_custom_roles",
|
|
108
108
|
"breakpoints": true
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
"idx": 15,
|
|
112
|
+
"version": "7",
|
|
113
|
+
"when": 1792803757287,
|
|
114
|
+
"tag": "0015_workload_access",
|
|
115
|
+
"breakpoints": true
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
"idx": 16,
|
|
119
|
+
"version": "7",
|
|
120
|
+
"when": 1792814038307,
|
|
121
|
+
"tag": "0016_spent_tokens",
|
|
122
|
+
"breakpoints": true
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
"idx": 17,
|
|
126
|
+
"version": "7",
|
|
127
|
+
"when": 1792835445795,
|
|
128
|
+
"tag": "0017_capped_alerts",
|
|
129
|
+
"breakpoints": true
|
|
109
130
|
}
|
|
110
131
|
]
|
|
111
132
|
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
-- Workload access (docs/design/workload-access.md, section 11): key-bound sessions, their enrollment codes, and bindings' policies. It only adds: the release before neither reads nor writes any of it, and every check is only looser for its rows. SQLite widens a check by rebuilding the table, every row and index kept.
|
|
2
|
+
CREATE TABLE `enrollments` (
|
|
3
|
+
`id` text PRIMARY KEY NOT NULL,
|
|
4
|
+
`auth_mac` blob NOT NULL,
|
|
5
|
+
`binding_id` text NOT NULL,
|
|
6
|
+
`code_hash` blob NOT NULL,
|
|
7
|
+
`code_hint` text NOT NULL,
|
|
8
|
+
`scope` text NOT NULL,
|
|
9
|
+
`created_at` integer DEFAULT (CAST(unixepoch('subsec') * 1000 AS INTEGER)) NOT NULL,
|
|
10
|
+
`created_by` text NOT NULL,
|
|
11
|
+
`created_with` text,
|
|
12
|
+
`expires_at` integer NOT NULL,
|
|
13
|
+
FOREIGN KEY (`binding_id`) REFERENCES `service_bindings`(`id`) ON UPDATE no action ON DELETE restrict,
|
|
14
|
+
CONSTRAINT "enrollments_auth_mac_check" CHECK(octet_length("enrollments"."auth_mac") = 32),
|
|
15
|
+
CONSTRAINT "enrollments_code_hash_check" CHECK(octet_length("enrollments"."code_hash") = 32),
|
|
16
|
+
CONSTRAINT "enrollments_scope_check" CHECK(json_valid("enrollments"."scope"))
|
|
17
|
+
);
|
|
18
|
+
--> statement-breakpoint
|
|
19
|
+
CREATE INDEX `enrollments_binding_idx` ON `enrollments` (`binding_id`,`created_at`);--> statement-breakpoint
|
|
20
|
+
CREATE UNIQUE INDEX `enrollments_code_hash_key` ON `enrollments` (`code_hash`);--> statement-breakpoint
|
|
21
|
+
PRAGMA foreign_keys=OFF;--> statement-breakpoint
|
|
22
|
+
CREATE TABLE `__new_credentials` (
|
|
23
|
+
`id` text PRIMARY KEY NOT NULL,
|
|
24
|
+
`kind` text NOT NULL,
|
|
25
|
+
`auth_mac` blob NOT NULL,
|
|
26
|
+
`token_hash` blob NOT NULL,
|
|
27
|
+
`token_hint` text NOT NULL,
|
|
28
|
+
`generation` integer NOT NULL,
|
|
29
|
+
`principal` text NOT NULL,
|
|
30
|
+
`identity_id` text,
|
|
31
|
+
`scope` text,
|
|
32
|
+
`places` text,
|
|
33
|
+
`label` text,
|
|
34
|
+
`created_at` integer DEFAULT (CAST(unixepoch('subsec') * 1000 AS INTEGER)) NOT NULL,
|
|
35
|
+
`created_by` text NOT NULL,
|
|
36
|
+
`expires_at` integer NOT NULL,
|
|
37
|
+
`last_used_at` integer,
|
|
38
|
+
`last_used_ip` text,
|
|
39
|
+
`revoked_at` integer,
|
|
40
|
+
`revoked_by` text,
|
|
41
|
+
`jkt` text,
|
|
42
|
+
`not_after` integer,
|
|
43
|
+
`ancestors` text,
|
|
44
|
+
`constraints` text,
|
|
45
|
+
`enrollment_id` text,
|
|
46
|
+
`approved_at` integer,
|
|
47
|
+
`approved_by` text,
|
|
48
|
+
FOREIGN KEY (`principal`) REFERENCES `vault_members`(`principal`) ON UPDATE no action ON DELETE restrict,
|
|
49
|
+
FOREIGN KEY (`identity_id`,`principal`,`generation`) REFERENCES `identities`(`id`,`principal`,`generation`) ON UPDATE no action ON DELETE restrict,
|
|
50
|
+
FOREIGN KEY (`enrollment_id`) REFERENCES `enrollments`(`id`) ON UPDATE no action ON DELETE restrict,
|
|
51
|
+
CONSTRAINT "credentials_kind_check" CHECK("__new_credentials"."kind" IN ('browser', 'cli', 'service', 'personal', 'handle', 'workload')),
|
|
52
|
+
CONSTRAINT "credentials_principal_check" CHECK("__new_credentials"."principal" LIKE 'user:%' OR "__new_credentials"."principal" LIKE 'token:%'),
|
|
53
|
+
CONSTRAINT "credentials_kind_matches_principal" CHECK(("__new_credentials"."kind" IN ('service', 'workload')) = ("__new_credentials"."principal" LIKE 'token:%')),
|
|
54
|
+
CONSTRAINT "credentials_workload_jkt_check" CHECK("__new_credentials"."kind" <> 'workload' OR "__new_credentials"."jkt" IS NOT NULL),
|
|
55
|
+
CONSTRAINT "credentials_token_hash_check" CHECK(octet_length("__new_credentials"."token_hash") = 32),
|
|
56
|
+
CONSTRAINT "credentials_auth_mac_check" CHECK(octet_length("__new_credentials"."auth_mac") = 32)
|
|
57
|
+
);
|
|
58
|
+
--> statement-breakpoint
|
|
59
|
+
INSERT INTO `__new_credentials`("id", "kind", "auth_mac", "token_hash", "token_hint", "generation", "principal", "identity_id", "scope", "places", "label", "created_at", "created_by", "expires_at", "last_used_at", "last_used_ip", "revoked_at", "revoked_by") SELECT "id", "kind", "auth_mac", "token_hash", "token_hint", "generation", "principal", "identity_id", "scope", "places", "label", "created_at", "created_by", "expires_at", "last_used_at", "last_used_ip", "revoked_at", "revoked_by" FROM `credentials`;--> statement-breakpoint
|
|
60
|
+
DROP TABLE `credentials`;--> statement-breakpoint
|
|
61
|
+
ALTER TABLE `__new_credentials` RENAME TO `credentials`;--> statement-breakpoint
|
|
62
|
+
PRAGMA foreign_keys=ON;--> statement-breakpoint
|
|
63
|
+
CREATE INDEX `credentials_principal_idx` ON `credentials` (`principal`,`generation`);--> statement-breakpoint
|
|
64
|
+
CREATE INDEX `credentials_live_idx` ON `credentials` (`principal`,`expires_at`) WHERE "credentials"."revoked_at" IS NULL;--> statement-breakpoint
|
|
65
|
+
CREATE INDEX `credentials_issued_by_idx` ON `credentials` (`principal`,`created_by`,`created_at`);--> statement-breakpoint
|
|
66
|
+
CREATE INDEX `credentials_enrollment_roots_idx` ON `credentials` (`enrollment_id`,`created_at`) WHERE "credentials"."kind" = 'workload' AND "credentials"."ancestors" IS NULL;--> statement-breakpoint
|
|
67
|
+
CREATE UNIQUE INDEX `credentials_token_hash_key` ON `credentials` (`token_hash`);--> statement-breakpoint
|
|
68
|
+
ALTER TABLE `service_bindings` ADD `policy` text;--> statement-breakpoint
|
|
69
|
+
CREATE INDEX `audit_log_freeze_idx` ON `audit_log` (json_extract("metadata", '$.target'),`seq`) WHERE "audit_log"."author" = 'app' AND "audit_log"."action" IN ('workload.freeze', 'workload.unfreeze') AND "audit_log"."decision" = 'allow';--> statement-breakpoint
|
|
70
|
+
CREATE INDEX `audit_log_supersede_idx` ON `audit_log` (json_extract("metadata", '$.enrollmentId')) WHERE "audit_log"."author" = 'app' AND "audit_log"."action" = 'enrollment.supersede' AND "audit_log"."decision" = 'allow';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
-- Capped alerts (T98): when a service's sign-in was last refused `unknown_key` with an alert, so that the next alerts an hour later at the soonest, whichever process sees it. It only adds.
|
|
2
|
+
CREATE TABLE `capped_alerts` (
|
|
3
|
+
`service` text NOT NULL,
|
|
4
|
+
`kind` text NOT NULL,
|
|
5
|
+
`raised_at` integer NOT NULL,
|
|
6
|
+
PRIMARY KEY(`service`, `kind`)
|
|
7
|
+
);
|