@fabrika/iam 0.0.0-stage → 0.9.0-dev.26
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/fabrika.config.ts +267 -0
- package/migrations/0001_init.sql +316 -0
- package/migrations/0002_oauth.sql +38 -0
- package/migrations/0003_contract_apps.sql +11 -0
- package/migrations/0004_membership.sql +93 -0
- package/migrations/0005_workloads.sql +23 -0
- package/migrations/0006_membership_transport_keys.sql +16 -0
- package/migrations/0007_member_directory.sql +7 -0
- package/migrations/0008_durable_audit.sql +28 -0
- package/migrations/0009_member_lookups.sql +7 -0
- package/migrations/0010_workload_issues.sql +6 -0
- package/migrations/0011_app_presentation.sql +15 -0
- package/migrations/0012_external_principals.sql +10 -0
- package/migrations/0013_app_mail_templates.sql +14 -0
- package/migrations/0014_invitation_wording.sql +8 -0
- package/migrations/0015_app_schema_revisions.sql +15 -0
- package/migrations/0016_principal_grant_revision.sql +9 -0
- package/migrations/0017_app_sign_ins.sql +12 -0
- package/migrations/0018_app_members.sql +13 -0
- package/migrations/0019_app_mail_html.sql +7 -0
- package/migrations/0020_public_workloads.sql +34 -0
- package/migrations/0021_installation_brand.sql +19 -0
- package/migrations/0022_password_policy.sql +12 -0
- package/migrations/0023_terminals.sql +155 -0
- package/migrations/0024_app_terminals.sql +10 -0
- package/migrations/0025_terminal_completion.sql +10 -0
- package/migrations/0026_terminal_generation.sql +12 -0
- package/migrations/0027_application_exact_actions.sql +28 -0
- package/migrations/0028_oauth_client_assertions.sql +10 -0
- package/migrations/0029_role_via.sql +6 -0
- package/migrations/0030_membership_role_via.sql +12 -0
- package/migrations/0031_person_locale.sql +11 -0
- package/migrations-postgres/0001_init.sql +331 -0
- package/migrations-postgres/0002_oauth.sql +36 -0
- package/migrations-postgres/0003_contract_apps.sql +8 -0
- package/migrations-postgres/0004_membership.sql +92 -0
- package/migrations-postgres/0005_workloads.sql +18 -0
- package/migrations-postgres/0006_membership_transport_keys.sql +12 -0
- package/migrations-postgres/0007_member_directory.sql +7 -0
- package/migrations-postgres/0008_durable_audit.sql +8 -0
- package/migrations-postgres/0009_member_lookups.sql +7 -0
- package/migrations-postgres/0010_workload_issues.sql +6 -0
- package/migrations-postgres/0011_app_presentation.sql +15 -0
- package/migrations-postgres/0012_external_principals.sql +10 -0
- package/migrations-postgres/0013_app_mail_templates.sql +14 -0
- package/migrations-postgres/0014_invitation_wording.sql +8 -0
- package/migrations-postgres/0015_app_schema_revisions.sql +15 -0
- package/migrations-postgres/0016_principal_grant_revision.sql +9 -0
- package/migrations-postgres/0017_app_sign_ins.sql +12 -0
- package/migrations-postgres/0018_app_members.sql +13 -0
- package/migrations-postgres/0019_app_mail_html.sql +7 -0
- package/migrations-postgres/0020_public_workloads.sql +9 -0
- package/migrations-postgres/0021_installation_brand.sql +19 -0
- package/migrations-postgres/0022_password_policy.sql +12 -0
- package/migrations-postgres/0023_terminals.sql +70 -0
- package/migrations-postgres/0024_app_terminals.sql +10 -0
- package/migrations-postgres/0025_terminal_completion.sql +10 -0
- package/migrations-postgres/0026_terminal_generation.sql +12 -0
- package/migrations-postgres/0027_application_exact_actions.sql +28 -0
- package/migrations-postgres/0028_oauth_client_assertions.sql +9 -0
- package/migrations-postgres/0029_role_via.sql +4 -0
- package/migrations-postgres/0030_membership_role_via.sql +7 -0
- package/migrations-postgres/0031_person_locale.sql +11 -0
- package/package.json +70 -5
- package/src/admin/access.ts +47 -0
- package/src/admin/api-keys.ts +280 -0
- package/src/admin/app-people.ts +209 -0
- package/src/admin/app-schema.ts +308 -0
- package/src/admin/audit.ts +81 -0
- package/src/admin/brand.ts +54 -0
- package/src/admin/connections.ts +48 -0
- package/src/admin/context.ts +70 -0
- package/src/admin/grant-support.ts +192 -0
- package/src/admin/grants.ts +189 -0
- package/src/admin/handlers.ts +102 -0
- package/src/admin/http.ts +24 -0
- package/src/admin/membership-keys.ts +38 -0
- package/src/admin/pagination.ts +28 -0
- package/src/admin/password-policy.ts +48 -0
- package/src/admin/passwords.ts +78 -0
- package/src/admin/policies.ts +136 -0
- package/src/admin/principals.ts +226 -0
- package/src/admin/router.ts +291 -0
- package/src/admin/rpc.ts +387 -0
- package/src/admin/sessions.ts +115 -0
- package/src/admin/share-links.ts +127 -0
- package/src/admin/terminals.ts +115 -0
- package/src/admin/user-admin.ts +76 -0
- package/src/admin/workloads.ts +85 -0
- package/src/app-presentation.ts +178 -0
- package/src/app.ts +158 -0
- package/src/auth/cookies.ts +64 -0
- package/src/auth/failure.ts +25 -0
- package/src/auth/handoff.ts +136 -0
- package/src/auth/http.ts +88 -0
- package/src/auth/invitations.ts +220 -0
- package/src/auth/known-device.ts +44 -0
- package/src/auth/login.ts +162 -0
- package/src/auth/oidc-flight.ts +91 -0
- package/src/auth/oidc.ts +148 -0
- package/src/auth/password.ts +416 -0
- package/src/auth/routes.ts +108 -0
- package/src/auth/sessions.ts +249 -0
- package/src/auth/terminals.ts +284 -0
- package/src/auth.ts +193 -0
- package/src/binding-identity.ts +25 -0
- package/src/bounded-body.ts +35 -0
- package/src/catalog/cs.ts +147 -0
- package/src/catalog/en.ts +148 -0
- package/src/catalog/index.ts +122 -0
- package/src/catalog/uk.ts +164 -0
- package/src/client-address.ts +39 -0
- package/src/common-passwords.ts +37 -0
- package/src/contract-rules.ts +80 -0
- package/src/cron.ts +54 -0
- package/src/db.ts +128 -0
- package/src/delegation.ts +100 -0
- package/src/device-http.ts +39 -0
- package/src/device.ts +269 -0
- package/src/email-identity.ts +2 -0
- package/src/env.ts +132 -0
- package/src/handoff.ts +175 -0
- package/src/html.ts +4 -0
- package/src/human-admission.ts +40 -0
- package/src/identification.ts +185 -0
- package/src/index.ts +292 -0
- package/src/installation-brand.ts +82 -0
- package/src/issue.ts +265 -0
- package/src/json.ts +30 -0
- package/src/log.ts +26 -0
- package/src/membership-http.ts +135 -0
- package/src/membership.ts +1210 -0
- package/src/messages.ts +44 -0
- package/src/narrow-permissions.ts +26 -0
- package/src/node/browser-identity.ts +69 -0
- package/src/node/migrate.ts +52 -0
- package/src/node/prune.ts +34 -0
- package/src/node/runtime.ts +221 -0
- package/src/node/server.ts +104 -0
- package/src/oauth-client-auth.ts +93 -0
- package/src/oauth-client.ts +145 -0
- package/src/oauth-config.ts +72 -0
- package/src/oauth-http.ts +262 -0
- package/src/oauth.ts +272 -0
- package/src/oidc.ts +260 -0
- package/src/origin.ts +29 -0
- package/src/password-crypto.ts +148 -0
- package/src/password-db.ts +419 -0
- package/src/password-minimum.ts +44 -0
- package/src/password-pages.ts +397 -0
- package/src/password-policy.ts +79 -0
- package/src/password-service.ts +67 -0
- package/src/person-locale.ts +103 -0
- package/src/proxy-proof.ts +36 -0
- package/src/relay-mail.ts +64 -0
- package/src/repositories/app-schema.ts +550 -0
- package/src/repositories/audit.ts +405 -0
- package/src/repositories/brand.ts +66 -0
- package/src/repositories/credentials.ts +331 -0
- package/src/repositories/device.ts +137 -0
- package/src/repositories/grants.ts +404 -0
- package/src/repositories/handoff.ts +103 -0
- package/src/repositories/membership-transport.ts +49 -0
- package/src/repositories/membership.ts +875 -0
- package/src/repositories/oauth.ts +122 -0
- package/src/repositories/password-policy.ts +44 -0
- package/src/repositories/principals.ts +358 -0
- package/src/repositories/sessions.ts +339 -0
- package/src/repositories/sql.ts +23 -0
- package/src/repositories/terminals.ts +346 -0
- package/src/repositories/workloads.ts +134 -0
- package/src/request-id.ts +46 -0
- package/src/resolve.ts +396 -0
- package/src/retention.ts +34 -0
- package/src/roles.ts +54 -0
- package/src/rpc-http.ts +333 -0
- package/src/rpc-inputs.ts +110 -0
- package/src/rpc.ts +440 -0
- package/src/secret.ts +45 -0
- package/src/service.ts +59 -0
- package/src/services.ts +199 -0
- package/src/signing.ts +260 -0
- package/src/stored-chain.ts +23 -0
- package/src/stored-permissions.ts +34 -0
- package/src/terminals.ts +15 -0
- package/src/tokens.ts +506 -0
- package/src/workload-token.ts +130 -0
- package/types/fabrika.config.d.ts +11 -0
- package/types/src/admin/access.d.ts +19 -0
- package/types/src/admin/api-keys.d.ts +26 -0
- package/types/src/admin/app-people.d.ts +8 -0
- package/types/src/admin/app-schema.d.ts +32 -0
- package/types/src/admin/audit.d.ts +10 -0
- package/types/src/admin/brand.d.ts +10 -0
- package/types/src/admin/connections.d.ts +5 -0
- package/types/src/admin/context.d.ts +46 -0
- package/types/src/admin/grant-support.d.ts +59 -0
- package/types/src/admin/grants.d.ts +8 -0
- package/types/src/admin/handlers.d.ts +82 -0
- package/types/src/admin/http.d.ts +9 -0
- package/types/src/admin/membership-keys.d.ts +8 -0
- package/types/src/admin/pagination.d.ts +5 -0
- package/types/src/admin/password-policy.d.ts +9 -0
- package/types/src/admin/passwords.d.ts +5 -0
- package/types/src/admin/policies.d.ts +15 -0
- package/types/src/admin/principals.d.ts +15 -0
- package/types/src/admin/router.d.ts +75 -0
- package/types/src/admin/rpc.d.ts +6 -0
- package/types/src/admin/sessions.d.ts +14 -0
- package/types/src/admin/share-links.d.ts +21 -0
- package/types/src/admin/terminals.d.ts +13 -0
- package/types/src/admin/user-admin.d.ts +30 -0
- package/types/src/admin/workloads.d.ts +5 -0
- package/types/src/app-presentation.d.ts +86 -0
- package/types/src/app.d.ts +62 -0
- package/types/src/auth/cookies.d.ts +29 -0
- package/types/src/auth/failure.d.ts +47 -0
- package/types/src/auth/handoff.d.ts +66 -0
- package/types/src/auth/http.d.ts +29 -0
- package/types/src/auth/invitations.d.ts +18 -0
- package/types/src/auth/known-device.d.ts +12 -0
- package/types/src/auth/login.d.ts +10 -0
- package/types/src/auth/oidc-flight.d.ts +39 -0
- package/types/src/auth/oidc.d.ts +7 -0
- package/types/src/auth/password.d.ts +7 -0
- package/types/src/auth/routes.d.ts +15 -0
- package/types/src/auth/sessions.d.ts +60 -0
- package/types/src/auth/terminals.d.ts +47 -0
- package/types/src/auth.d.ts +70 -0
- package/types/src/binding-identity.d.ts +12 -0
- package/types/src/bounded-body.d.ts +12 -0
- package/types/src/catalog/cs.d.ts +2 -0
- package/types/src/catalog/en.d.ts +2 -0
- package/types/src/catalog/index.d.ts +112 -0
- package/types/src/catalog/uk.d.ts +2 -0
- package/types/src/client-address.d.ts +31 -0
- package/types/src/common-passwords.d.ts +2 -0
- package/types/src/contract-rules.d.ts +25 -0
- package/types/src/cron.d.ts +15 -0
- package/types/src/db.d.ts +58 -0
- package/types/src/delegation.d.ts +38 -0
- package/types/src/device-http.d.ts +2 -0
- package/types/src/device.d.ts +11 -0
- package/types/src/email-identity.d.ts +1 -0
- package/types/src/env.d.ts +127 -0
- package/types/src/handoff.d.ts +57 -0
- package/types/src/html.d.ts +2 -0
- package/types/src/human-admission.d.ts +22 -0
- package/types/src/identification.d.ts +30 -0
- package/types/src/index.d.ts +62 -0
- package/types/src/installation-brand.d.ts +22 -0
- package/types/src/issue.d.ts +62 -0
- package/types/src/json.d.ts +15 -0
- package/types/src/log.d.ts +15 -0
- package/types/src/membership-http.d.ts +8 -0
- package/types/src/membership.d.ts +156 -0
- package/types/src/messages.d.ts +20 -0
- package/types/src/narrow-permissions.d.ts +7 -0
- package/types/src/node/browser-identity.d.ts +1 -0
- package/types/src/node/migrate.d.ts +4 -0
- package/types/src/node/prune.d.ts +1 -0
- package/types/src/node/runtime.d.ts +51 -0
- package/types/src/node/server.d.ts +5 -0
- package/types/src/oauth-client-auth.d.ts +26 -0
- package/types/src/oauth-client.d.ts +17 -0
- package/types/src/oauth-config.d.ts +16 -0
- package/types/src/oauth-http.d.ts +7 -0
- package/types/src/oauth.d.ts +51 -0
- package/types/src/oidc.d.ts +81 -0
- package/types/src/origin.d.ts +9 -0
- package/types/src/password-crypto.d.ts +37 -0
- package/types/src/password-db.d.ts +134 -0
- package/types/src/password-minimum.d.ts +23 -0
- package/types/src/password-pages.d.ts +143 -0
- package/types/src/password-policy.d.ts +19 -0
- package/types/src/password-service.d.ts +24 -0
- package/types/src/person-locale.d.ts +50 -0
- package/types/src/proxy-proof.d.ts +21 -0
- package/types/src/relay-mail.d.ts +25 -0
- package/types/src/repositories/app-schema.d.ts +244 -0
- package/types/src/repositories/audit.d.ts +187 -0
- package/types/src/repositories/brand.d.ts +41 -0
- package/types/src/repositories/credentials.d.ts +148 -0
- package/types/src/repositories/device.d.ts +50 -0
- package/types/src/repositories/grants.d.ts +177 -0
- package/types/src/repositories/handoff.d.ts +52 -0
- package/types/src/repositories/membership-transport.d.ts +31 -0
- package/types/src/repositories/membership.d.ts +273 -0
- package/types/src/repositories/oauth.d.ts +55 -0
- package/types/src/repositories/password-policy.d.ts +25 -0
- package/types/src/repositories/principals.d.ts +159 -0
- package/types/src/repositories/sessions.d.ts +150 -0
- package/types/src/repositories/sql.d.ts +13 -0
- package/types/src/repositories/terminals.d.ts +144 -0
- package/types/src/repositories/workloads.d.ts +61 -0
- package/types/src/request-id.d.ts +25 -0
- package/types/src/resolve.d.ts +118 -0
- package/types/src/retention.d.ts +18 -0
- package/types/src/roles.d.ts +34 -0
- package/types/src/rpc-http.d.ts +53 -0
- package/types/src/rpc-inputs.d.ts +707 -0
- package/types/src/rpc.d.ts +4 -0
- package/types/src/secret.d.ts +21 -0
- package/types/src/service.d.ts +19 -0
- package/types/src/services.d.ts +72 -0
- package/types/src/signing.d.ts +72 -0
- package/types/src/stored-chain.d.ts +6 -0
- package/types/src/stored-permissions.d.ts +12 -0
- package/types/src/terminals.d.ts +7 -0
- package/types/src/tokens.d.ts +113 -0
- package/types/src/workload-token.d.ts +7 -0
- package/README.md +0 -3
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
-- Membership, delegation grants and share links for multi-tenant applications (A12). SQLite/D1 dialect;
|
|
2
|
+
-- `../migrations-postgres/0004_membership.sql` states the same outcome. Every row written before this
|
|
3
|
+
-- file keeps NULL in each new column, which is what an app without the declarations means.
|
|
4
|
+
|
|
5
|
+
-- What a contract compiles into its schema: a dimension's container, its creator role and the actions
|
|
6
|
+
-- that manage and list its members; who may assign a membership role (JSON array of role keys).
|
|
7
|
+
ALTER TABLE app_scopes ADD COLUMN parent_scope TEXT;
|
|
8
|
+
ALTER TABLE app_scopes ADD COLUMN creator_role TEXT;
|
|
9
|
+
ALTER TABLE app_scopes ADD COLUMN members_manage TEXT;
|
|
10
|
+
ALTER TABLE app_scopes ADD COLUMN members_list TEXT;
|
|
11
|
+
ALTER TABLE roles ADD COLUMN assignable_by TEXT;
|
|
12
|
+
|
|
13
|
+
-- Share-link mounts. `grants` is a JSON array of exact actions, like `roles.permissions`.
|
|
14
|
+
CREATE TABLE app_link_mounts (
|
|
15
|
+
app TEXT NOT NULL,
|
|
16
|
+
mount TEXT NOT NULL,
|
|
17
|
+
dimension TEXT NOT NULL,
|
|
18
|
+
grants TEXT NOT NULL,
|
|
19
|
+
issued_by TEXT NOT NULL,
|
|
20
|
+
max_days INTEGER NOT NULL CHECK (max_days > 0),
|
|
21
|
+
PRIMARY KEY (app, mount)
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
-- The endpoints whose requests may spend the caller's membership authority through a delegation grant.
|
|
25
|
+
CREATE TABLE app_delegated_endpoints (
|
|
26
|
+
app TEXT NOT NULL,
|
|
27
|
+
endpoint TEXT NOT NULL,
|
|
28
|
+
action TEXT NOT NULL,
|
|
29
|
+
dimension TEXT NOT NULL,
|
|
30
|
+
purpose TEXT NOT NULL CHECK (purpose IN ('members', 'creates')),
|
|
31
|
+
PRIMARY KEY (app, endpoint)
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
-- A value IAM created for an app. Membership itself is ordinary role grants scoped to the value; this
|
|
35
|
+
-- row records who created it and is the row a revoke locks, so two concurrent revokes cannot each
|
|
36
|
+
-- remove one of the last two holders of the creator role.
|
|
37
|
+
CREATE TABLE membership_scopes (
|
|
38
|
+
app TEXT NOT NULL,
|
|
39
|
+
scope_type TEXT NOT NULL,
|
|
40
|
+
scope_value TEXT NOT NULL,
|
|
41
|
+
created_by TEXT REFERENCES principals(id) ON DELETE SET NULL,
|
|
42
|
+
created_at INTEGER NOT NULL,
|
|
43
|
+
PRIMARY KEY (app, scope_type, scope_value)
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
-- Single-use delegation grants (ADR-0022 rule 6): bound to one caller, one endpoint and one request,
|
|
47
|
+
-- stored only as a hash and spent by a conditional UPDATE, like `auth_codes`.
|
|
48
|
+
CREATE TABLE delegation_grants (
|
|
49
|
+
id TEXT PRIMARY KEY,
|
|
50
|
+
grant_hash TEXT NOT NULL UNIQUE,
|
|
51
|
+
app TEXT NOT NULL,
|
|
52
|
+
principal_id TEXT NOT NULL REFERENCES principals(id) ON DELETE CASCADE,
|
|
53
|
+
endpoint TEXT NOT NULL,
|
|
54
|
+
request_id TEXT NOT NULL,
|
|
55
|
+
expires_at INTEGER NOT NULL,
|
|
56
|
+
consumed_at INTEGER,
|
|
57
|
+
created_at INTEGER NOT NULL
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
CREATE INDEX idx_delegation_grants_expires ON delegation_grants(expires_at);
|
|
61
|
+
|
|
62
|
+
-- An invitation to a membership role in one value, accepted only by the verified owner of `email` (the
|
|
63
|
+
-- normalized mailbox). The one-time token travels in the invitation email and only its hash is kept.
|
|
64
|
+
CREATE TABLE membership_invitations (
|
|
65
|
+
id TEXT PRIMARY KEY,
|
|
66
|
+
token_hash TEXT NOT NULL UNIQUE,
|
|
67
|
+
app TEXT NOT NULL,
|
|
68
|
+
scope_type TEXT NOT NULL,
|
|
69
|
+
scope_value TEXT NOT NULL,
|
|
70
|
+
role_key TEXT NOT NULL,
|
|
71
|
+
email TEXT NOT NULL,
|
|
72
|
+
invited_by TEXT NOT NULL REFERENCES principals(id) ON DELETE CASCADE,
|
|
73
|
+
expires_at INTEGER NOT NULL,
|
|
74
|
+
accepted_at INTEGER,
|
|
75
|
+
accepted_by TEXT REFERENCES principals(id) ON DELETE SET NULL,
|
|
76
|
+
-- Set by the one acceptance that won; the grant is written only for the attempt that holds it.
|
|
77
|
+
acceptance_id TEXT UNIQUE,
|
|
78
|
+
revoked_at INTEGER,
|
|
79
|
+
created_at INTEGER NOT NULL
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
-- One open invitation per (value, role, mailbox), so repeating an invitation answers the same one. The
|
|
83
|
+
-- predicate must stay character-for-character equal to the Postgres set (`ON CONFLICT` infers from it).
|
|
84
|
+
CREATE UNIQUE INDEX idx_membership_invitations_open
|
|
85
|
+
ON membership_invitations(app, scope_type, scope_value, role_key, email)
|
|
86
|
+
WHERE accepted_at IS NULL AND revoked_at IS NULL;
|
|
87
|
+
CREATE INDEX idx_membership_invitations_expires ON membership_invitations(expires_at);
|
|
88
|
+
|
|
89
|
+
-- A share link is an anonymous credential bound to a link mount and the containment chain of its object
|
|
90
|
+
-- (a JSON array of `{type, value}`, the object first). NULL on every other credential.
|
|
91
|
+
ALTER TABLE credentials ADD COLUMN link_mount TEXT;
|
|
92
|
+
ALTER TABLE credentials ADD COLUMN link_dimension TEXT;
|
|
93
|
+
ALTER TABLE credentials ADD COLUMN link_chain TEXT;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
-- Workload credentials (ADR-0022 "Principal kinds"): a job, a webhook or a connector of a contract application holds a
|
|
2
|
+
-- `px_` key of its own principal kind. SQLite/D1 dialect; `../migrations-postgres/0005_workloads.sql` states the same
|
|
3
|
+
-- outcome. Nothing written before this file is a workload.
|
|
4
|
+
|
|
5
|
+
-- A workload's identity. Its principal is a `service` row whose `external_id` is `workload:<app>:<kind>:<name>`, so the
|
|
6
|
+
-- unique index on (type, external_id) makes creating it idempotent; this row names the kind the key mints with.
|
|
7
|
+
CREATE TABLE workload_principals (
|
|
8
|
+
principal_id TEXT PRIMARY KEY REFERENCES principals(id) ON DELETE CASCADE,
|
|
9
|
+
app TEXT NOT NULL,
|
|
10
|
+
kind TEXT NOT NULL CHECK (kind IN ('job', 'webhook', 'app')),
|
|
11
|
+
name TEXT NOT NULL,
|
|
12
|
+
UNIQUE (app, kind, name)
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
-- What a schema reconcile declares for each workload: its exact actions (JSON array), app-wide. A workload key resolves
|
|
16
|
+
-- to these and nothing else; one no longer declared resolves to nothing, and the reconcile revokes its keys.
|
|
17
|
+
CREATE TABLE app_workloads (
|
|
18
|
+
app TEXT NOT NULL,
|
|
19
|
+
kind TEXT NOT NULL CHECK (kind IN ('job', 'webhook', 'app')),
|
|
20
|
+
name TEXT NOT NULL,
|
|
21
|
+
actions TEXT NOT NULL,
|
|
22
|
+
PRIMARY KEY (app, kind, name)
|
|
23
|
+
);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
-- The membership transport keys of applications on a runtime without an IAM service binding (Zerops). SQLite/D1
|
|
2
|
+
-- dialect; `../migrations-postgres/0006_membership_transport_keys.sql` states the same outcome.
|
|
3
|
+
--
|
|
4
|
+
-- A key authenticates `POST /membership/<method>` and pins the IAM application id `<app>@<env>` every call acts for.
|
|
5
|
+
-- It is no principal and no `credentials` row, so no path that resolves a `px_` credential can find it: it mints no
|
|
6
|
+
-- token and carries no authority. Only the SHA-256 hash is stored; a row exists only while the key is live, and an
|
|
7
|
+
-- issuance or a reconcile that leaves the app without a membership operation deletes the rows it supersedes.
|
|
8
|
+
CREATE TABLE membership_transport_keys (
|
|
9
|
+
id TEXT PRIMARY KEY,
|
|
10
|
+
app TEXT NOT NULL,
|
|
11
|
+
key_hash TEXT NOT NULL UNIQUE,
|
|
12
|
+
expires_at INTEGER NOT NULL,
|
|
13
|
+
created_at INTEGER NOT NULL
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
CREATE INDEX membership_transport_keys_app ON membership_transport_keys (app);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
-- A dimension's member directory (`directory: 'labels'` in the contract's vocabulary). SQLite/D1 dialect;
|
|
2
|
+
-- `../migrations-postgres/0007_member_directory.sql` states the same outcome.
|
|
3
|
+
--
|
|
4
|
+
-- `listMembers` shows a user's label (its spelling of its address) to a holder of `members.manage` only, unless the
|
|
5
|
+
-- dimension declares `labels` here: then every holder of `members.list` sees it too. Emails and invitations stay with
|
|
6
|
+
-- `members.manage`.
|
|
7
|
+
ALTER TABLE app_scopes ADD COLUMN members_directory TEXT CHECK (members_directory IS NULL OR members_directory = 'labels');
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
-- Durable audit: a logout is an `auth_log` row of its own, and a login of an installation administrator is marked
|
|
2
|
+
-- privileged. SQLite/D1 dialect; `../migrations-postgres/0008_durable_audit.sql` states the same outcome.
|
|
3
|
+
--
|
|
4
|
+
-- SQLite cannot alter a CHECK, so the table is rebuilt. Nothing references `auth_log`, and every existing row was a
|
|
5
|
+
-- login attempt that nobody marked, so it is copied as `privileged = 0`. The rowid ids are copied, so the admin
|
|
6
|
+
-- view's `before=` cursor keeps working across the migration.
|
|
7
|
+
CREATE TABLE auth_log_next (
|
|
8
|
+
id INTEGER PRIMARY KEY,
|
|
9
|
+
request_id TEXT NOT NULL,
|
|
10
|
+
app TEXT NOT NULL,
|
|
11
|
+
kind TEXT NOT NULL CHECK (kind IN ('authenticate', 'logout')),
|
|
12
|
+
principal_id TEXT REFERENCES principals(id) ON DELETE SET NULL,
|
|
13
|
+
credential_id TEXT,
|
|
14
|
+
decision TEXT NOT NULL CHECK (decision IN ('allow','deny')),
|
|
15
|
+
reason TEXT,
|
|
16
|
+
created_at INTEGER NOT NULL,
|
|
17
|
+
privileged INTEGER NOT NULL DEFAULT 0 CHECK (privileged IN (0, 1))
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
INSERT INTO auth_log_next (id, request_id, app, kind, principal_id, credential_id, decision, reason, created_at, privileged)
|
|
21
|
+
SELECT id, request_id, app, kind, principal_id, credential_id, decision, reason, created_at, 0 FROM auth_log;
|
|
22
|
+
|
|
23
|
+
DROP TABLE auth_log;
|
|
24
|
+
|
|
25
|
+
ALTER TABLE auth_log_next RENAME TO auth_log;
|
|
26
|
+
|
|
27
|
+
CREATE INDEX idx_auth_log_principal ON auth_log(principal_id, created_at);
|
|
28
|
+
CREATE INDEX idx_auth_log_request ON auth_log(request_id);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
-- The actions that look up one member of a dimension (`findMember`), from the endpoints on, in or below it that the
|
|
2
|
+
-- approved contract records under `directories`. SQLite/D1 dialect; `../migrations-postgres/0009_member_lookups.sql`
|
|
3
|
+
-- states the same outcome.
|
|
4
|
+
--
|
|
5
|
+
-- A JSON array of exact actions, or NULL for none. IAM answers a lookup only for one of them, held on the directory's
|
|
6
|
+
-- value itself, so the application names no containment IAM would have to trust.
|
|
7
|
+
ALTER TABLE app_scopes ADD COLUMN members_lookup TEXT;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
-- The link mount a job may issue links of (`issues: '<mount>'` on its `c.cron`, read from the approved artifact).
|
|
2
|
+
-- SQLite/D1 dialect; `../migrations-postgres/0010_workload_issues.sql` states the same outcome.
|
|
3
|
+
--
|
|
4
|
+
-- `issueLink` and `revokeLink` accept a job's token only while its row here names the mount; every other membership
|
|
5
|
+
-- operation still refuses a workload. NULL for a job that issues nothing, and always for a webhook or a connector.
|
|
6
|
+
ALTER TABLE app_workloads ADD COLUMN issues TEXT CHECK (issues IS NULL OR kind = 'job');
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
-- How IAM names an application to a person (`locale` and `displayName` in the contract's vocabulary), and the
|
|
2
|
+
-- application a password action returns to. SQLite/D1 dialect; `../migrations-postgres/0011_app_presentation.sql`
|
|
3
|
+
-- states the same outcome.
|
|
4
|
+
--
|
|
5
|
+
-- The schema reconcile writes `app_presentation` in its own batch; an app that declares neither field has no row.
|
|
6
|
+
-- `locale` is not checked here: IAM parses it at read and falls back to its default for a value it does not speak.
|
|
7
|
+
CREATE TABLE app_presentation (
|
|
8
|
+
app TEXT PRIMARY KEY,
|
|
9
|
+
locale TEXT,
|
|
10
|
+
display_name TEXT
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
-- The application a forgot-password request came from: its pages and mail speak the application's language, and the
|
|
14
|
+
-- completed action lands in it. NULL for an action on the installation itself, which is every row before this file.
|
|
15
|
+
ALTER TABLE password_action_tokens ADD COLUMN app TEXT;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
-- External principals and the roles they may hold (ADR-0051).
|
|
2
|
+
-- SQLite/D1 dialect; `../migrations-postgres/0012_external_principals.sql` states the same outcome.
|
|
3
|
+
--
|
|
4
|
+
-- A user is `internal` (every row written before this file) or `external`, a person from outside the organization;
|
|
5
|
+
-- a service is always `internal`. An external principal holds only grants of a role its application declares
|
|
6
|
+
-- `external`, which only a membership role reconciled from the application may be.
|
|
7
|
+
ALTER TABLE principals ADD COLUMN affiliation TEXT NOT NULL DEFAULT 'internal'
|
|
8
|
+
CHECK (affiliation IN ('internal', 'external') AND (affiliation = 'internal' OR type = 'user'));
|
|
9
|
+
ALTER TABLE roles ADD COLUMN external INTEGER NOT NULL DEFAULT 0
|
|
10
|
+
CHECK (external IN (0, 1) AND (external = 0 OR (member_scope IS NOT NULL AND origin = 'app')));
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
-- An application's wording of IAM's e-mails (`mail` in the contract's vocabulary): per message and language, the subject
|
|
2
|
+
-- and the plain-text body IAM fills and wraps in its own HTML. SQLite/D1 dialect; `../migrations-postgres/0013_app_mail_templates.sql`
|
|
3
|
+
-- states the same outcome.
|
|
4
|
+
--
|
|
5
|
+
-- The schema reconcile rewrites an app's rows in its own batch; an app that declares none has no row, and IAM sends its
|
|
6
|
+
-- catalog's wording. IAM checks a row again when it renders it and falls back to the catalog for one it refuses.
|
|
7
|
+
CREATE TABLE app_mail_templates (
|
|
8
|
+
app TEXT NOT NULL,
|
|
9
|
+
kind TEXT NOT NULL,
|
|
10
|
+
locale TEXT NOT NULL,
|
|
11
|
+
subject TEXT NOT NULL,
|
|
12
|
+
body TEXT NOT NULL,
|
|
13
|
+
PRIMARY KEY (app, kind, locale)
|
|
14
|
+
);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
-- What an invitation by address carries besides its role: the invited person's company as the inviting application
|
|
2
|
+
-- names it, and the inviter's personal message. SQLite/D1 dialect; `../migrations-postgres/0014_invitation_wording.sql`
|
|
3
|
+
-- states the same outcome.
|
|
4
|
+
--
|
|
5
|
+
-- Both are plain text IAM puts into the invitation's e-mail (`{{companyLabel}}`, `{{message}}`), escaped in its HTML
|
|
6
|
+
-- part, and keeps for a resend. NULL on every invitation before this file and on one that names neither.
|
|
7
|
+
ALTER TABLE membership_invitations ADD COLUMN company_label TEXT;
|
|
8
|
+
ALTER TABLE membership_invitations ADD COLUMN message TEXT;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
-- The revision of an application's reconciled schema and policies. SQLite/D1 dialect;
|
|
2
|
+
-- `../migrations-postgres/0015_app_schema_revisions.sql` states the same outcome.
|
|
3
|
+
--
|
|
4
|
+
-- Every schema reconcile and every custom-policy write of the app increments it in its own transaction, as its first
|
|
5
|
+
-- statement. An invitation's acceptance reads it before it checks the inviter's authority and writes only while it is
|
|
6
|
+
-- unchanged, so a reconcile between the check and the write makes the write change nothing. On Postgres the
|
|
7
|
+
-- acceptance holds the row `FOR SHARE` to its commit, and a reconcile's increment waits for it.
|
|
8
|
+
CREATE TABLE app_schema_revisions (
|
|
9
|
+
app TEXT PRIMARY KEY,
|
|
10
|
+
revision INTEGER NOT NULL
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
-- Every application IAM already holds a schema or a policy of starts at revision 1.
|
|
14
|
+
INSERT INTO app_schema_revisions (app, revision)
|
|
15
|
+
SELECT app, 1 FROM (SELECT app FROM roles UNION SELECT app FROM app_scopes UNION SELECT app FROM app_actions) known;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- The revision of a principal's grants. SQLite/D1 dialect; `../migrations-postgres/0016_principal_grant_revision.sql`
|
|
2
|
+
-- states the same outcome.
|
|
3
|
+
--
|
|
4
|
+
-- Every write that removes a grant of a principal increments it, as the first statement of its transaction. An
|
|
5
|
+
-- invitation's acceptance reads the inviter's before it checks the inviter's live permissions and writes only while it
|
|
6
|
+
-- is unchanged, so a removal of ANY grant of the inviter between the check and the write makes the write change
|
|
7
|
+
-- nothing. On Postgres the increment takes the principal row first, so it waits for an acceptance holding the row
|
|
8
|
+
-- `FOR SHARE`. Every principal before this file starts at 0.
|
|
9
|
+
ALTER TABLE principals ADD COLUMN grant_revision INTEGER NOT NULL DEFAULT 0;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
-- When each person last signed in to each application. SQLite/D1 dialect; `../migrations-postgres/0017_app_sign_ins.sql`
|
|
2
|
+
-- states the same outcome.
|
|
3
|
+
--
|
|
4
|
+
-- A sign-in to an application is the redemption of its handoff code: the child session it opens writes this row in
|
|
5
|
+
-- its own batch. IAM answers it, as `lastSignInAt`, only to a holder of `members.manage` (it is personal data, like an
|
|
6
|
+
-- address). It is not pruned with `auth_log`, and it goes with its principal. Empty for every sign-in before this file.
|
|
7
|
+
CREATE TABLE app_sign_ins (
|
|
8
|
+
app TEXT NOT NULL,
|
|
9
|
+
principal_id TEXT NOT NULL REFERENCES principals(id) ON DELETE CASCADE,
|
|
10
|
+
signed_in_at INTEGER NOT NULL,
|
|
11
|
+
PRIMARY KEY (app, principal_id)
|
|
12
|
+
);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
-- The application's own people (`members` and `directory` of the contract's vocabulary). SQLite/D1 dialect;
|
|
2
|
+
-- `../migrations-postgres/0018_app_members.sql` states the same outcome.
|
|
3
|
+
--
|
|
4
|
+
-- The schema reconcile writes the row in its own batch; an application that declares no `members` has none. A holder
|
|
5
|
+
-- of `manage`, globally at the application, grants and revokes the application's global roles through IAM's
|
|
6
|
+
-- administration API within its own actions; a holder of `list`, globally, reads every principal holding one of the
|
|
7
|
+
-- application's roles (`listAppMembers`). `directory` `labels` shows labels to `list` holders too.
|
|
8
|
+
CREATE TABLE app_members (
|
|
9
|
+
app TEXT PRIMARY KEY,
|
|
10
|
+
manage TEXT NOT NULL,
|
|
11
|
+
list TEXT NOT NULL,
|
|
12
|
+
directory TEXT CHECK (directory IS NULL OR directory = 'labels')
|
|
13
|
+
);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
-- An application's HTML body of an IAM e-mail, beside its subject and text. SQLite/D1 dialect;
|
|
2
|
+
-- `../migrations-postgres/0019_app_mail_html.sql` states the same outcome.
|
|
3
|
+
--
|
|
4
|
+
-- The closed HTML subset of `mailHtmlTokens` (`@fabrika/auth-core`): IAM checks it at the reconcile and again at render,
|
|
5
|
+
-- renders it from its tokens with every value escaped and the action link put in, and falls back to its catalog for a
|
|
6
|
+
-- row it refuses. NULL on every row before this file and on one that declares no HTML: IAM builds the HTML part itself.
|
|
7
|
+
ALTER TABLE app_mail_templates ADD COLUMN html TEXT;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
-- A public procedure is a workload of its own (`public`, named by its endpoint id): Control issues its key, and IAM
|
|
2
|
+
-- signs its token with the actions the schema declares for it. SQLite/D1 dialect;
|
|
3
|
+
-- `../migrations-postgres/0020_public_workloads.sql` states the same outcome.
|
|
4
|
+
--
|
|
5
|
+
-- SQLite cannot alter a CHECK, so both tables are rebuilt with every row copied as it is. Nothing references either
|
|
6
|
+
-- table; `workload_principals` keeps its cascade from `principals`.
|
|
7
|
+
CREATE TABLE workload_principals_next (
|
|
8
|
+
principal_id TEXT PRIMARY KEY REFERENCES principals(id) ON DELETE CASCADE,
|
|
9
|
+
app TEXT NOT NULL,
|
|
10
|
+
kind TEXT NOT NULL CHECK (kind IN ('job', 'webhook', 'public', 'app')),
|
|
11
|
+
name TEXT NOT NULL,
|
|
12
|
+
UNIQUE (app, kind, name)
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
INSERT INTO workload_principals_next (principal_id, app, kind, name) SELECT principal_id, app, kind, name FROM workload_principals;
|
|
16
|
+
|
|
17
|
+
DROP TABLE workload_principals;
|
|
18
|
+
|
|
19
|
+
ALTER TABLE workload_principals_next RENAME TO workload_principals;
|
|
20
|
+
|
|
21
|
+
CREATE TABLE app_workloads_next (
|
|
22
|
+
app TEXT NOT NULL,
|
|
23
|
+
kind TEXT NOT NULL CHECK (kind IN ('job', 'webhook', 'public', 'app')),
|
|
24
|
+
name TEXT NOT NULL,
|
|
25
|
+
actions TEXT NOT NULL,
|
|
26
|
+
issues TEXT CHECK (issues IS NULL OR kind = 'job'),
|
|
27
|
+
PRIMARY KEY (app, kind, name)
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
INSERT INTO app_workloads_next (app, kind, name, actions, issues) SELECT app, kind, name, actions, issues FROM app_workloads;
|
|
31
|
+
|
|
32
|
+
DROP TABLE app_workloads;
|
|
33
|
+
|
|
34
|
+
ALTER TABLE app_workloads_next RENAME TO app_workloads;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
-- The installation's client logo on fabrika's own pages (ADR-0066). SQLite/D1 dialect;
|
|
2
|
+
-- `../migrations-postgres/0021_installation_brand.sql` states the same outcome.
|
|
3
|
+
--
|
|
4
|
+
-- An installation serves one client, so this is one row or none: `id` is always 1. An installation administrator sets
|
|
5
|
+
-- it through IAM's administration API, which checks each image with `brandImageProblem` (`@fabrika/proxy-core/brand`)
|
|
6
|
+
-- and IAM checks it again at every read, so the image types are not checked here. A clear keeps the row with no
|
|
7
|
+
-- images, so `updated_at` still says when the brand last changed. No row, or a row without a light image, is no brand:
|
|
8
|
+
-- the pages draw the fabrika mark, as every installation did before this file.
|
|
9
|
+
CREATE TABLE installation_brand (
|
|
10
|
+
id INTEGER PRIMARY KEY CHECK (id = 1),
|
|
11
|
+
light_type TEXT,
|
|
12
|
+
light_base64 TEXT,
|
|
13
|
+
dark_type TEXT,
|
|
14
|
+
dark_base64 TEXT,
|
|
15
|
+
updated_at INTEGER NOT NULL,
|
|
16
|
+
CHECK ((light_type IS NULL) = (light_base64 IS NULL)),
|
|
17
|
+
CHECK ((dark_type IS NULL) = (dark_base64 IS NULL)),
|
|
18
|
+
CHECK (dark_type IS NULL OR light_type IS NOT NULL)
|
|
19
|
+
);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
-- The installation's minimum password length (ADR-0020). SQLite/D1 dialect;
|
|
2
|
+
-- `../migrations-postgres/0022_password_policy.sql` states the same outcome.
|
|
3
|
+
--
|
|
4
|
+
-- One minimum for every principal of the installation, so this is one row or none: `id` is always 1. An installation
|
|
5
|
+
-- administrator sets it through IAM's administration API, which also holds it to the runtime's floor (15 where the
|
|
6
|
+
-- verifiers are cheaper than OWASP's PBKDF2 cost); the CHECK is only the widest range any runtime accepts. No row is the
|
|
7
|
+
-- default of 15, which every installation applied before this file.
|
|
8
|
+
CREATE TABLE password_policy (
|
|
9
|
+
id INTEGER PRIMARY KEY CHECK (id = 1),
|
|
10
|
+
min_length INTEGER NOT NULL CHECK (min_length BETWEEN 4 AND 256),
|
|
11
|
+
updated_at INTEGER NOT NULL
|
|
12
|
+
);
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
-- Terminals (ADR-0067): a browser an administrator enrolled, on which an application asserts which person is at it.
|
|
2
|
+
-- SQLite/D1 dialect; `../migrations-postgres/0023_terminals.sql` states the same outcome.
|
|
3
|
+
--
|
|
4
|
+
-- A terminal is a `service` principal with this side table, as a workload is. Only the hash of its cookie is stored.
|
|
5
|
+
-- `session_ttl` is how long a person's session on it lasts, in seconds, at most one hour.
|
|
6
|
+
CREATE TABLE terminals (
|
|
7
|
+
principal_id TEXT PRIMARY KEY REFERENCES principals(id) ON DELETE CASCADE,
|
|
8
|
+
label TEXT NOT NULL,
|
|
9
|
+
enrolled_by TEXT REFERENCES principals(id) ON DELETE SET NULL,
|
|
10
|
+
token_hash TEXT NOT NULL UNIQUE,
|
|
11
|
+
session_ttl INTEGER NOT NULL CHECK (session_ttl > 0 AND session_ttl <= 3600),
|
|
12
|
+
created_at INTEGER NOT NULL,
|
|
13
|
+
last_seen_at INTEGER,
|
|
14
|
+
revoked_at INTEGER
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
-- The applications that may assert a person on a terminal, each with its ceiling: a JSON array of the action patterns
|
|
18
|
+
-- of the person's own permissions that survive there. An application without a row asserts nothing on the terminal.
|
|
19
|
+
CREATE TABLE terminal_asserters (
|
|
20
|
+
terminal_id TEXT NOT NULL REFERENCES terminals(principal_id) ON DELETE CASCADE,
|
|
21
|
+
app TEXT NOT NULL,
|
|
22
|
+
ceiling TEXT NOT NULL,
|
|
23
|
+
PRIMARY KEY (terminal_id, app)
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
-- One identification: IAM sent the terminal's browser to `app` to identify the person, carrying the proxy-started
|
|
27
|
+
-- handoff. Single use (`consumed_at`), and only its id's hash is stored.
|
|
28
|
+
CREATE TABLE terminal_identifications (
|
|
29
|
+
id_hash TEXT PRIMARY KEY,
|
|
30
|
+
terminal_id TEXT NOT NULL REFERENCES terminals(principal_id) ON DELETE CASCADE,
|
|
31
|
+
app TEXT NOT NULL,
|
|
32
|
+
return_url TEXT NOT NULL,
|
|
33
|
+
handoff_state TEXT NOT NULL,
|
|
34
|
+
handoff_challenge TEXT NOT NULL,
|
|
35
|
+
created_at INTEGER NOT NULL,
|
|
36
|
+
expires_at INTEGER NOT NULL,
|
|
37
|
+
consumed_at INTEGER
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
CREATE INDEX idx_terminal_identifications_terminal ON terminal_identifications(terminal_id);
|
|
41
|
+
CREATE INDEX idx_terminal_identifications_expires ON terminal_identifications(expires_at);
|
|
42
|
+
|
|
43
|
+
-- A login on a terminal carries its terminal and the application that asserted the person. SQLite cannot change a
|
|
44
|
+
-- CHECK, so `sessions` is rebuilt with every row copied as it is. `auth_codes` and `oauth_grants` reference it, and
|
|
45
|
+
-- `oauth_codes` and `oauth_refresh_tokens` reference `oauth_grants`: their rows are kept aside and restored, so
|
|
46
|
+
-- dropping the old tables cascades into nothing. The rebuilt table names itself as the parent of a child session, and
|
|
47
|
+
-- the rename carries that reference over; roots are copied before the children that reference them.
|
|
48
|
+
CREATE TABLE oauth_codes_kept AS SELECT * FROM oauth_codes;
|
|
49
|
+
CREATE TABLE oauth_refresh_tokens_kept AS SELECT * FROM oauth_refresh_tokens;
|
|
50
|
+
CREATE TABLE oauth_grants_kept AS SELECT * FROM oauth_grants;
|
|
51
|
+
CREATE TABLE auth_codes_kept AS SELECT * FROM auth_codes;
|
|
52
|
+
DROP TABLE oauth_codes;
|
|
53
|
+
DROP TABLE oauth_refresh_tokens;
|
|
54
|
+
DROP TABLE oauth_grants;
|
|
55
|
+
DROP TABLE auth_codes;
|
|
56
|
+
|
|
57
|
+
CREATE TABLE sessions_rebuilt (
|
|
58
|
+
id TEXT PRIMARY KEY,
|
|
59
|
+
token_hash TEXT NOT NULL UNIQUE,
|
|
60
|
+
principal_id TEXT NOT NULL REFERENCES principals(id) ON DELETE CASCADE,
|
|
61
|
+
idp_sub TEXT,
|
|
62
|
+
email TEXT,
|
|
63
|
+
authentication_method TEXT NOT NULL CHECK (authentication_method IN ('oidc', 'password', 'local_dev', 'terminal_assertion')),
|
|
64
|
+
created_at INTEGER NOT NULL,
|
|
65
|
+
expires_at INTEGER NOT NULL,
|
|
66
|
+
revoked_at INTEGER,
|
|
67
|
+
app TEXT,
|
|
68
|
+
parent_session_id TEXT REFERENCES sessions_rebuilt(id) ON DELETE CASCADE,
|
|
69
|
+
terminal_id TEXT REFERENCES terminals(principal_id) ON DELETE CASCADE,
|
|
70
|
+
asserted_by TEXT,
|
|
71
|
+
CHECK (
|
|
72
|
+
(authentication_method IN ('oidc', 'local_dev') AND idp_sub IS NOT NULL)
|
|
73
|
+
OR (authentication_method IN ('password', 'terminal_assertion') AND idp_sub IS NULL)
|
|
74
|
+
),
|
|
75
|
+
CHECK (
|
|
76
|
+
(authentication_method = 'terminal_assertion' AND terminal_id IS NOT NULL AND asserted_by IS NOT NULL)
|
|
77
|
+
OR (authentication_method <> 'terminal_assertion' AND terminal_id IS NULL AND asserted_by IS NULL)
|
|
78
|
+
)
|
|
79
|
+
);
|
|
80
|
+
INSERT INTO sessions_rebuilt (
|
|
81
|
+
id, token_hash, principal_id, idp_sub, email, authentication_method, created_at, expires_at, revoked_at, app, parent_session_id
|
|
82
|
+
)
|
|
83
|
+
SELECT id, token_hash, principal_id, idp_sub, email, authentication_method, created_at, expires_at, revoked_at, app, parent_session_id
|
|
84
|
+
FROM sessions
|
|
85
|
+
ORDER BY parent_session_id IS NOT NULL;
|
|
86
|
+
DROP TABLE sessions;
|
|
87
|
+
ALTER TABLE sessions_rebuilt RENAME TO sessions;
|
|
88
|
+
CREATE INDEX idx_sessions_principal ON sessions(principal_id);
|
|
89
|
+
CREATE INDEX idx_sessions_expires ON sessions(expires_at);
|
|
90
|
+
CREATE INDEX idx_sessions_principal_method ON sessions(principal_id, authentication_method);
|
|
91
|
+
CREATE INDEX idx_sessions_parent ON sessions(parent_session_id);
|
|
92
|
+
CREATE INDEX idx_sessions_terminal ON sessions(terminal_id) WHERE terminal_id IS NOT NULL;
|
|
93
|
+
|
|
94
|
+
CREATE TABLE auth_codes (
|
|
95
|
+
id TEXT PRIMARY KEY, -- UUIDv7, minted caller-side
|
|
96
|
+
code_hash TEXT NOT NULL UNIQUE, -- SHA-256; the plaintext lives in one redirect
|
|
97
|
+
app TEXT NOT NULL,
|
|
98
|
+
parent_session_id TEXT NOT NULL REFERENCES sessions(id) ON DELETE CASCADE,
|
|
99
|
+
return_url TEXT NOT NULL, -- carried server-side so redemption cannot be pointed elsewhere
|
|
100
|
+
expires_at INTEGER NOT NULL,
|
|
101
|
+
consumed_at INTEGER,
|
|
102
|
+
created_at INTEGER NOT NULL
|
|
103
|
+
);
|
|
104
|
+
INSERT INTO auth_codes (id, code_hash, app, parent_session_id, return_url, expires_at, consumed_at, created_at)
|
|
105
|
+
SELECT id, code_hash, app, parent_session_id, return_url, expires_at, consumed_at, created_at FROM auth_codes_kept;
|
|
106
|
+
DROP TABLE auth_codes_kept;
|
|
107
|
+
CREATE INDEX idx_auth_codes_expires ON auth_codes(expires_at);
|
|
108
|
+
|
|
109
|
+
CREATE TABLE oauth_grants (
|
|
110
|
+
id TEXT PRIMARY KEY,
|
|
111
|
+
principal_id TEXT NOT NULL REFERENCES principals(id) ON DELETE CASCADE,
|
|
112
|
+
session_id TEXT NOT NULL REFERENCES sessions(id) ON DELETE CASCADE,
|
|
113
|
+
client_id TEXT NOT NULL,
|
|
114
|
+
app TEXT NOT NULL,
|
|
115
|
+
resource TEXT NOT NULL,
|
|
116
|
+
scopes TEXT NOT NULL,
|
|
117
|
+
created_at INTEGER NOT NULL,
|
|
118
|
+
expires_at INTEGER NOT NULL,
|
|
119
|
+
revoked_at INTEGER
|
|
120
|
+
);
|
|
121
|
+
INSERT INTO oauth_grants (id, principal_id, session_id, client_id, app, resource, scopes, created_at, expires_at, revoked_at)
|
|
122
|
+
SELECT id, principal_id, session_id, client_id, app, resource, scopes, created_at, expires_at, revoked_at FROM oauth_grants_kept;
|
|
123
|
+
DROP TABLE oauth_grants_kept;
|
|
124
|
+
CREATE INDEX idx_oauth_grants_session ON oauth_grants(session_id);
|
|
125
|
+
CREATE INDEX idx_oauth_grants_principal ON oauth_grants(principal_id);
|
|
126
|
+
|
|
127
|
+
CREATE TABLE oauth_codes (
|
|
128
|
+
token_hash TEXT PRIMARY KEY,
|
|
129
|
+
grant_id TEXT NOT NULL REFERENCES oauth_grants(id) ON DELETE CASCADE,
|
|
130
|
+
redirect_uri TEXT NOT NULL,
|
|
131
|
+
challenge TEXT NOT NULL,
|
|
132
|
+
expires_at INTEGER NOT NULL,
|
|
133
|
+
used_at INTEGER
|
|
134
|
+
);
|
|
135
|
+
INSERT INTO oauth_codes (token_hash, grant_id, redirect_uri, challenge, expires_at, used_at)
|
|
136
|
+
SELECT token_hash, grant_id, redirect_uri, challenge, expires_at, used_at FROM oauth_codes_kept;
|
|
137
|
+
DROP TABLE oauth_codes_kept;
|
|
138
|
+
CREATE INDEX idx_oauth_codes_grant ON oauth_codes(grant_id);
|
|
139
|
+
CREATE INDEX idx_oauth_codes_expires ON oauth_codes(expires_at);
|
|
140
|
+
|
|
141
|
+
CREATE TABLE oauth_refresh_tokens (
|
|
142
|
+
token_hash TEXT PRIMARY KEY,
|
|
143
|
+
grant_id TEXT NOT NULL REFERENCES oauth_grants(id) ON DELETE CASCADE,
|
|
144
|
+
expires_at INTEGER NOT NULL,
|
|
145
|
+
used_at INTEGER
|
|
146
|
+
);
|
|
147
|
+
INSERT INTO oauth_refresh_tokens (token_hash, grant_id, expires_at, used_at)
|
|
148
|
+
SELECT token_hash, grant_id, expires_at, used_at FROM oauth_refresh_tokens_kept;
|
|
149
|
+
DROP TABLE oauth_refresh_tokens_kept;
|
|
150
|
+
CREATE INDEX idx_oauth_refresh_tokens_grant ON oauth_refresh_tokens(grant_id);
|
|
151
|
+
CREATE INDEX idx_oauth_refresh_tokens_expires ON oauth_refresh_tokens(expires_at);
|
|
152
|
+
|
|
153
|
+
-- Every `auth_log` row of a terminal session names the terminal and the asserting application, read from the session.
|
|
154
|
+
ALTER TABLE auth_log ADD COLUMN terminal_id TEXT;
|
|
155
|
+
ALTER TABLE auth_log ADD COLUMN asserted_by TEXT;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
-- The identification page of an application that identifies people at enrolled terminals (`terminal` of the
|
|
2
|
+
-- contract's vocabulary, ADR-0067). SQLite/D1 dialect; `../migrations-postgres/0024_app_terminals.sql` states the same outcome.
|
|
3
|
+
--
|
|
4
|
+
-- The schema reconcile writes the row in its own batch; an application that declares no terminal has none, and IAM
|
|
5
|
+
-- never sends a terminal's browser to it. `identify` is an absolute path on the application's own origin, which IAM
|
|
6
|
+
-- resolves against the sign-in's return origin.
|
|
7
|
+
CREATE TABLE app_terminals (
|
|
8
|
+
app TEXT PRIMARY KEY,
|
|
9
|
+
identify TEXT NOT NULL CHECK (identify LIKE '/%')
|
|
10
|
+
);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
-- The completion of a terminal identification (ADR-0067 §3). SQLite/D1 dialect;
|
|
2
|
+
-- `../migrations-postgres/0025_terminal_completion.sql` states the same outcome.
|
|
3
|
+
--
|
|
4
|
+
-- An assertion no longer hands the application a code. It records the login it opened in `session_id`, and the
|
|
5
|
+
-- terminal's own browser completes the identification at IAM (`completed_at`), which only then issues the code.
|
|
6
|
+
-- `session_id` has no foreign key: the assertion's batch writes it before the login row, and the completion reads the
|
|
7
|
+
-- login through the session validity rule, which answers nothing for a login that is gone.
|
|
8
|
+
ALTER TABLE terminal_identifications ADD COLUMN session_id TEXT;
|
|
9
|
+
|
|
10
|
+
ALTER TABLE terminal_identifications ADD COLUMN completed_at INTEGER;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
-- The generation of a terminal (ADR-0067 §5). SQLite/D1 dialect; `../migrations-postgres/0026_terminal_generation.sql` states
|
|
2
|
+
-- the same outcome.
|
|
3
|
+
--
|
|
4
|
+
-- A release or a revocation of a terminal ends every session and identification of its current generation. A release
|
|
5
|
+
-- increments `terminals.generation`; an identification records the generation it was opened in, a login on the
|
|
6
|
+
-- terminal the generation of its identification, and a session is valid only while that is still the terminal's. So an
|
|
7
|
+
-- assertion that raced a release opens a login that is already invalid, whichever transaction commits first.
|
|
8
|
+
ALTER TABLE terminals ADD COLUMN generation INTEGER NOT NULL DEFAULT 0;
|
|
9
|
+
|
|
10
|
+
ALTER TABLE terminal_identifications ADD COLUMN generation INTEGER NOT NULL DEFAULT 0;
|
|
11
|
+
|
|
12
|
+
ALTER TABLE sessions ADD COLUMN terminal_generation INTEGER;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
-- A contract application's authority is exact actions of its approved catalog (the authorization model's Layer 1):
|
|
2
|
+
-- from this release IAM resolves no wildcard at a contract application, so a pattern can no longer track the catalog
|
|
3
|
+
-- beyond the approved revision. Writes have refused one since 0003; this file is the preflight for rows older than
|
|
4
|
+
-- that. SQLite/D1 dialect; `../migrations-postgres/0027_application_exact_actions.sql` states the same outcome.
|
|
5
|
+
--
|
|
6
|
+
-- No outcome would be correct for such a row: dropping it loses authority, expanding it guesses which revision it
|
|
7
|
+
-- meant. So the file REFUSES while one exists — an inline grant or a role of the app that names a pattern, a grant of
|
|
8
|
+
-- the built-in `admin`, or a key's frozen pattern — and the deploy stops with the old release serving. Resolve each
|
|
9
|
+
-- row with exact actions (or remove it), then deploy again. Expired rows count too.
|
|
10
|
+
CREATE TABLE IF NOT EXISTS iam_preflight_exact_actions (
|
|
11
|
+
app TEXT,
|
|
12
|
+
CONSTRAINT "contract app holds a wildcard: give it exact actions first"
|
|
13
|
+
CHECK (app IS NULL)
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
INSERT INTO iam_preflight_exact_actions (app)
|
|
17
|
+
SELECT g.app FROM grants g JOIN contract_apps c ON c.app = g.app
|
|
18
|
+
WHERE g.permissions LIKE '%*%' OR g.role_key = 'admin';
|
|
19
|
+
|
|
20
|
+
INSERT INTO iam_preflight_exact_actions (app)
|
|
21
|
+
SELECT r.app FROM roles r JOIN contract_apps c ON c.app = r.app
|
|
22
|
+
WHERE r.permissions LIKE '%*%';
|
|
23
|
+
|
|
24
|
+
INSERT INTO iam_preflight_exact_actions (app)
|
|
25
|
+
SELECT k.app FROM credential_grants cg JOIN credentials k ON k.id = cg.credential_id JOIN contract_apps c ON c.app = k.app
|
|
26
|
+
WHERE cg.action LIKE '%*%';
|
|
27
|
+
|
|
28
|
+
DROP TABLE iam_preflight_exact_actions;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
-- The `jti` of every accepted `private_key_jwt` client assertion (RFC 7523 §3), kept until the assertion's
|
|
2
|
+
-- own `exp` so a replayed assertion is refused. SQLite/D1 dialect;
|
|
3
|
+
-- `../migrations-postgres/0028_oauth_client_assertions.sql` states the same outcome.
|
|
4
|
+
CREATE TABLE oauth_client_assertions (
|
|
5
|
+
client_id TEXT NOT NULL,
|
|
6
|
+
jti TEXT NOT NULL,
|
|
7
|
+
expires_at INTEGER NOT NULL,
|
|
8
|
+
PRIMARY KEY (client_id, jti)
|
|
9
|
+
);
|
|
10
|
+
CREATE INDEX idx_oauth_client_assertions_expires ON oauth_client_assertions(expires_at);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
-- A role's relations (`via`): relation → exact actions a GLOBAL grant of the role also carries as `~rel` entries, which an
|
|
2
|
+
-- application holds where one of its rows names the principal in that relation. SQLite/D1 dialect;
|
|
3
|
+
-- `../migrations-postgres/0029_role_via.sql` states the same outcome. NULL (every row before this file) is none; only an
|
|
4
|
+
-- application-wide internal role reconciled from the application declares one.
|
|
5
|
+
ALTER TABLE roles ADD COLUMN via TEXT
|
|
6
|
+
CHECK (via IS NULL OR (member_scope IS NULL AND external = 0 AND origin = 'app'));
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
-- A membership role may hold actions through a relation (`via`): a grant of it at a value carries them as `~relin`
|
|
2
|
+
-- entries, held only inside that value. SQLite/D1 dialect; `../migrations-postgres/0030_membership_role_via.sql` states
|
|
3
|
+
-- the same outcome. The column's CHECK no longer requires `member_scope IS NULL`; an external role still declares no
|
|
4
|
+
-- `via` (ADR-0051). SQLite changes a column's CHECK only by dropping the column, so the values are carried over through
|
|
5
|
+
-- a scratch column. No row changes: every row satisfied the stricter CHECK.
|
|
6
|
+
ALTER TABLE roles ADD COLUMN via_0030 TEXT;
|
|
7
|
+
UPDATE roles SET via_0030 = via;
|
|
8
|
+
ALTER TABLE roles DROP COLUMN via;
|
|
9
|
+
ALTER TABLE roles ADD COLUMN via TEXT
|
|
10
|
+
CHECK (via IS NULL OR (external = 0 AND origin = 'app'));
|
|
11
|
+
UPDATE roles SET via = via_0030;
|
|
12
|
+
ALTER TABLE roles DROP COLUMN via_0030;
|