Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/libs/db/migrator/src/bootstrap_roles.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Convergent provisioning of control-plane Postgres roles

Check warning on line 1 in crates/libs/db/migrator/src/bootstrap_roles.rs

View workflow job for this annotation

GitHub Actions / rust_static / Rust clippy

[archcheck] reported by reviewdog 🐶 crates/libs/db/migrator/src/bootstrap_roles.rs grew from 1202 to 1204 code lines. Once this rule is required, split the file before adding to it. Raw Output: message:"crates/libs/db/migrator/src/bootstrap_roles.rs grew from 1202 to 1204 code lines. Once this rule is required, split the file before adding to it." location:{path:"crates/libs/db/migrator/src/bootstrap_roles.rs" range:{start:{line:1}}} severity:WARNING source:{name:"archcheck"} code:{value:"file_size.listed_no_growth"}
//!
//! `space-db-migrator bootstrap-roles` is the single owner of role
//! provisioning for the control-plane database. Every run converges the
Expand Down Expand Up @@ -110,6 +110,7 @@
("sessions", &["token_hash"]),
("api_keys", &["key_hash"]),
("data_plane_sessions", &["token_hash"]),
("data_plane_session_tokens", &["token_hash"]),
("sandbox_federated_service_grants", &["grant_blob"]),
("template_system_publication_grants", &["id"]),
("template_tenant_publication_grants", &["id"]),
Expand Down
8 changes: 8 additions & 0 deletions db/postgres/20261021182104_data_plane_session_tokens.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
SET LOCAL lock_timeout = '5s';
SET LOCAL statement_timeout = '60s';

-- Reverting drops every token a replay minted beyond the session's latest,
-- which `data_plane_sessions.token_hash` still holds. Roll the API and
-- internal-api releases back with this migration: a release that writes the
-- table fails its session creates and replays once the table is gone.
DROP TABLE IF EXISTS data_plane_session_tokens;
23 changes: 23 additions & 0 deletions db/postgres/20261021182104_data_plane_session_tokens.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
SET LOCAL lock_timeout = '5s';
SET LOCAL statement_timeout = '60s';

-- Live attach tokens of a data-plane session, one row per token.
--
-- Replaying a session's create with the same idempotency key mints another
-- token for the same session. Each token stays valid until its own
-- `expires_at`, so a replay no longer invalidates the tokens earlier replays
-- returned. `data_plane_sessions.token_hash` and `token_expires_at` keep
-- naming the most recent token while servers that read only those columns are
-- still deployed; validators consult this table first and fall back to them.
CREATE TABLE IF NOT EXISTS data_plane_session_tokens (
-- SHA-256 hex digest of the bearer token; the raw token is never stored.
token_hash text PRIMARY KEY,
session_id text NOT NULL REFERENCES data_plane_sessions (session_id) ON DELETE CASCADE,
expires_at timestamptz NOT NULL,
created_at timestamptz NOT NULL DEFAULT now()
);

-- Replays prune and cap a session's tokens by expiry, and the session
-- foreign key's cascade finds its rows through the leading column.
CREATE INDEX IF NOT EXISTS idx_data_plane_session_tokens_session_id_expires_at
ON data_plane_session_tokens (session_id, expires_at);
Loading