feat(db): add SQLite persistence layer, migrations, and crypto #10

Merged
David merged 1 commit from feat/sqlite-crypto-layer into main 2026-06-14 21:38:33 +02:00
Owner

Add the durable-state foundation the multi-user HTTP transport (YTMCP-6) consumes, with no web wiring yet.

New src/db/: mod.rs opens a SqlitePool (foreign keys on, create-if-missing) and runs the embedded 0001_initial.sql migration via sqlx::migrate!, creating users, hub_tokens, oauth_clients, authorization_codes, access_tokens, refresh_tokens, settings, and allowlist. Provides typed CRUD per table (upsert/get/revoke/consume), single-use authorization-code redemption as a replay guard, and sweep_expired to prune spent codes and expired tokens on a timer. All timestamps are unix seconds; tokens and codes are stored only as hashes, Hub tokens only as AEAD ciphertext.

New src/crypto.rs: XChaCha20-Poly1305 AEAD encrypt/decrypt keyed by the base64 YT_MCP_MASTER_KEY, CSPRNG token/code generation, SHA-256 at-rest hashing, and constant-time PKCE S256 verification.

Deps: sqlx 0.9 (default-features off; runtime-tokio, tls-rustls, sqlite, macros, migrate), chacha20poly1305 0.10, rand 0.8, sha2 0.10, base64 0.22, time. No OpenSSL or native-tls in the lockfile: TLS is rustls and SQLite is bundled.

Unit tests cover AEAD round-trip/tamper/wrong-key, PKCE S256 (RFC 7636 vector), token hashing, the migration set, foreign-key enforcement, single-use code redemption, access-token validity, and expiry pruning. New modules carry allow(dead_code) until YTMCP-6 wires them up so the -D warnings gate stays green.

#YTMCP-4

Add the durable-state foundation the multi-user HTTP transport (YTMCP-6) consumes, with no web wiring yet. New `src/db/`: `mod.rs` opens a `SqlitePool` (foreign keys on, create-if-missing) and runs the embedded `0001_initial.sql` migration via `sqlx::migrate!`, creating users, hub_tokens, oauth_clients, authorization_codes, access_tokens, refresh_tokens, settings, and allowlist. Provides typed CRUD per table (upsert/get/revoke/consume), single-use authorization-code redemption as a replay guard, and `sweep_expired` to prune spent codes and expired tokens on a timer. All timestamps are unix seconds; tokens and codes are stored only as hashes, Hub tokens only as AEAD ciphertext. New `src/crypto.rs`: XChaCha20-Poly1305 AEAD encrypt/decrypt keyed by the base64 `YT_MCP_MASTER_KEY`, CSPRNG token/code generation, SHA-256 at-rest hashing, and constant-time PKCE S256 verification. Deps: sqlx 0.9 (default-features off; runtime-tokio, tls-rustls, sqlite, macros, migrate), chacha20poly1305 0.10, rand 0.8, sha2 0.10, base64 0.22, time. No OpenSSL or native-tls in the lockfile: TLS is rustls and SQLite is bundled. Unit tests cover AEAD round-trip/tamper/wrong-key, PKCE S256 (RFC 7636 vector), token hashing, the migration set, foreign-key enforcement, single-use code redemption, access-token validity, and expiry pruning. New modules carry `allow(dead_code)` until YTMCP-6 wires them up so the `-D warnings` gate stays green. #YTMCP-4
feat(db): add SQLite persistence layer, migrations, and crypto
All checks were successful
Check / fmt + clippy + build + tests (pull_request) Successful in 22s
Create release / Create release from merged PR (pull_request) Has been skipped
ac2def634e
Add the durable-state foundation the multi-user HTTP transport (YTMCP-6) consumes, with no web wiring yet.

New `src/db/`: `mod.rs` opens a `SqlitePool` (foreign keys on, create-if-missing) and runs the embedded `0001_initial.sql` migration via `sqlx::migrate!`, creating users, hub_tokens, oauth_clients, authorization_codes, access_tokens, refresh_tokens, settings, and allowlist. Provides typed CRUD per table (upsert/get/revoke/consume), single-use authorization-code redemption as a replay guard, and `sweep_expired` to prune spent codes and expired tokens on a timer. All timestamps are unix seconds; tokens and codes are stored only as hashes, Hub tokens only as AEAD ciphertext.

New `src/crypto.rs`: XChaCha20-Poly1305 AEAD encrypt/decrypt keyed by the base64 `YT_MCP_MASTER_KEY`, CSPRNG token/code generation, SHA-256 at-rest hashing, and constant-time PKCE S256 verification.

Deps: sqlx 0.9 (default-features off; runtime-tokio, tls-rustls, sqlite, macros, migrate), chacha20poly1305 0.10, rand 0.8, sha2 0.10, base64 0.22, time. No OpenSSL or native-tls in the lockfile: TLS is rustls and SQLite is bundled.

Unit tests cover AEAD round-trip/tamper/wrong-key, PKCE S256 (RFC 7636 vector), token hashing, the migration set, foreign-key enforcement, single-use code redemption, access-token validity, and expiry pruning. New modules carry `allow(dead_code)` until YTMCP-6 wires them up so the `-D warnings` gate stays green.

#YTMCP-4
David merged commit f223658502 into main 2026-06-14 21:38:33 +02:00
David deleted branch feat/sqlite-crypto-layer 2026-06-14 21:38:33 +02:00
Commenting is not possible because the repository is archived.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
pandoras-box/youtrack-mcp!10
No description provided.