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
|
|
@ -30,8 +30,10 @@ import {
|
|||
teamsPullAction,
|
||||
secretsTeamsLinkAction,
|
||||
secretsUpAction,
|
||||
secretsDownAction
|
||||
secretsDownAction,
|
||||
prepareApiKeyAuth
|
||||
} from "./teams.js";
|
||||
import { registerKeysCommands } from "./keys.js";
|
||||
import { sshAgentAction, sshListAction, sshPullAction, sshPushAction } from "./ssh.js";
|
||||
import { credentialsRotateAction } from "./rotate.js";
|
||||
import { boards, tasks } from "./fixtures.js";
|
||||
|
|
@ -111,11 +113,13 @@ program
|
|||
.command("login")
|
||||
.option("--api-url <url>", "LogicSRC credentials app URL (default: $LOGICSRC_API, else the hosted app)")
|
||||
.option("--token <lsk_key>", "Use an existing API key instead of the browser flow (CI)")
|
||||
.option("--api-key <lsk_key>", "Log this box in with a machine API key; it gets its own identity key (never yours)")
|
||||
.option("--reregister", "With --api-key: move a machine key that registered on another box here (drops its grants)")
|
||||
.option("--device", "Force the device-code flow (approve from a browser on another machine)")
|
||||
.option("--web", "Force the loopback browser flow (needs a browser on THIS machine)")
|
||||
.description("Log in via your browser for team credential sharing; registers your device identity key.")
|
||||
.action(async (options) => {
|
||||
await loginAction({ apiUrl: options.apiUrl, token: options.token, device: options.device, web: options.web });
|
||||
await loginAction({ apiUrl: options.apiUrl, token: options.token, apiKey: options.apiKey, reregister: options.reregister, device: options.device, web: options.web });
|
||||
});
|
||||
|
||||
program.command("logout").description("Clear local auth token (keeps your identity key).").action(async () => {
|
||||
|
|
@ -738,6 +742,12 @@ Quick start (<team> is e.g. profullstack; see yours with "logicsrc teams list"):
|
|||
logicsrc teams grant <team> <project> <env> dev@example.com
|
||||
logicsrc teams key your key, to read values in the web app
|
||||
|
||||
Deploy boxes and CI (a machine API key: one team, scoped vaults, read-only, its own identity):
|
||||
logicsrc keys create <name> --team <team> --vault <project>--<env> --out deploy.key
|
||||
LOGICSRC_API_KEY=$(cat deploy.key) logicsrc whoami on the box, once
|
||||
logicsrc teams grant <team> <project> <env> --key <name> from your machine
|
||||
LOGICSRC_API_KEY=$(cat deploy.key) logicsrc teams pull <team> <project> <env> --env .env
|
||||
|
||||
Categories: logicsrc teams categories. Help for one command: logicsrc teams <command> --help
|
||||
`
|
||||
);
|
||||
|
|
@ -892,10 +902,11 @@ teams
|
|||
.argument("<slug>", "Team slug")
|
||||
.argument("<project>", "Project name")
|
||||
.argument("<env>", "Environment name (prod, staging, …)")
|
||||
.argument("<email>", "Teammate email to grant vault access")
|
||||
.argument("[email]", "Teammate email to grant vault access")
|
||||
.option("--key <name>", "Grant one of your machine API keys instead of a person (name, id, or prefix)")
|
||||
.option("--format <format>", "table, json, or markdown", "table")
|
||||
.description("Grant a member decryption access to a vault (re-wraps the vault key to their key).")
|
||||
.action((slug, project, env, email, options) => teamsGrantAction(slug, project, env, email, options.format as OutputFormat));
|
||||
.description("Grant a member, or a machine API key, decryption access to a vault (re-seals the vault key to their key).")
|
||||
.action((slug, project, env, email, options) => teamsGrantAction(slug, project, env, email, options.format as OutputFormat, { key: options.key }));
|
||||
|
||||
teams
|
||||
.command("push")
|
||||
|
|
@ -1172,6 +1183,17 @@ async function runYoloArcade(game: string, repo?: string) {
|
|||
});
|
||||
}
|
||||
|
||||
registerKeysCommands(program);
|
||||
|
||||
// LOGICSRC_API_KEY: prepare the key's identity (first use registers a machine
|
||||
// key's own public key) before any command that talks to the credentials app.
|
||||
const API_KEY_COMMANDS = new Set(["teams", "secrets", "credentials", "whoami", "keys"]);
|
||||
program.hook("preAction", async (_root, actionCommand) => {
|
||||
let top: Command = actionCommand;
|
||||
while (top.parent && top.parent !== program) top = top.parent;
|
||||
if (API_KEY_COMMANDS.has(top.name())) await prepareApiKeyAuth();
|
||||
});
|
||||
|
||||
registerOpenContextCommands(program);
|
||||
registerOpenCredsCommands(program);
|
||||
registerOntologyCommands(program);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue