mirror of
https://github.com/profullstack/logicsrc.git
synced 2026-12-01 09:24:46 +00:00
Machine API keys: headless teams pull for deploy boxes and CI (#230)
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>
This commit is contained in:
parent
4df342a064
commit
ade33efd17
35 changed files with 2220 additions and 106 deletions
29
apps/pwa/src/migrations-pg/005_machine_keys.sql
Normal file
29
apps/pwa/src/migrations-pg/005_machine_keys.sql
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
-- Machine API keys: headless credentials for deploy boxes and CI.
|
||||
--
|
||||
-- A 'user' key is what `logicsrc login` mints: it acts as the person, with the
|
||||
-- person's identity key. A 'machine' key is created on purpose, is scoped to
|
||||
-- one team (and optionally a list of vault names), is read-only unless asked
|
||||
-- otherwise, may expire, and carries its OWN identity public key, registered by
|
||||
-- the machine on first use. Vault keys are sealed to that public key in
|
||||
-- credshare_key_grants, so a machine never holds a person's secret key and a
|
||||
-- revoked machine key reads nothing.
|
||||
--
|
||||
-- read_only defaults to 0 so every existing (person) key keeps writing; the
|
||||
-- app sets it to 1 for a machine key unless --read-write is asked for.
|
||||
ALTER TABLE api_keys ADD COLUMN kind TEXT NOT NULL DEFAULT 'user';
|
||||
ALTER TABLE api_keys ADD COLUMN team_id TEXT;
|
||||
ALTER TABLE api_keys ADD COLUMN vault_scope TEXT;
|
||||
ALTER TABLE api_keys ADD COLUMN read_only bigint NOT NULL DEFAULT 0;
|
||||
ALTER TABLE api_keys ADD COLUMN expires_at bigint;
|
||||
ALTER TABLE api_keys ADD COLUMN public_key TEXT;
|
||||
ALTER TABLE credshare_audit ADD COLUMN actor_key_id TEXT;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS credshare_key_grants (
|
||||
vault_id TEXT NOT NULL REFERENCES credshare_vaults(id) ON DELETE CASCADE,
|
||||
api_key_id TEXT NOT NULL REFERENCES api_keys(id) ON DELETE CASCADE,
|
||||
wrapped_dek TEXT NOT NULL,
|
||||
granted_by TEXT NOT NULL REFERENCES users(id),
|
||||
created_at bigint NOT NULL,
|
||||
PRIMARY KEY (vault_id, api_key_id)
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS idx_key_grants_key ON credshare_key_grants(api_key_id);
|
||||
Loading…
Add table
Add a link
Reference in a new issue