mirror of
https://github.com/profullstack/logicsrc.git
synced 2026-11-30 17:07:50 +00:00
A person's lsk_ key acts as the person, with one identity key per user. Logging a fresh box in with `login --token` uploaded the box's new keypair as the person's identity and replaced the real one. Machine keys fix that: a key made for a box, scoped to one team (and optionally named vaults), read-only unless --read-write, optionally expiring, with its OWN identity key registered on the key row. A vault key reaches it as a grant sealed to that public key (credshare_key_grants), never through the person. Schema (005_machine_keys, SQLite + Postgres): api_keys gains kind, team_id, vault_scope, read_only (default 0, so existing person keys keep writing), expires_at, public_key; new credshare_key_grants; credshare_audit.actor_key_id. Server: each credshare route declares what a machine key may do (read / write / register); the rest are people-only. Machine keys see only their team and scoped vaults, read their grant from credshare_key_grants (audited as vault:read with the key id), are refused every write when read-only, and cannot mint/list/revoke keys, read /api/me or touch the personal vault. Expired and revoked keys are 401. New GET|POST /api/keys, DELETE /api/keys/:id, and GET|POST|DELETE /api/credshare/vaults/:id/key-grants. A re-key re-seals the machine grants it is given and drops the rest. CLI 0.8.0: `logicsrc keys create|list|revoke` (--team, --vault, --read-only / --read-write, --expires, --out 0600); LOGICSRC_API_KEY and `login --api-key` with a per-key identity in keys/<prefix>.json (0600), generated and registered on first use; `login --token` with a machine key takes that path instead of replacing the person's key; `teams grant … --key <name>`; `credentials rotate` re-seals machine keys. PWA: settings creates machine keys (team, vaults, read-only, expiry); a vault page grants or revokes a machine key in the browser after unlock. MCP: list_api_keys / create_api_key / revoke_api_key over /api/keys with a Bearer LOGICSRC_API_KEY. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
49 lines
2.4 KiB
Markdown
49 lines
2.4 KiB
Markdown
# @logicsrc/pwa — LogicSRC credentials
|
|
|
|
Express app on Postgres for **team credential sharing**: auth (email/password,
|
|
passkeys, CoinPay OAuth, sessions, `lsk_` CLI API keys) + end-to-end-encrypted
|
|
team vaults. Zero-knowledge — the server only stores ciphertext, per-member
|
|
sealed vault keys, and identity public keys. Decryption happens in the
|
|
`logicsrc` CLI.
|
|
|
|
```bash
|
|
cp .env.example .env # set SESSION_SECRET; DATABASE_URL=postgres://… for prod (else a local libSQL file db)
|
|
npm install
|
|
npm start # migrates on boot, serves on :8080
|
|
```
|
|
|
|
## Database
|
|
|
|
Production runs on Postgres: `DATABASE_URL` must be a `postgres://` URL and the
|
|
app refuses to start on anything else there (a leftover `libsql://` value is
|
|
called out by name). The client is
|
|
[`@profullstack/libsql-pg`](https://github.com/profullstack/libsql-pg), which
|
|
keeps the `@libsql/client` surface the code was written against and rewrites
|
|
the remaining SQLite idioms per statement. Development and the tests use libSQL
|
|
itself (`file:./data/local.db` by default, `:memory:` in tests).
|
|
|
|
Migrations run at boot and live in two dialect copies with the same file names:
|
|
`src/migrations/` (SQLite) and `src/migrations-pg/` (Postgres, generated with
|
|
`npx libsql-pg convert-schema` and reviewed). `npm run migrate` applies the copy
|
|
matching `DATABASE_URL`. To move an existing Turso database:
|
|
|
|
```bash
|
|
DATABASE_URL=postgres://… npm run migrate # schema
|
|
npx libsql-pg copy --from "$TURSO_DATABASE_URL" --token "$TURSO_AUTH_TOKEN" \
|
|
--to "$DATABASE_URL" --verify # rows
|
|
```
|
|
|
|
Set `PWA_TEST_DATABASE_URL=postgres://…` to run the test suite against a real
|
|
Postgres (it drops and recreates the `public` schema of that database).
|
|
|
|
The CLI connects with `LOGICSRC_API=<origin> logicsrc login` (browser OAuth-PKCE
|
|
loopback → an `lsk_` key). See `docs/credential-sharing.md` in the repo root.
|
|
|
|
Deploy boxes and CI use a **machine key** instead (`logicsrc keys create`, or
|
|
Settings ▸ API keys): one team, optional vault list, read-only by default,
|
|
optional expiry, and its own identity public key on the `api_keys` row. Vault
|
|
keys reach it through `credshare_key_grants`. Routes: `GET|POST /api/keys`,
|
|
`DELETE /api/keys/:id` (session or a person's key only) and
|
|
`GET|POST /api/credshare/vaults/:id/key-grants`,
|
|
`DELETE /api/credshare/vaults/:id/key-grants/:keyId`. Migration
|
|
`005_machine_keys.sql`; tests in `test/machine-keys.test.mjs`.
|