Add SSH keys and config to credential sharing (#139)
Some checks failed
CI / build (push) Has been cancelled
test / test (push) Has been cancelled

* Add SSH keys and config to credential sharing

Private keys have lived as plaintext-on-disk files guarded only by a
passphrase. This puts them in the same end-to-end-encrypted vaults as
.env secrets, and adds an agent path so a machine can use a key without
ever writing one to its disk.

- `ssh` provider: ~/.ssh as a value bag. Files are picked by sniffing
  contents (PRIVATE KEY blocks, ssh-*/ecdsa-*/sk-* public keys) plus
  config, config.d/* and allowed_signers. known_hosts and
  authorized_keys are host-specific and access-granting, so they need
  an explicit --include.
- Each file is one secret carrying a JSON envelope of path, mode and
  body. The engine only hands write() the secrets that CHANGED, so a
  separate manifest secret would be absent whenever a key's contents
  change but the file list doesn't — self-describing values keep every
  restore total.
- `logicsrc secrets ssh push|pull|list|agent`, addressed by PERSON not
  project: the vault is ssh--<username>, which teams vaults reads as
  project ssh, env <username>. One teammate's keys never land in
  another's restore; sharing stays a deliberate teams grant.
- Both directions hold back anything that would overwrite a file that
  already differs, and say what they skipped. --force opts in. A
  restore onto a machine with its own keys is otherwise a way to lose
  them.
- Restores chmod each file back to its recorded mode; writeFileSync's
  mode applies only on create, so an existing world-readable key would
  otherwise stay world-readable. The adapter declares delete:false.
- push warns about passphrase-less private keys before they go up.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* Add worked examples to secrets and secrets ssh help

Commander's usage line shows only the first alias, so `logicsrc secrets`
— the spelling people actually type — was invisible in its own help.
The examples carry it, alongside the flows worth copying: link/up/down,
the ssh backup round trip, and a plan → dry-run → approve sync.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* Advertise the ssh provider on the marketing page

The marketing-drift contract failed the build because `ssh` shipped in the
provider registry with no entry in MARKETING_PROOF -- which is the test
working: it exists so a provider cannot ship while the pages people
actually land on still describe the tool without it.

The proof regex is `/~\/\.ssh|SSH key/` rather than a bare `/SSH/` on
purpose. The provider grid renders every registry `name`, and this one is
"Local SSH directory", so `/SSH/` would already be satisfied by the
generated grid and the provider could ship with no copy written about it
at all -- passing the test while failing its intent. Requiring the path or
the phrase means a human wrote a sentence.

That sentence is the new block in the credential-sharing band: ~/.ssh is a
directory of files whose permission bits are load-bearing, not a set of
KEY=VALUE lines, which is the part that makes this provider different from
the other six. README already named ~/.ssh keys, so it needed no change.

apps/logicsrc-web: 75/75 contract tests pass (was 74 passed, 1 failed).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Anthony Ettinger 2026-08-13 17:03:00 -07:00 • committed by GitHub
parent 1cfec322ac
commit b1805d08e5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 939 additions and 10 deletions

View file

@ -27,6 +27,7 @@ import {
secretsUpAction,
secretsDownAction
} from "./teams.js";
import { sshAgentAction, sshListAction, sshPullAction, sshPushAction } from "./ssh.js";
import { credentialsRotateAction } from "./rotate.js";
import { boards, tasks } from "./fixtures.js";
import { print, type OutputFormat } from "./format.js";
@ -415,7 +416,34 @@ const credentials = program
// `secrets` is what people reach for; keep it pointing at the same group
// rather than growing a second, divergent surface.
.alias("secrets")
.description("Credential Sharing OpenSpec: portable, auditable secret sync.");
.description("Credential Sharing OpenSpec: portable, auditable secret sync.")
// Commander's usage line only ever shows the first alias, so the everyday
// spelling — `logicsrc secrets` — is only discoverable from the examples.
.addHelpText(
"after",
`
Examples:
# .env in this directory, shared with the team
logicsrc secrets teams link link this directory to a team project/env
logicsrc secrets up push .env to the linked environment
logicsrc secrets down pull it back down
logicsrc secrets down staging pull another env of the same project
# ~/.ssh keys and config, backed up under your username
logicsrc secrets ssh push profullstack back up ~/.ssh to vault ssh--<you>
logicsrc secrets ssh pull profullstack restore it on another machine
logicsrc secrets ssh agent profullstack load the keys into ssh-agent, not onto disk
# anywhere to anywhere, one plan at a time
logicsrc secrets inspect --provider env --path .env
logicsrc secrets plan --from env --from-path .env --to railway \\
--to-project <projectId> --to-config <environmentId>
logicsrc secrets sync --plan <planId> dry run — no writes
logicsrc secrets sync --plan <planId> --approve
Every command also answers to "credentials" and "creds". Full guide: docs/credential-sharing.md
`
);
function endpointFromOptions(options: Record<string, unknown>, prefix: "" | "from" | "to"): CredentialEndpoint {
const pick = (name: string) => {
@ -491,6 +519,71 @@ credentials
.description("Pull the linked team environment into .env.")
.action((env, options) => secretsDownAction(env, { env: options.env, format: options.format as OutputFormat }));
const secretsSsh = credentials
.command("ssh")
.description("Back up ~/.ssh keys and config to an end-to-end-encrypted vault, keyed by username.")
.addHelpText(
"after",
`
Examples:
logicsrc secrets ssh push profullstack back up ~/.ssh to vault ssh--<your username>
logicsrc secrets ssh push --dry-run show what would go up, write nothing
logicsrc secrets ssh push --include authorized_keys
logicsrc secrets ssh list profullstack what the vault holds: paths, kinds, modes
logicsrc secrets ssh pull profullstack restore onto this machine, permissions and all
logicsrc secrets ssh pull --force also overwrite local files that differ
logicsrc secrets ssh agent profullstack --lifetime 3600
logicsrc secrets ssh pull profullstack anthony when this box logs in as someone else
The vault is ssh--<username>, so "teams vaults" lists it as project ssh, env
<username>. Key pairs, config, config.d/* and allowed_signers travel; known_hosts
and authorized_keys need --include. Nothing that would overwrite a file which
already differs is written without --force.
`
);
const collect = (value: string, previous: string[]): string[] => [...previous, value];
/** Every ssh subcommand addresses the same `ssh--<username>` vault the same way. */
function withSshTarget(command: import("commander").Command): import("commander").Command {
return command
.argument("[team]", "Team slug (selected interactively when omitted)")
.argument("[username]", "Vault owner (defaults to your local username)")
.option("--dir <path>", "SSH directory", "~/.ssh")
.option("--format <format>", "table, json, or markdown", "table");
}
const sshOptions = (options: Record<string, unknown>) => ({
dir: options.dir as string,
include: options.include as string[] | undefined,
force: Boolean(options.force),
dryRun: Boolean(options.dryRun),
format: options.format as OutputFormat
});
withSshTarget(secretsSsh.command("push"))
.option("--include <name>", "Also back up this file (authorized_keys, known_hosts…); repeatable", collect, [])
.option("--force", "Overwrite vault copies that differ from the local file")
.option("--dry-run", "Show what would be pushed without writing")
.description("Push key pairs and config from ~/.ssh into the vault.")
.action((team, username, options) => sshPushAction(team, username, sshOptions(options)));
withSshTarget(secretsSsh.command("pull"))
.option("--force", "Overwrite local files that differ from the vault copy")
.option("--dry-run", "Show what would be restored without writing")
.description("Restore key pairs and config from the vault into ~/.ssh, permissions included.")
.action((team, username, options) => sshPullAction(team, username, sshOptions(options)));
withSshTarget(secretsSsh.command("list"))
.description("List the files an ssh vault holds — paths, kinds and modes, never key bodies.")
.action((team, username, options) => sshListAction(team, username, sshOptions(options)));
withSshTarget(secretsSsh.command("agent"))
.option("--lifetime <seconds>", "Forget the keys after this long (ssh-add -t)")
.option("--dry-run", "List the keys that would be added without adding them")
.description("Load the vault's private keys into the running ssh-agent, without writing them to disk.")
.action((team, username, options) => sshAgentAction(team, username, { ...sshOptions(options), lifetime: options.lifetime as string | undefined }));
withEndpointOptions(
credentials.command("inspect").requiredOption("--provider <provider>", "Provider id"),
"",