mirror of
https://github.com/profullstack/logicsrc.git
synced 2026-12-01 17:24:48 +00:00
Machine API keys: headless teams pull for deploy boxes and CI
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
77075ea1e2
35 changed files with 2220 additions and 106 deletions
|
|
@ -16,6 +16,8 @@
|
|||
var STORE = "logicsrc.identityKey";
|
||||
var status = card.querySelector("[data-role=status]");
|
||||
var values = null; // name -> plaintext, once unlocked
|
||||
var vaultDek = null; // the vault key (bytes), once unlocked -- only ever used to seal it to a machine key
|
||||
var keysCard = document.getElementById("machine-keys");
|
||||
|
||||
function say(msg) { if (status) status.textContent = msg || ""; }
|
||||
|
||||
|
|
@ -90,7 +92,7 @@
|
|||
out[s.name] = na.to_string(na.crypto_secretbox_open_easy(na.from_base64(s.ciphertext, V), na.from_base64(s.nonce, V), dek));
|
||||
} catch (_) { failed.push(s.name); }
|
||||
});
|
||||
return { values: out, failed: failed };
|
||||
return { values: out, failed: failed, dek: dek };
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -107,6 +109,13 @@
|
|||
|
||||
function render(result) {
|
||||
values = result.values;
|
||||
vaultDek = result.dek || null;
|
||||
if (keysCard && vaultDek) {
|
||||
Array.prototype.forEach.call(keysCard.querySelectorAll("[data-action=grant-key]"), function (b) {
|
||||
b.disabled = false;
|
||||
b.removeAttribute("title");
|
||||
});
|
||||
}
|
||||
var rows = main.querySelectorAll("tr[data-key-name]");
|
||||
Array.prototype.forEach.call(rows, function (tr) {
|
||||
var name = tr.getAttribute("data-key-name");
|
||||
|
|
@ -195,6 +204,61 @@
|
|||
}
|
||||
}
|
||||
|
||||
function csrfHeader() {
|
||||
var m = document.cookie.match(/(?:^|; )mc_csrf=([^;]+)/);
|
||||
return m ? decodeURIComponent(m[1]) : "";
|
||||
}
|
||||
|
||||
function keySay(msg, bad) {
|
||||
var el = keysCard && keysCard.querySelector("[data-role=key-status]");
|
||||
if (!el) return;
|
||||
el.textContent = msg || "";
|
||||
el.style.color = bad ? "var(--danger,#c23a3a)" : "";
|
||||
}
|
||||
|
||||
// Machine keys: seal the vault key to the machine's own public key, here.
|
||||
if (keysCard) {
|
||||
keysCard.addEventListener("click", function (e) {
|
||||
var btn = e.target && e.target.closest ? e.target.closest("[data-action]") : null;
|
||||
if (!btn) return;
|
||||
var action = btn.getAttribute("data-action");
|
||||
var keyId = btn.getAttribute("data-key-id");
|
||||
var url = "/api/credshare/vaults/" + encodeURIComponent(vaultId) + "/key-grants";
|
||||
if (action === "grant-key") {
|
||||
if (!vaultDek) { keySay("Unlock the vault with your key first.", true); return; }
|
||||
btn.disabled = true;
|
||||
sodium().then(function (na) {
|
||||
var V = na.base64_variants.ORIGINAL;
|
||||
var sealed = na.to_base64(na.crypto_box_seal(vaultDek, na.from_base64(btn.getAttribute("data-key-public"), V)), V);
|
||||
return fetch(url, {
|
||||
method: "POST",
|
||||
credentials: "same-origin",
|
||||
headers: { "content-type": "application/json", "x-csrf-token": csrfHeader() },
|
||||
body: JSON.stringify({ keyId: keyId, wrappedDek: sealed })
|
||||
});
|
||||
}).then(function (res) {
|
||||
return res.json().catch(function () { return {}; }).then(function (body) {
|
||||
if (!res.ok) throw new Error(body.error || ("HTTP " + res.status));
|
||||
keySay("Granted " + btn.getAttribute("data-key-name") + ". Reload to see it listed.");
|
||||
btn.textContent = "Granted";
|
||||
});
|
||||
}).catch(function (err) { btn.disabled = false; keySay(err.message, true); });
|
||||
} else if (action === "revoke-key") {
|
||||
btn.disabled = true;
|
||||
fetch(url + "/" + encodeURIComponent(keyId), {
|
||||
method: "DELETE",
|
||||
credentials: "same-origin",
|
||||
headers: { "x-csrf-token": csrfHeader() }
|
||||
}).then(function (res) {
|
||||
return res.json().catch(function () { return {}; }).then(function (body) {
|
||||
if (!res.ok) throw new Error(body.error || ("HTTP " + res.status));
|
||||
location.reload();
|
||||
});
|
||||
}).catch(function (err) { btn.disabled = false; keySay(err.message, true); });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// No identity registered yet: make one here and register only its public half.
|
||||
function generate(btn) {
|
||||
btn.disabled = true;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue