mirror of
https://github.com/profullstack/logicsrc.git
synced 2026-12-01 01:14:47 +00:00
security: keep signing keys out of deployable team vaults (CLI 0.13.0) (#264)
Some checks are pending
CI / build (push) Waiting to run
Deploy to dev2 / deploy (push) Waiting to run
test / test (push) Waiting to run
Some checks are pending
CI / build (push) Waiting to run
Deploy to dev2 / deploy (push) Waiting to run
test / test (push) Waiting to run
* security: keep signing keys out of deployable team vaults (CLI 0.13.0) After the 2026-10-27 dev2 incident, root on the box drained every wallet whose key sat in an app.env, and deploys write app.env from team vaults. Wallet keys, seed phrases, hsm secrets and SSH/deploy keys now stay out of that path: - server: a machine (deploy) key never receives a signing key from GET /vaults/:id/secrets (listed as `withheld`, audited as secrets:withheld:signing) and cannot write or delete one (403 signing_key_machine_write). People still see them, so they can move them. - CLI `teams push` refuses a .env holding signing keys, by name or by value shape (PEM private key, 0x-hex, Solana base58/byte array, mnemonic), unless --allow-signing-keys. - CLI `teams pull` withholds signing keys by default; --include-signing-keys needs a person at a terminal, so deploy-app.sh's fallback to the logged-in account withholds them too. - One name rule in packages/opencreds/src/signing-keys.ts, mirrored in apps/pwa/src/lib/signing-keys.mjs, both held to one fixture file. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: bound the wallet-name regex, build PEM fixtures at runtime Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Anthony Ettinger <anthony@profullstack.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
1bff3e975c
commit
b5f875837a
12 changed files with 297 additions and 12 deletions
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@logicsrc/cli",
|
||||
"version": "0.12.0",
|
||||
"version": "0.13.0",
|
||||
"description": "LogicSRC CLI: every LogicSRC standard and tool as one command.",
|
||||
"type": "module",
|
||||
"main": "./dist/index.js",
|
||||
|
|
|
|||
|
|
@ -1112,9 +1112,10 @@ teams
|
|||
.argument("<project>", "Project name")
|
||||
.argument("<env>", "Environment name (prod, staging, …)")
|
||||
.option("--env <path>", "Source .env file", ".env")
|
||||
.option("--allow-signing-keys", "Push wallet keys, seed phrases or SSH keys anyway (refused by default: use `logicsrc keyring`)")
|
||||
.option("--format <format>", "table, json, or markdown", "table")
|
||||
.description("Encrypt and push a local .env into a team vault (<project>--<env>).")
|
||||
.action((slug, project, env, options) => teamsPushAction(slug, project, env, { env: options.env, format: options.format as OutputFormat }));
|
||||
.description("Encrypt and push a local .env into a team vault (<project>--<env>). Signing keys are refused.")
|
||||
.action((slug, project, env, options) => teamsPushAction(slug, project, env, { env: options.env, format: options.format as OutputFormat, allowSigningKeys: Boolean(options.allowSigningKeys) }));
|
||||
|
||||
teams
|
||||
.command("pull")
|
||||
|
|
@ -1122,9 +1123,10 @@ teams
|
|||
.argument("<project>", "Project name")
|
||||
.argument("<env>", "Environment name (prod, staging, …)")
|
||||
.option("--env <path>", "Destination .env file", ".env")
|
||||
.option("--include-signing-keys", "Also write wallet keys, seed phrases and SSH keys (interactive only; withheld by default)")
|
||||
.option("--format <format>", "table, json, or markdown", "table")
|
||||
.description("Pull a team vault (<project>--<env>) and decrypt it into a local .env.")
|
||||
.action((slug, project, env, options) => teamsPullAction(slug, project, env, { env: options.env, format: options.format as OutputFormat }));
|
||||
.description("Pull a team vault (<project>--<env>) and decrypt it into a local .env. Signing keys are withheld.")
|
||||
.action((slug, project, env, options) => teamsPullAction(slug, project, env, { env: options.env, format: options.format as OutputFormat, includeSigningKeys: Boolean(options.includeSigningKeys) }));
|
||||
|
||||
const accounts = program.command("accounts").description("Manage connected social and email accounts.");
|
||||
|
||||
|
|
|
|||
33
packages/cli/src/signing-keys-cli.test.ts
Normal file
33
packages/cli/src/signing-keys-cli.test.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { signingKeysInEnvFile, teamsPullAction, teamsPushAction } from "./teams.js";
|
||||
|
||||
const dirs: string[] = [];
|
||||
const envFile = (body: string) => {
|
||||
const d = mkdtempSync(join(tmpdir(), "lsk-sign-"));
|
||||
dirs.push(d);
|
||||
const p = join(d, ".env");
|
||||
writeFileSync(p, body);
|
||||
return p;
|
||||
};
|
||||
afterEach(() => { for (const d of dirs.splice(0)) rmSync(d, { recursive: true, force: true }); });
|
||||
|
||||
describe("signing keys stay out of team vaults", () => {
|
||||
it("finds signing keys by name and by value shape", () => {
|
||||
const p = envFile(`API_KEY=abc\nSOLANA_PRIVATE_KEY=xyz\nNOTES=0x${"ab".repeat(32)}\nSESSION_SECRET=${"cd".repeat(32)}\n`);
|
||||
expect(signingKeysInEnvFile(p)).toEqual(["NOTES", "SOLANA_PRIVATE_KEY"]);
|
||||
expect(signingKeysInEnvFile(join(tmpdir(), "missing-lsk.env"))).toEqual([]);
|
||||
});
|
||||
|
||||
it("push refuses a file holding signing keys before touching the network", async () => {
|
||||
const p = envFile("EVM_PRIVATE_KEY=0xabc\n");
|
||||
await expect(teamsPushAction("acme", "web", "prod", { env: p, format: "json" })).rejects.toThrow(/signing keys: EVM_PRIVATE_KEY/);
|
||||
});
|
||||
|
||||
it("pull refuses --include-signing-keys without a terminal", async () => {
|
||||
const p = envFile("");
|
||||
await expect(teamsPullAction("acme", "web", "prod", { env: p, format: "json", includeSigningKeys: true })).rejects.toThrow(/needs a person at a terminal/);
|
||||
});
|
||||
});
|
||||
|
|
@ -3,8 +3,8 @@ import { createHash, randomBytes } from "node:crypto";
|
|||
import { hostname } from "node:os";
|
||||
import { spawn } from "node:child_process";
|
||||
import { createInterface } from "node:readline/promises";
|
||||
import { chmodSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { OTHER_CATEGORY, SECRET_CATEGORIES, categorizeSecret, csvLine, parseCategories } from "@logicsrc/opencreds";
|
||||
import { chmodSync, existsSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { OTHER_CATEGORY, SECRET_CATEGORIES, categorizeSecret, csvLine, isSigningKey, isSigningKeyName, parseCategories } from "@logicsrc/opencreds";
|
||||
import {
|
||||
TeamClient,
|
||||
TeamApiError,
|
||||
|
|
@ -28,6 +28,7 @@ import {
|
|||
checkAndPinKey,
|
||||
keyFingerprint,
|
||||
pinStatus,
|
||||
parseEnv,
|
||||
type CredentialEndpoint,
|
||||
type RemoteVault
|
||||
} from "@logicsrc/plugin-credential-sharing";
|
||||
|
|
@ -588,7 +589,23 @@ export function teamEndpoint(slug: string, vault: string): CredentialEndpoint {
|
|||
|
||||
// Note the two different "env"s: `envName` is the environment half of the vault
|
||||
// address (prod, staging), while `options.env` is the local .env file path.
|
||||
export async function teamsPushAction(slug: string, project: string, envName: string, options: { env: string; format: OutputFormat }): Promise<void> {
|
||||
const SIGNING_KEY_HELP =
|
||||
"Signing keys (wallet keys, seed phrases, hsm secrets, SSH/deploy keys) do not go in a team vault: a deploy " +
|
||||
"pulls a vault into app.env and keeps it there 24/7. Keep them in `logicsrc keyring` and have the service ask " +
|
||||
"for an unlock when it signs.";
|
||||
|
||||
/** Names in a local .env that are signing keys, by name or by what the value looks like. */
|
||||
export function signingKeysInEnvFile(path: string): string[] {
|
||||
if (!existsSync(path)) return [];
|
||||
const bag = parseEnv(readFileSync(path, "utf8"));
|
||||
return Object.entries(bag).filter(([k, v]) => isSigningKey(k, String(v ?? ""))).map(([k]) => k).sort();
|
||||
}
|
||||
|
||||
export async function teamsPushAction(slug: string, project: string, envName: string, options: { env: string; format: OutputFormat; allowSigningKeys?: boolean }): Promise<void> {
|
||||
const signing = signingKeysInEnvFile(options.env);
|
||||
if (signing.length && !options.allowSigningKeys) {
|
||||
throw new Error(`${options.env} holds signing keys: ${signing.join(", ")}. ${SIGNING_KEY_HELP} Remove them from the file, or pass --allow-signing-keys if this vault is never deployed.`);
|
||||
}
|
||||
requireAuth();
|
||||
const vault = vaultName(project, envName);
|
||||
const engine = createCredentialEngine();
|
||||
|
|
@ -606,12 +623,22 @@ export async function teamsPushAction(slug: string, project: string, envName: st
|
|||
print({ team: slug, project, env: envName, vault, applied, keys: run.results.map((r) => ({ key: r.key, op: r.op, applied: r.applied })) }, options.format);
|
||||
}
|
||||
|
||||
export async function teamsPullAction(slug: string, project: string, envName: string, options: { env: string; format: OutputFormat }): Promise<void> {
|
||||
export async function teamsPullAction(slug: string, project: string, envName: string, options: { env: string; format: OutputFormat; includeSigningKeys?: boolean }): Promise<void> {
|
||||
if (options.includeSigningKeys && !(process.stdin.isTTY && process.stderr.isTTY)) {
|
||||
throw new Error("--include-signing-keys needs a person at a terminal: a script or deploy never writes signing keys to disk.");
|
||||
}
|
||||
requireAuth();
|
||||
const vault = vaultName(project, envName);
|
||||
const engine = createCredentialEngine();
|
||||
const from = teamEndpoint(slug, vault);
|
||||
const to: CredentialEndpoint = { provider: "env", path: options.env };
|
||||
const plan = await engine.createCredentialSyncPlan({ from: teamEndpoint(slug, vault), to });
|
||||
// Signing keys stay in the vault unless a person asks for them at a terminal;
|
||||
// the server never sends them to a machine key at all.
|
||||
const withheld = options.includeSigningKeys
|
||||
? []
|
||||
: (await engine.diffCredentialEndpoints(from, to)).entries.map((e) => e.key).filter((k) => isSigningKeyName(k));
|
||||
if (withheld.length) console.error(`Withheld ${withheld.length} signing key(s): ${withheld.join(", ")}. ${SIGNING_KEY_HELP}`);
|
||||
const plan = await engine.createCredentialSyncPlan({ from, to, policy: withheld.length ? { denyKeys: withheld } : undefined });
|
||||
if (plan.changes.length === 0) {
|
||||
console.error(`${options.env} is already up to date with ${slug}/${vault}.`);
|
||||
print({ team: slug, project, env: envName, vault, changes: 0 }, options.format);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue