@keyboxed/cli 0.3.0 → 0.3.2
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/skill/SKILL.md +2 -2
- package/assets/worker.js +31 -3
- package/dist/keybox.js +798 -247
- package/package.json +1 -1
package/assets/skill/SKILL.md
CHANGED
|
@@ -15,7 +15,7 @@ Docs: https://keybox.space/docs
|
|
|
15
15
|
|
|
16
16
|
1. **Never see a key value.** Do not `cat`, `grep`, `head`, `source` or open `.env` files or anything that may hold a credential. To see what a file holds, list names only: `cut -d= -f1 .env`. Do not print environment variables (`env`, `printenv`, `echo $X`).
|
|
17
17
|
2. **Never put a key on a command line.** Values go in only through `keybox migrate`, `keybox secrets add` (hidden prompt, pipe, or `--from` reference), or the dashboard. Never write `keybox secrets add X <<< "sk-…"` with a value you typed.
|
|
18
|
-
3. **Never read `~/.config/keybox/config.json`.** It holds
|
|
18
|
+
3. **Never read `~/.config/keybox/config.json`.** It holds this machine's device key. Inside `keybox run` it is hidden on purpose, and Keybox admin commands fail there; do not try to get around that.
|
|
19
19
|
4. **Ask before** you change the user's Cloudflare account, edit a file that holds secrets, delete anything, or widen access. Show the exact command first.
|
|
20
20
|
5. **Do not work around a refusal.** If Keybox returns `blocked`, `not_allowed` or `network_denied`, report it and propose a narrower rule. Never suggest putting the key back in the environment to "make it work".
|
|
21
21
|
6. **Do not run `keybox ui --print`** or open login links yourself. Ask the user to run `keybox ui`.
|
|
@@ -130,7 +130,7 @@ Confirm the expected calls show as allowed and nothing is refused by mistake. Co
|
|
|
130
130
|
|
|
131
131
|
| Code | Meaning | What to do |
|
|
132
132
|
| --- | --- | --- |
|
|
133
|
-
| `not_allowed` | No rule allows this method/host/path |
|
|
133
|
+
| `not_allowed` | No rule allows this method/host/path | The message names the fix. Show the user `keybox agents suggest NAME` (reviews every refused call) or the narrowest `keybox agents allow NAME 'RULE'`; ask first. Never propose `**` to silence it |
|
|
134
134
|
| `blocked` | Built-in list: the call would mint a key or grant access | Explain; there is no override |
|
|
135
135
|
| `network_denied` | The caller's IP or country is outside the access rules | Show `keybox access`; let the user decide |
|
|
136
136
|
| `ambiguous_secret` | Several keys could apply | Send header `x-keybox-secret: NAME` or prefix rules |
|
package/assets/worker.js
CHANGED
|
@@ -46,7 +46,7 @@ async function verifyAccess(jwt, cfg) {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
// src/types.ts
|
|
49
|
-
var VERSION = "0.3.
|
|
49
|
+
var VERSION = "0.3.2";
|
|
50
50
|
function keyboxError(status, code, message) {
|
|
51
51
|
return Response.json({ type: "error", error: { type: "keybox_error", code, message } }, { status });
|
|
52
52
|
}
|
|
@@ -510,6 +510,20 @@ async function removeMember(env, who, id) {
|
|
|
510
510
|
]);
|
|
511
511
|
return Response.json({ removed: true });
|
|
512
512
|
}
|
|
513
|
+
async function setRole(req, env, who, id) {
|
|
514
|
+
check(roleOf(who) === "owner", "Only an owner can change a role.");
|
|
515
|
+
const b = await body(req);
|
|
516
|
+
check(b.role === "admin" || b.role === "member", "role is admin or member");
|
|
517
|
+
const m = await env.DB.prepare("SELECT id AS member_id, role FROM members WHERE id = ? AND role != 'removed'").bind(id).first();
|
|
518
|
+
check(m, "No such member.");
|
|
519
|
+
check(m.role !== "owner", "An owner keeps the owner role. Remove them to change that.");
|
|
520
|
+
check(m.member_id !== who.member, "You cannot change your own role.");
|
|
521
|
+
await env.DB.batch([
|
|
522
|
+
env.DB.prepare("UPDATE members SET role = ? WHERE id = ?").bind(b.role, id),
|
|
523
|
+
env.DB.prepare("DELETE FROM sessions WHERE kind LIKE '%:' || ?").bind(id)
|
|
524
|
+
]);
|
|
525
|
+
return Response.json({ id, role: b.role });
|
|
526
|
+
}
|
|
513
527
|
async function logEvent(env, who, method, path) {
|
|
514
528
|
await env.DB.prepare("INSERT INTO events (ts, member_id, device_id, via, action) VALUES (?, ?, ?, ?, ?)").bind(Date.now(), who.member ?? null, who.device ?? null, who.via, `${method} ${path}`.slice(0, 200)).run().catch(() => {
|
|
515
529
|
});
|
|
@@ -831,6 +845,7 @@ async function route(req, env, path, policy, who) {
|
|
|
831
845
|
if (a === "members" && !b && m === "GET") return listMembers(env);
|
|
832
846
|
if (a === "members" && !b && m === "POST") return invite(req, env, who);
|
|
833
847
|
if (a === "members" && b && !c && m === "DELETE") return removeMember(env, who, b);
|
|
848
|
+
if (a === "members" && b && !c && m === "PATCH") return setRole(req, env, who, b);
|
|
834
849
|
if (a === "events" && !b && m === "GET") return listEvents(req, env);
|
|
835
850
|
if (a === "policy" && !b && m === "GET") return Response.json(policy);
|
|
836
851
|
if (a === "policy" && !b && m === "PUT") {
|
|
@@ -933,7 +948,17 @@ async function route(req, env, path, policy, who) {
|
|
|
933
948
|
const q = new URL(req.url).searchParams;
|
|
934
949
|
const after = Number(q.get("after") ?? 0);
|
|
935
950
|
const limit = Math.min(Math.max(Number(q.get("limit") ?? 100), 1), 500);
|
|
936
|
-
const
|
|
951
|
+
const where = [];
|
|
952
|
+
const binds = [];
|
|
953
|
+
for (const col of ["agent", "reason"]) {
|
|
954
|
+
const v = q.get(col);
|
|
955
|
+
if (v) {
|
|
956
|
+
where.push(`${col} = ?`);
|
|
957
|
+
binds.push(v.slice(0, 64));
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
const filter = where.length ? ` AND ${where.join(" AND ")}` : "";
|
|
961
|
+
const stmt = after > 0 ? env.DB.prepare(`SELECT * FROM audit WHERE id > ?${filter} ORDER BY id ASC LIMIT ?`).bind(after, ...binds, limit) : env.DB.prepare(`SELECT * FROM (SELECT * FROM audit WHERE 1=1${filter} ORDER BY id DESC LIMIT ?) ORDER BY id ASC`).bind(...binds, limit);
|
|
937
962
|
return Response.json((await stmt.all()).results);
|
|
938
963
|
}
|
|
939
964
|
if (a === "blocked" && !b && m === "GET") {
|
|
@@ -1279,7 +1304,10 @@ async function proxy(req, env, ctx) {
|
|
|
1279
1304
|
if (g.allow.some(hit)) candidates.add(g.secret);
|
|
1280
1305
|
}
|
|
1281
1306
|
if (candidates.size === 0) {
|
|
1282
|
-
|
|
1307
|
+
const pasteable = /^[A-Za-z0-9._~\-/%:@,+=]*$/.test(path);
|
|
1308
|
+
const review = `keybox agents suggest ${auth.agent}`;
|
|
1309
|
+
const fix = auth.share ? "This share does not cover that call." : pasteable ? `To allow it, a Keybox admin runs: keybox agents allow ${auth.agent} '${method} ${host}${path}' (or \`${review}\` to review every refused call).` : `A Keybox admin can review refused calls with \`${review}\`.`;
|
|
1310
|
+
return deny(403, "not_allowed", `Agent ${auth.agent} has no rule allowing ${method} ${host}${path}. ${fix}`);
|
|
1283
1311
|
}
|
|
1284
1312
|
let pick = [...candidates][0];
|
|
1285
1313
|
if (candidates.size > 1) {
|