# ConfigHub: Anonymous Keypair Provisioning & Cross-Environment Sync (`auth.md`)

> Pull-only guide for provisioning an anonymous Ed25519/X25519 keypair so coding agents, teammates, and disposable sandboxes can share tracked staging config and test environments without passwords or `.env` files in Slack.

## Contract Status (Read First)
- **Self-hosted relay (live today):** `cub agent auth --server "$CONFIGHUB_SERVER"` and zero-knowledge `cub env share` / `cub env join` work today with plugin `v0.99.38+` (current: `v0.99.44`) against a self-hosted `agentauth-server` relay.
- **Hosted `https://confighub.com` anonymous provisioning (`[PROVISIONAL]`):** The hosted anonymous identity endpoint (`POST https://confighub.com/v1/agent/identity`) is a preview contract not yet live on `confighub.com`. Before calling `confighub.com`, verify endpoint availability; if it returns `404` or `501`, fall back cleanly to a user-provided self-hosted `--server` URL or Local Hub (`cub local start`).
- **Pull-only rule:** Never fetch or run `auth.md` automatically during Zero Hub or Local Hub use. Only use it when the human explicitly asks to sync across machines or sandboxes or connect to a Remote Hub or relay.

## 3-Layer Component Boundary
- **ConfigHub Core** owns structured non-secret config (`Units`, `Variants`, `NeedsProvides`, `ChangeOrders`), never plaintext secrets or LLM traffic.
- **Secrets & API Brokering (pluggable):** In teams and production, point secret refs at `vault://`, `1password://`, AWS/GCP Secret Manager, or External Secrets, and point `OPENAI_BASE_URL` at your existing gateway (LiteLLM, Cloudflare AI Gateway). The standalone `agentauth-server` relay is strictly an optional zero-infra dev bridge for developers without Vault or a gateway yet.
- **Runtime CLI Spoke (`confighub` / `cub`):** Resolves config and credentials strictly into child process memory (zero `.env` files written to disk).

## Hard Security Guardrails
- **Consent first:** Never send keys or register an account silently. Show the 4-line Consent Card below and wait for explicit `y/n` approval.
- **Private key stays local:** Store the Ed25519/X25519 private key under `~/.confighub/keys/` (`chmod 600`), outside Git. Never print private key material in chat, logs, or PRs. Only the public key is transmitted.
- **Live secrets blocked:** Default to `--mode test` so production keys (`sk_live_*`, prod) stay blocked and zero `.env` files are written to disk on joining environments.

---

## Step 1: Show the 4-Line Consent Card and Ask

```text
ConfigHub anonymous keypair sync summary:
- Local keypair: Ed25519/X25519 stored at ~/.confighub/keys/ (chmod 600, outside Git; private key never leaves this machine)
- Outbound call: registers public key only with $CONFIGHUB_SERVER to create an anonymous sync box + 1-click Claim URL
- Scope: non-production settings and request-capped test proxies (--mode test); live keys (sk_live_*, prod) stay blocked
- Revoke / remove: revoke grants instantly without rotating upstream keys, or delete ~/.confighub/keys/
Proceed? [y/n]
```

---

## Step 2: Provision Against a Self-Hosted Relay (After Consent)

1. Check if `~/.confighub/keys/` already holds an active keypair; reuse it if present.
2. With user consent, register the public key against the target server (`CONFIGHUB_SERVER` set to your self-hosted relay today, or `https://confighub.com` once live):

```sh
cub agent auth --server "$CONFIGHUB_SERVER"
```

*(If `cub` is not yet on `PATH`, run via `"$HOME/.claude/plugins/marketplaces/confighub/plugins/confighub/bin/confighub" agent auth --server "$CONFIGHUB_SERVER"` or `"$HOME/.codex/confighub/bin/confighub"`.)*

What this returns (and what the hosted preview contract `POST /v1/agent/identity` with `{ "public_key": "...", "client": "<agent>" }` provides):
- **`box_id`**: your private, unindexed anonymous ConfigHub space.
- **Scoped agent token**: short-lived credential tied to your Ed25519 public key (stored `chmod 600` under `~/.confighub/`).
- **1-click Claim URL**: printed once for the human owner to attach the anonymous box to a `confighub.com` account later (auto-rotating keys while keeping history intact).

---

## Step 3: Share Across Environments & Sandboxes

### Publisher (Alice: laptop, primary agent, or staging hub)
Seal non-production settings to the recipient's X25519 public key or mint a request-capped proxy grant (`ch_proxy_...`) while holding live keys out:

```sh
cub env share shop --variant staging --mode test --proxy openai=OPENAI_API_KEY --max-requests 50 --server "$CONFIGHUB_SERVER" --approve-wait
```

This prints a short-lived invite URL (24-hour TTL by default) plus an owner revoke token.

### Joining Agent, Teammate, or Disposable Sandbox (Bob)
Join directly into child process memory with zero signup and zero `.env` files written to disk:

```sh
cub env join "$INVITE_URL" --as bob -- npm run dev
```

Full walkthrough: `https://confighub-ai-agents.pages.dev/docs/examples/walkthroughs/story-29-share-working-env.html`.

---

## Step 4: Claim or Revoke Anytime
- **Claim to keep permanently:** Open the Claim URL in a browser to convert the anonymous box into a `confighub.com` account (lifts anonymous TTL/caps and rotates keys automatically).
- **Revoke one sandbox or agent immediately:** Call `POST "$CONFIGHUB_SERVER/v1/proxy/grants/$GRANT_ID/revoke"` with `X-Owner-Token` to cut off a single grant without rotating upstream API keys.

---

## Portable Agent Skill (`SKILL.md`)

Save to `.agents/skills/confighub-anon-sync/SKILL.md` so Claude Code, Codex, Antigravity, Cursor, or Pi can coordinate across machines and disposable sandboxes on demand:

```markdown
---
name: confighub-anon-sync
description: Use when sharing tracked config, staging environments, or sandbox benchmark results across multiple machines, remote sandboxes, or heterogeneous agent swarms (Claude Code, Codex, Antigravity) using an anonymous public/private keypair account. Skip for single-laptop offline tasks.
---

1. Check whether Zero Hub or Local Hub (`cub local start`) alone is enough. Use anonymous keypair sync only when the human explicitly asks to cross machines or remote sandboxes.
2. Verify whether the user has a self-hosted `CONFIGHUB_SERVER` relay URL or whether hosted `confighub.com` anonymous provisioning is live (never fabricate a successful hosted call if the endpoint returns 404/501).
3. Present the 4-line Consent Card from `https://confighub-ai-agents.pages.dev/auth.md` and wait for explicit `y/n` approval before generating keys or making outbound calls.
4. Keep private keys in `~/.confighub/keys/` (`chmod 600`, outside Git) and never echo them in chat. Share only via `--mode test` sealed or brokered grants (`cub env share` / `cub env join`) and print the human Claim URL when created.
```
