@keyboxed/cli 0.2.5 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/schema.sql +8 -0
- package/assets/worker.js +704 -238
- package/dist/keybox.js +261 -20
- package/package.json +1 -1
package/dist/keybox.js
CHANGED
|
@@ -50,6 +50,9 @@ function configDir() {
|
|
|
50
50
|
}
|
|
51
51
|
function loadConfig() {
|
|
52
52
|
const env2 = process.env;
|
|
53
|
+
if (env2.KEYBOX_URL && env2.KEYBOX_DEVICE_ID && env2.KEYBOX_DEVICE_KEY) {
|
|
54
|
+
return { url: env2.KEYBOX_URL, deviceId: env2.KEYBOX_DEVICE_ID, deviceKey: env2.KEYBOX_DEVICE_KEY, name: env2.KEYBOX_NAME ?? "keybox", d1Id: "" };
|
|
55
|
+
}
|
|
53
56
|
if (env2.KEYBOX_URL && env2.KEYBOX_ADMIN_TOKEN) {
|
|
54
57
|
return {
|
|
55
58
|
url: env2.KEYBOX_URL,
|
|
@@ -83,14 +86,48 @@ var init_config = __esm({
|
|
|
83
86
|
}
|
|
84
87
|
});
|
|
85
88
|
|
|
89
|
+
// src/device.ts
|
|
90
|
+
import { createHash, createPrivateKey, createPublicKey, generateKeyPairSync, randomBytes, sign } from "node:crypto";
|
|
91
|
+
import { hostname } from "node:os";
|
|
92
|
+
function newDeviceKey() {
|
|
93
|
+
const { privateKey, publicKey } = generateKeyPairSync("ed25519");
|
|
94
|
+
return {
|
|
95
|
+
privateKey: privateKey.export({ format: "der", type: "pkcs8" }).toString("base64url"),
|
|
96
|
+
publicKey: publicKey.export({ format: "jwk" }).x
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function deviceName() {
|
|
100
|
+
return hostname().replace(/\.local$/, "").slice(0, 48) || "device";
|
|
101
|
+
}
|
|
102
|
+
function signRequest(device, method, fullUrl, body, now = Date.now()) {
|
|
103
|
+
const u = new URL(fullUrl);
|
|
104
|
+
const ts = String(now);
|
|
105
|
+
const nonce = randomBytes(16).toString("base64url");
|
|
106
|
+
const text = ["KEYBOX-SIG-1", method.toUpperCase(), u.host, u.pathname + u.search, ts, nonce, createHash("sha256").update(body).digest("hex")].join("\n");
|
|
107
|
+
const key = createPrivateKey({ key: Buffer.from(device.privateKey, "base64url"), format: "der", type: "pkcs8" });
|
|
108
|
+
const sig = sign(null, Buffer.from(text), key).toString("base64url");
|
|
109
|
+
return `Keybox-Sig id=${device.id}, ts=${ts}, nonce=${nonce}, sig=${sig}`;
|
|
110
|
+
}
|
|
111
|
+
var init_device = __esm({
|
|
112
|
+
"src/device.ts"() {
|
|
113
|
+
"use strict";
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
|
|
86
117
|
// src/api.ts
|
|
87
118
|
async function api(method, path, body, config = requireConfig()) {
|
|
88
119
|
let res;
|
|
120
|
+
const url = `${config.url.replace(/\/$/, "")}/_keybox/admin${path}`;
|
|
121
|
+
const text = body === void 0 ? "" : JSON.stringify(body);
|
|
122
|
+
let authorization;
|
|
123
|
+
if (config.deviceId && config.deviceKey) authorization = signRequest({ id: config.deviceId, privateKey: config.deviceKey }, method, url, text);
|
|
124
|
+
else if (config.adminToken) authorization = `Bearer ${config.adminToken}`;
|
|
125
|
+
else throw new UserError("No credentials for this Keybox. Run `keybox login`.");
|
|
89
126
|
try {
|
|
90
|
-
res = await fetch(
|
|
127
|
+
res = await fetch(url, {
|
|
91
128
|
method,
|
|
92
|
-
headers: { authorization
|
|
93
|
-
body: body === void 0 ? void 0 :
|
|
129
|
+
headers: { authorization, "content-type": "application/json" },
|
|
130
|
+
body: body === void 0 ? void 0 : text
|
|
94
131
|
});
|
|
95
132
|
} catch {
|
|
96
133
|
throw new UserError(`Could not reach ${config.url}.`);
|
|
@@ -103,6 +140,7 @@ var init_api = __esm({
|
|
|
103
140
|
"src/api.ts"() {
|
|
104
141
|
"use strict";
|
|
105
142
|
init_config();
|
|
143
|
+
init_device();
|
|
106
144
|
}
|
|
107
145
|
});
|
|
108
146
|
|
|
@@ -1894,7 +1932,7 @@ var VERSION;
|
|
|
1894
1932
|
var init_version = __esm({
|
|
1895
1933
|
"src/version.ts"() {
|
|
1896
1934
|
"use strict";
|
|
1897
|
-
VERSION = true ? "0.
|
|
1935
|
+
VERSION = true ? "0.3.0" : "0.0.0-dev";
|
|
1898
1936
|
}
|
|
1899
1937
|
});
|
|
1900
1938
|
|
|
@@ -1909,7 +1947,7 @@ __export(verify_exports, {
|
|
|
1909
1947
|
shippedWorkerVersion: () => shippedWorkerVersion,
|
|
1910
1948
|
verify: () => verify
|
|
1911
1949
|
});
|
|
1912
|
-
import { createHash } from "node:crypto";
|
|
1950
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
1913
1951
|
import { readFileSync as readFileSync4 } from "node:fs";
|
|
1914
1952
|
async function liveHealth(url, want, seconds = 30) {
|
|
1915
1953
|
let last = null;
|
|
@@ -2055,7 +2093,7 @@ var init_verify = __esm({
|
|
|
2055
2093
|
init_version();
|
|
2056
2094
|
init_wrangler();
|
|
2057
2095
|
EXPECTED_BINDINGS = /* @__PURE__ */ new Set(["DB", "KEYBOX_KEK", "KEYBOX_ADMIN_TOKEN_HASH", "KEYBOX_SCRIPT_NAME", "KEYBOX_D1_ID"]);
|
|
2058
|
-
shaHex = (b) =>
|
|
2096
|
+
shaHex = (b) => createHash2("sha256").update(b).digest("hex");
|
|
2059
2097
|
shippedWorkerHash = () => shaHex(readFileSync4(new URL("../assets/worker.js", import.meta.url)));
|
|
2060
2098
|
shippedWorkerVersion = () => /VERSION = "([^"]+)"/.exec(readFileSync4(new URL("../assets/worker.js", import.meta.url), "utf8"))?.[1] ?? VERSION;
|
|
2061
2099
|
}
|
|
@@ -2069,7 +2107,7 @@ __export(deploy_exports, {
|
|
|
2069
2107
|
status: () => status
|
|
2070
2108
|
});
|
|
2071
2109
|
import { spawn as spawn4 } from "node:child_process";
|
|
2072
|
-
import { createHash as
|
|
2110
|
+
import { createHash as createHash3, randomBytes as randomBytes2 } from "node:crypto";
|
|
2073
2111
|
import { copyFileSync, existsSync as existsSync3, mkdirSync as mkdirSync2, readFileSync as readFileSync5, writeFileSync as writeFileSync2 } from "node:fs";
|
|
2074
2112
|
import { join as join4 } from "node:path";
|
|
2075
2113
|
async function deployWorker(cfg) {
|
|
@@ -2206,16 +2244,16 @@ async function init(opts) {
|
|
|
2206
2244
|
async () => {
|
|
2207
2245
|
const secrets = parseJson(await wrangler(["secret", "list", "--config", cfgPath, "--format", "json"], { capture: true, quiet: true }));
|
|
2208
2246
|
if (secrets.some((s) => s.name === "KEYBOX_KEK")) return "kept the existing one";
|
|
2209
|
-
await wrangler(["secret", "put", "KEYBOX_KEK", "--config", cfgPath], { input:
|
|
2247
|
+
await wrangler(["secret", "put", "KEYBOX_KEK", "--config", cfgPath], { input: randomBytes2(32).toString("base64"), capture: true, quiet: true });
|
|
2210
2248
|
return "generated and sent to Cloudflare; never written to disk";
|
|
2211
2249
|
},
|
|
2212
2250
|
(r) => r
|
|
2213
2251
|
);
|
|
2214
|
-
const adminToken = "kb_adm_" +
|
|
2252
|
+
const adminToken = "kb_adm_" + randomBytes2(32).toString("base64url");
|
|
2215
2253
|
await task(
|
|
2216
2254
|
"Admin token",
|
|
2217
2255
|
async () => {
|
|
2218
|
-
const hash =
|
|
2256
|
+
const hash = createHash3("sha256").update(adminToken).digest("hex");
|
|
2219
2257
|
await wrangler(["secret", "put", "KEYBOX_ADMIN_TOKEN_HASH", "--config", cfgPath], { input: hash, capture: true, quiet: true });
|
|
2220
2258
|
saveConfig({ url, adminToken, name, d1Id, accountId: account.id });
|
|
2221
2259
|
},
|
|
@@ -2274,7 +2312,9 @@ async function deploy(opts) {
|
|
|
2274
2312
|
return;
|
|
2275
2313
|
}
|
|
2276
2314
|
process.stderr.write(`
|
|
2277
|
-
${c.accent("\u25A0")} This
|
|
2315
|
+
${c.accent("\u25A0")} This updates the Worker's code. Your stored keys, agents and logs are not touched.
|
|
2316
|
+
They live in your D1 database and under your encryption key, and a deploy changes neither.
|
|
2317
|
+
The only thing that changes is the code that runs.
|
|
2278
2318
|
deployed ${c.dim(current ?? "(unknown)")}
|
|
2279
2319
|
new ${next} ${c.dim(`@keyboxed/cli ${VERSION}`)}
|
|
2280
2320
|
The new code comes from this copy of @keyboxed/cli. Only continue if you trust it.
|
|
@@ -2317,7 +2357,7 @@ var init_deploy = __esm({
|
|
|
2317
2357
|
init_wrangler();
|
|
2318
2358
|
COMPAT_DATE = "2026-07-01";
|
|
2319
2359
|
asset = (f) => new URL(`../assets/${f}`, import.meta.url).pathname;
|
|
2320
|
-
sha = (path) =>
|
|
2360
|
+
sha = (path) => createHash3("sha256").update(readFileSync5(path)).digest("hex");
|
|
2321
2361
|
LATER = [
|
|
2322
2362
|
["keybox migrate", "bring keys in from .env, 1Password, Doppler, Vault\u2026"],
|
|
2323
2363
|
["keybox secrets add NAME", "add one key (hidden input)"],
|
|
@@ -4145,15 +4185,135 @@ __export(extra_exports, {
|
|
|
4145
4185
|
accessCloudflare: () => accessCloudflare,
|
|
4146
4186
|
accessSet: () => accessSet,
|
|
4147
4187
|
accessShow: () => accessShow,
|
|
4188
|
+
claim: () => claim,
|
|
4189
|
+
devicesAdd: () => devicesAdd,
|
|
4190
|
+
devicesApprove: () => devicesApprove,
|
|
4191
|
+
devicesList: () => devicesList,
|
|
4192
|
+
devicesRevoke: () => devicesRevoke,
|
|
4193
|
+
login: () => login,
|
|
4194
|
+
membersAdd: () => membersAdd,
|
|
4195
|
+
membersList: () => membersList,
|
|
4196
|
+
membersLog: () => membersLog,
|
|
4197
|
+
membersRm: () => membersRm,
|
|
4148
4198
|
pair: () => pair,
|
|
4149
4199
|
qrBlocks: () => qrBlocks,
|
|
4150
4200
|
skill: () => skill,
|
|
4201
|
+
tokenOff: () => tokenOff,
|
|
4151
4202
|
ui: () => ui
|
|
4152
4203
|
});
|
|
4153
4204
|
import { spawn as spawn5 } from "node:child_process";
|
|
4154
4205
|
import { existsSync as existsSync4, mkdirSync as mkdirSync3, readFileSync as readFileSync6, writeFileSync as writeFileSync3 } from "node:fs";
|
|
4155
4206
|
import { homedir as homedir3 } from "node:os";
|
|
4156
4207
|
import { dirname as dirname2, join as join5 } from "node:path";
|
|
4208
|
+
async function login(urlArg, opts = {}) {
|
|
4209
|
+
const url = checkUrl(urlArg ?? await ask("Keybox address (https://\u2026)"));
|
|
4210
|
+
const code = (opts.code ?? process.env.KEYBOX_JOIN_CODE ?? "").trim();
|
|
4211
|
+
if (code) return joinWithCode(url, code);
|
|
4212
|
+
const token2 = (process.env.KEYBOX_ADMIN_TOKEN ?? await readSecret("Admin token")).trim();
|
|
4213
|
+
if (!token2.startsWith("kb_adm_")) throw new UserError("That does not look like an admin token (they start with kb_adm_).");
|
|
4214
|
+
let res;
|
|
4215
|
+
try {
|
|
4216
|
+
res = await fetch(`${url}/_keybox/admin/secrets`, { headers: { authorization: `Bearer ${token2}` } });
|
|
4217
|
+
} catch {
|
|
4218
|
+
throw new UserError(`Could not reach ${url}.`);
|
|
4219
|
+
}
|
|
4220
|
+
if (res.status === 401 || res.status === 403) throw new UserError("That token was not accepted by this Keybox.");
|
|
4221
|
+
if (!res.ok) throw new UserError(`${url} answered HTTP ${res.status}. Is that a Keybox?`);
|
|
4222
|
+
saveConfig({ url, adminToken: token2, name: "", d1Id: "" });
|
|
4223
|
+
ok(`Connected to ${url}. The token is saved in ~/.config/keybox (mode 600).`);
|
|
4224
|
+
note("Next: `keybox claim` gives this machine its own key, so the shared token can be turned off.");
|
|
4225
|
+
}
|
|
4226
|
+
async function joinWithCode(url, code) {
|
|
4227
|
+
const kind = /^kb_(pair|inv|clm)_[A-Za-z0-9_-]{20,}$/.exec(code)?.[1];
|
|
4228
|
+
if (!kind) throw new UserError("That does not look like a join code (they start with kb_pair_, kb_inv_ or kb_clm_).");
|
|
4229
|
+
const memberName = kind === "clm" && process.stdin.isTTY ? await ask("Your name", "owner") : void 0;
|
|
4230
|
+
const key = newDeviceKey();
|
|
4231
|
+
let res;
|
|
4232
|
+
try {
|
|
4233
|
+
res = await fetch(`${url}/_keybox/join`, {
|
|
4234
|
+
method: "POST",
|
|
4235
|
+
headers: { "content-type": "application/json" },
|
|
4236
|
+
body: JSON.stringify({ code, pubkey: key.publicKey, device_name: deviceName(), member_name: memberName })
|
|
4237
|
+
});
|
|
4238
|
+
} catch {
|
|
4239
|
+
throw new UserError(`Could not reach ${url}.`);
|
|
4240
|
+
}
|
|
4241
|
+
const data = await res.json().catch(() => null);
|
|
4242
|
+
if (!res.ok || !data?.device) throw new UserError(data?.error?.message ?? `${url} answered HTTP ${res.status}. Is that a Keybox?`);
|
|
4243
|
+
saveConfig({ url, deviceId: data.device, deviceKey: key.privateKey, name: "", d1Id: "" });
|
|
4244
|
+
if (data.pending) {
|
|
4245
|
+
ok(`Joined ${url} as ${c.bold(deviceName())}. This machine's key never left it.`);
|
|
4246
|
+
warn(`Waiting for approval. Ask an owner or admin to run: keybox devices approve ${data.device}`);
|
|
4247
|
+
note("Until then every command here will say the machine is waiting.");
|
|
4248
|
+
return;
|
|
4249
|
+
}
|
|
4250
|
+
ok(`Connected to ${url} as ${c.bold(deviceName())}. This machine's key never left it.`);
|
|
4251
|
+
note("Try `keybox ui` for the dashboard, or `keybox secrets add NAME`.");
|
|
4252
|
+
}
|
|
4253
|
+
async function claim() {
|
|
4254
|
+
const cfg = requireConfig();
|
|
4255
|
+
if (cfg.deviceId) throw new UserError("This machine already has a device key. See `keybox devices`.");
|
|
4256
|
+
if (!cfg.adminToken) throw new UserError("Claiming starts from the admin token. Run `keybox login` first.");
|
|
4257
|
+
const key = newDeviceKey();
|
|
4258
|
+
const name = deviceName();
|
|
4259
|
+
const r = await api("POST", "/claim", { pubkey: key.publicKey, device_name: name });
|
|
4260
|
+
const keepToken = process.env.KEYBOX_ADMIN_TOKEN ? void 0 : cfg.adminToken;
|
|
4261
|
+
saveConfig({ ...cfg, adminToken: keepToken, deviceId: r.device, deviceKey: key.privateKey });
|
|
4262
|
+
ok(`This machine (${c.bold(name)}) is now the owner of ${cfg.url}. Requests are signed with a key that never leaves it.`);
|
|
4263
|
+
note("The shared admin token still works. When you are ready, `keybox token off` turns it off for good.");
|
|
4264
|
+
note("Add a second machine with `keybox devices add`, so losing this one does not lock you out.");
|
|
4265
|
+
}
|
|
4266
|
+
async function devicesList() {
|
|
4267
|
+
const r = await api("GET", "/devices");
|
|
4268
|
+
if (!r.devices.length) {
|
|
4269
|
+
note("No devices yet. `keybox claim` enrols this machine as the owner.");
|
|
4270
|
+
} else {
|
|
4271
|
+
process.stdout.write(
|
|
4272
|
+
headed([
|
|
4273
|
+
["ID", "MACHINE", "PERSON", "ROLE", "LAST SEEN", ""],
|
|
4274
|
+
...r.devices.map((d) => [
|
|
4275
|
+
d.id,
|
|
4276
|
+
d.name,
|
|
4277
|
+
d.member,
|
|
4278
|
+
d.role,
|
|
4279
|
+
ago2(d.last_seen),
|
|
4280
|
+
d.revoked_at ? c.dim("revoked") : d.pending ? c.accent("waiting for approval") : d.current ? c.accent("this machine") : ""
|
|
4281
|
+
])
|
|
4282
|
+
])
|
|
4283
|
+
);
|
|
4284
|
+
if (r.devices.some((d) => d.pending && !d.revoked_at)) note("Check the machine name and person before approving: `keybox devices approve ID`.");
|
|
4285
|
+
}
|
|
4286
|
+
note(r.legacy_token ? "The shared admin token is still accepted. `keybox token off` turns it off." : "The shared admin token is off.");
|
|
4287
|
+
}
|
|
4288
|
+
async function devicesAdd() {
|
|
4289
|
+
if (!process.stderr.isTTY) throw new UserError("keybox devices add shows a one-time code that enrols a machine as you; run it yourself in a terminal.");
|
|
4290
|
+
const cfg = requireConfig();
|
|
4291
|
+
const { code } = await api("POST", "/devices/pair", {});
|
|
4292
|
+
step("On the other machine, run:");
|
|
4293
|
+
process.stderr.write(`
|
|
4294
|
+
keybox login ${cfg.url} --code ${code}
|
|
4295
|
+
|
|
4296
|
+
`);
|
|
4297
|
+
note("Works once, for 10 minutes. Anyone who has it in that time can enrol a machine as you, so type it yourself.");
|
|
4298
|
+
}
|
|
4299
|
+
async function devicesApprove(id) {
|
|
4300
|
+
await api("POST", `/devices/${encodeURIComponent(id)}/approve`, {});
|
|
4301
|
+
ok(`Approved ${id}. That machine can now use this Keybox with its person's role.`);
|
|
4302
|
+
}
|
|
4303
|
+
async function devicesRevoke(id) {
|
|
4304
|
+
await api("DELETE", `/devices/${encodeURIComponent(id)}`);
|
|
4305
|
+
ok(`Revoked ${id}. That machine can no longer reach this Keybox.`);
|
|
4306
|
+
}
|
|
4307
|
+
async function tokenOff(opts) {
|
|
4308
|
+
const cfg = requireConfig();
|
|
4309
|
+
if (!cfg.deviceId) throw new UserError("Run `keybox claim` first, so this machine has its own key.");
|
|
4310
|
+
note("After this, only device keys work. Anything still using the shared token stops, including the Rust terminal console (`keybox-tui`).");
|
|
4311
|
+
if (!opts.yes && !await confirm("Turn the shared admin token off?", false)) return;
|
|
4312
|
+
await api("POST", "/token/disable", {});
|
|
4313
|
+
if (!process.env.KEYBOX_ADMIN_TOKEN && cfg.adminToken) saveConfig({ ...cfg, adminToken: void 0 });
|
|
4314
|
+
ok("The shared admin token is off, and removed from this machine.");
|
|
4315
|
+
note("To bring it back (break-glass), set the Worker secret KEYBOX_ALLOW_ADMIN_TOKEN to 1.");
|
|
4316
|
+
}
|
|
4157
4317
|
function openBrowser(url) {
|
|
4158
4318
|
const cmd = process.platform === "darwin" ? "open" : process.platform === "win32" ? "cmd" : "xdg-open";
|
|
4159
4319
|
const args = process.platform === "win32" ? ["/c", "start", '""', url] : [url];
|
|
@@ -4181,7 +4341,7 @@ async function ui(opts) {
|
|
|
4181
4341
|
function qrBlocks(text) {
|
|
4182
4342
|
const qr = (0, import_qrcode.create)(text, { errorCorrectionLevel: "M" });
|
|
4183
4343
|
const n = qr.modules.size;
|
|
4184
|
-
const q =
|
|
4344
|
+
const q = 4;
|
|
4185
4345
|
const dark = (x, y) => x >= 0 && y >= 0 && x < n && y < n && Boolean(qr.modules.get(y, x));
|
|
4186
4346
|
const out2 = [];
|
|
4187
4347
|
for (let y = -q; y < n + q; y += 2) {
|
|
@@ -4205,6 +4365,7 @@ async function pair() {
|
|
|
4205
4365
|
step(`Scan this with the Keybox app ${c.dim("(Pair \u203A Scan QR code)")}`);
|
|
4206
4366
|
process.stderr.write("\n" + qrBlocks(url) + "\n");
|
|
4207
4367
|
note("Works once, for 2 minutes. The app gets a 12-hour session; your admin token stays on this machine.");
|
|
4368
|
+
note("Camera will not read it? Make the terminal window bigger or zoom out, or run `keybox ui --print` and paste that link into the app.");
|
|
4208
4369
|
note("To end every dashboard and app session: Access \u203A Sign out every dashboard session.");
|
|
4209
4370
|
}
|
|
4210
4371
|
async function accessShow() {
|
|
@@ -4299,15 +4460,63 @@ async function skill(opts) {
|
|
|
4299
4460
|
step("Agents that load skills now know how to set up Keybox, migrate keys and write narrow rules safely.");
|
|
4300
4461
|
note('Ask yours: "set up keybox for this project".');
|
|
4301
4462
|
}
|
|
4302
|
-
|
|
4463
|
+
async function membersList() {
|
|
4464
|
+
const r = await api("GET", "/members");
|
|
4465
|
+
process.stdout.write(
|
|
4466
|
+
headed([
|
|
4467
|
+
["ID", "NAME", "ROLE", "MACHINES", ""],
|
|
4468
|
+
...r.map((m) => [m.id, m.name, m.role, String(m.devices), [m.pending ? c.accent(`${m.pending} waiting for approval`) : "", m.invited ? c.dim("invited, not joined") : ""].filter(Boolean).join(", ")])
|
|
4469
|
+
])
|
|
4470
|
+
);
|
|
4471
|
+
note("Roles: owner runs everything. admin runs keys and policy. member runs their own agents and tokens, and cannot change keys.");
|
|
4472
|
+
}
|
|
4473
|
+
async function membersAdd(name, opts) {
|
|
4474
|
+
const cfg = requireConfig();
|
|
4475
|
+
const r = await api("POST", "/members", { name, role: opts.role ?? "member" });
|
|
4476
|
+
step(`Invited ${c.bold(name)} as ${r.role}. They run:`);
|
|
4477
|
+
process.stderr.write(`
|
|
4478
|
+
keybox login ${cfg.url} --code ${r.code}
|
|
4479
|
+
|
|
4480
|
+
`);
|
|
4481
|
+
note("Valid 24 hours, works once. Their machine then waits for you: `keybox devices` shows it, `keybox devices approve ID` lets it in.");
|
|
4482
|
+
}
|
|
4483
|
+
async function membersRm(who) {
|
|
4484
|
+
const list2 = await api("GET", "/members");
|
|
4485
|
+
const m = list2.find((x) => x.id === who || x.name.toLowerCase() === who.toLowerCase());
|
|
4486
|
+
if (!m) throw new UserError(`No member called ${who}. See \`keybox members\`.`);
|
|
4487
|
+
await api("DELETE", `/members/${encodeURIComponent(m.id)}`);
|
|
4488
|
+
ok(`Removed ${m.name}. Their machines and dashboard sessions are revoked.`);
|
|
4489
|
+
}
|
|
4490
|
+
async function membersLog(limit) {
|
|
4491
|
+
const r = await api("GET", `/events?limit=${limit}`);
|
|
4492
|
+
if (!r.length) return note("Nothing yet.");
|
|
4493
|
+
process.stdout.write(
|
|
4494
|
+
headed([
|
|
4495
|
+
["WHEN", "WHO", "MACHINE", "WHAT"],
|
|
4496
|
+
...r.map((e) => [ago2(e.ts), e.member ?? (e.via === "token" ? c.dim("shared token") : c.dim(e.via)), e.device ?? "", e.action])
|
|
4497
|
+
])
|
|
4498
|
+
);
|
|
4499
|
+
}
|
|
4500
|
+
var import_qrcode, checkUrl, ago2, describe, skillAsset;
|
|
4303
4501
|
var init_extra = __esm({
|
|
4304
4502
|
"src/extra.ts"() {
|
|
4305
4503
|
"use strict";
|
|
4306
4504
|
import_qrcode = __toESM(require_qrcode(), 1);
|
|
4307
4505
|
init_api();
|
|
4308
4506
|
init_config();
|
|
4507
|
+
init_device();
|
|
4309
4508
|
init_prompt();
|
|
4310
4509
|
init_ui();
|
|
4510
|
+
checkUrl = (u) => {
|
|
4511
|
+
const url = u.trim().replace(/\/+$/, "");
|
|
4512
|
+
if (!/^https:\/\/[^/\s]+$/.test(url)) throw new UserError("Give the https:// address of your Keybox, for example https://yourteam.keybox.space.");
|
|
4513
|
+
return url;
|
|
4514
|
+
};
|
|
4515
|
+
ago2 = (ms) => {
|
|
4516
|
+
if (!ms) return "never";
|
|
4517
|
+
const s = Math.round((Date.now() - ms) / 1e3);
|
|
4518
|
+
return s < 60 ? "just now" : s < 3600 ? `${Math.round(s / 60)}m ago` : s < 86400 ? `${Math.round(s / 3600)}h ago` : `${Math.round(s / 86400)}d ago`;
|
|
4519
|
+
};
|
|
4311
4520
|
describe = (r) => {
|
|
4312
4521
|
if (!r || !Object.keys(r).length) return c.dim("any network");
|
|
4313
4522
|
const parts2 = [];
|
|
@@ -4415,7 +4624,7 @@ import { existsSync as existsSync5 } from "node:fs";
|
|
|
4415
4624
|
import { delimiter, join as join6 } from "node:path";
|
|
4416
4625
|
var TABS = ["Activity", "Secrets", "Agents"];
|
|
4417
4626
|
var out = process.stdout;
|
|
4418
|
-
var
|
|
4627
|
+
var ago3 = (ms) => {
|
|
4419
4628
|
if (!ms) return "never";
|
|
4420
4629
|
const s = Math.round((Date.now() - ms) / 1e3);
|
|
4421
4630
|
return s < 60 ? `${s}s` : s < 3600 ? `${Math.round(s / 60)}m` : s < 86400 ? `${Math.round(s / 3600)}h` : `${Math.round(s / 86400)}d`;
|
|
@@ -4449,9 +4658,8 @@ function nativeTui() {
|
|
|
4449
4658
|
}
|
|
4450
4659
|
async function tui(opts = {}) {
|
|
4451
4660
|
if (!process.stdin.isTTY || !out.isTTY) throw new UserError("keybox tui needs an interactive terminal. Try `keybox status` or `keybox audit -f`.");
|
|
4452
|
-
const native = opts.basic ? null : nativeTui();
|
|
4661
|
+
const native = opts.basic || !requireConfig().adminToken ? null : nativeTui();
|
|
4453
4662
|
if (native) {
|
|
4454
|
-
requireConfig();
|
|
4455
4663
|
const code = await new Promise((resolve) => {
|
|
4456
4664
|
const child = spawn6(native, [], { stdio: "inherit" });
|
|
4457
4665
|
child.on("error", () => resolve(-1));
|
|
@@ -4491,12 +4699,12 @@ async function tui(opts = {}) {
|
|
|
4491
4699
|
const res = r.decision === "allow" ? String(r.status) : r.decision.toUpperCase();
|
|
4492
4700
|
const col = r.decision === "allow" && r.status < 400 ? c.ok(res.padEnd(5)) : c.bad(res.padEnd(5));
|
|
4493
4701
|
const req = `${r.method} ${r.host ?? ""}${r.path ?? ""}`;
|
|
4494
|
-
return `${c.dim(
|
|
4702
|
+
return `${c.dim(ago3(r.ts).padStart(4))} ${(r.agent ?? "-").padEnd(12).slice(0, 12)} ${col} ${fit(req, Math.max(10, w - 52))} ${c.dim(r.secret ?? r.reason ?? "")}`;
|
|
4495
4703
|
});
|
|
4496
4704
|
}
|
|
4497
4705
|
if (st.tab === 1) {
|
|
4498
4706
|
return st.secrets.map(
|
|
4499
|
-
(s) => `${c.bold(s.name.padEnd(26))} ${s.hosts.join(",").padEnd(30).slice(0, 30)} ${c.dim((s.fingerprint ?? "-").padEnd(13))} ${c.dim("used " +
|
|
4707
|
+
(s) => `${c.bold(s.name.padEnd(26))} ${s.hosts.join(",").padEnd(30).slice(0, 30)} ${c.dim((s.fingerprint ?? "-").padEnd(13))} ${c.dim("used " + ago3(s.last_used))}`
|
|
4500
4708
|
);
|
|
4501
4709
|
}
|
|
4502
4710
|
return st.agents.flatMap((a) => [
|
|
@@ -4747,6 +4955,13 @@ init_ui();
|
|
|
4747
4955
|
init_version();
|
|
4748
4956
|
var HELP_BODY = `Setup
|
|
4749
4957
|
keybox init [--account ID] [--name keybox] Deploy Keybox to your Cloudflare account
|
|
4958
|
+
keybox login [URL] [--code kb_pair_\u2026] Connect to a Keybox someone else runs (a hosted team)
|
|
4959
|
+
keybox claim Give this machine its own key (becomes the owner)
|
|
4960
|
+
keybox members [add NAME [--role member|admin] | rm NAME | log]
|
|
4961
|
+
People on this Keybox: invite, remove, and who changed what
|
|
4962
|
+
keybox devices [list|add|approve ID|revoke ID]
|
|
4963
|
+
Machines that can manage this Keybox; add one with a one-time code
|
|
4964
|
+
keybox token off [--yes] Turn the shared admin token off; only device keys work after
|
|
4750
4965
|
keybox update [--check] [--yes] Update the CLI, then the deployed Worker, then verify
|
|
4751
4966
|
keybox verify [--json] Check Cloudflare is running exactly this CLI's code
|
|
4752
4967
|
keybox deploy [--yes] Replace the deployed Worker with this CLI's version
|
|
@@ -4856,6 +5071,8 @@ async function main(argv) {
|
|
|
4856
5071
|
version: { type: "boolean", short: "v", default: false },
|
|
4857
5072
|
follow: { type: "boolean", short: "f", default: false },
|
|
4858
5073
|
limit: { type: "string", default: "50" },
|
|
5074
|
+
code: { type: "string" },
|
|
5075
|
+
role: { type: "string" },
|
|
4859
5076
|
help: { type: "boolean", short: "h", default: false }
|
|
4860
5077
|
}
|
|
4861
5078
|
});
|
|
@@ -4867,7 +5084,7 @@ async function main(argv) {
|
|
|
4867
5084
|
if (o.version) return void process.stdout.write(VERSION + "\n");
|
|
4868
5085
|
if (o.verbose) process.env.KEYBOX_VERBOSE = "1";
|
|
4869
5086
|
if (o.help || !group) return void process.stdout.write(help());
|
|
4870
|
-
switch (`${group} ${["secrets", "agents", "tokens", "access", "skill"].includes(group) ? sub ?? "" : ""}`.trim()) {
|
|
5087
|
+
switch (`${group} ${["secrets", "agents", "tokens", "access", "skill", "devices", "token", "members"].includes(group) ? sub ?? "" : ""}`.trim()) {
|
|
4871
5088
|
case "init":
|
|
4872
5089
|
return init({ name: o.name, url: o.url, account: o.account, yes: o.yes });
|
|
4873
5090
|
case "verify":
|
|
@@ -4876,6 +5093,30 @@ async function main(argv) {
|
|
|
4876
5093
|
return o["worker-only"] ? updateWorker({ yes: o.yes, check: o.check }) : update({ yes: o.yes, check: o.check });
|
|
4877
5094
|
case "deploy":
|
|
4878
5095
|
return deploy({ yes: o.yes, force: o.force });
|
|
5096
|
+
case "login":
|
|
5097
|
+
return login(sub, { code: o.code });
|
|
5098
|
+
case "claim":
|
|
5099
|
+
return claim();
|
|
5100
|
+
case "devices":
|
|
5101
|
+
case "devices list":
|
|
5102
|
+
return devicesList();
|
|
5103
|
+
case "devices add":
|
|
5104
|
+
return devicesAdd();
|
|
5105
|
+
case "devices approve":
|
|
5106
|
+
return devicesApprove(need(arg, "device id"));
|
|
5107
|
+
case "members":
|
|
5108
|
+
case "members list":
|
|
5109
|
+
return membersList();
|
|
5110
|
+
case "members add":
|
|
5111
|
+
return membersAdd(need(arg, "name"), { role: o.role });
|
|
5112
|
+
case "members rm":
|
|
5113
|
+
return membersRm(need(arg, "name or id"));
|
|
5114
|
+
case "members log":
|
|
5115
|
+
return membersLog(Number(o.limit));
|
|
5116
|
+
case "devices revoke":
|
|
5117
|
+
return devicesRevoke(need(arg, "device id"));
|
|
5118
|
+
case "token off":
|
|
5119
|
+
return tokenOff({ yes: o.yes });
|
|
4879
5120
|
case "status":
|
|
4880
5121
|
return status();
|
|
4881
5122
|
case "ui":
|