@keyboxed/cli 0.1.0 → 0.1.1
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/LICENSE.md +105 -0
- package/README.md +7 -3
- package/dist/keybox.js +64 -9
- package/package.json +14 -4
package/LICENSE.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# Functional Source License, Version 1.1, ALv2 Future License
|
|
2
|
+
|
|
3
|
+
## Abbreviation
|
|
4
|
+
|
|
5
|
+
FSL-1.1-ALv2
|
|
6
|
+
|
|
7
|
+
## Notice
|
|
8
|
+
|
|
9
|
+
Copyright 2026 crsves
|
|
10
|
+
|
|
11
|
+
## Terms and Conditions
|
|
12
|
+
|
|
13
|
+
### Licensor ("We")
|
|
14
|
+
|
|
15
|
+
The party offering the Software under these Terms and Conditions.
|
|
16
|
+
|
|
17
|
+
### The Software
|
|
18
|
+
|
|
19
|
+
The "Software" is each version of the software that we make available under
|
|
20
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
|
21
|
+
Conditions with the Software.
|
|
22
|
+
|
|
23
|
+
### License Grant
|
|
24
|
+
|
|
25
|
+
Subject to your compliance with this License Grant and the Patents,
|
|
26
|
+
Redistribution and Trademark clauses below, we hereby grant you the right to
|
|
27
|
+
use, copy, modify, create derivative works, publicly perform, publicly display
|
|
28
|
+
and redistribute the Software for any Permitted Purpose identified below.
|
|
29
|
+
|
|
30
|
+
### Permitted Purpose
|
|
31
|
+
|
|
32
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
|
33
|
+
means making the Software available to others in a commercial product or
|
|
34
|
+
service that:
|
|
35
|
+
|
|
36
|
+
1. substitutes for the Software;
|
|
37
|
+
|
|
38
|
+
2. substitutes for any other product or service we offer using the Software
|
|
39
|
+
that exists as of the date we make the Software available; or
|
|
40
|
+
|
|
41
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
42
|
+
|
|
43
|
+
Permitted Purposes specifically include using the Software:
|
|
44
|
+
|
|
45
|
+
1. for your internal use and access;
|
|
46
|
+
|
|
47
|
+
2. for non-commercial education;
|
|
48
|
+
|
|
49
|
+
3. for non-commercial research; and
|
|
50
|
+
|
|
51
|
+
4. in connection with professional services that you provide to a licensee
|
|
52
|
+
using the Software in accordance with these Terms and Conditions.
|
|
53
|
+
|
|
54
|
+
### Patents
|
|
55
|
+
|
|
56
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our
|
|
57
|
+
patents, the license grant above includes a license under our patents. If you
|
|
58
|
+
make a claim against any party that the Software infringes or contributes to
|
|
59
|
+
the infringement of any patent, then your patent license to the Software ends
|
|
60
|
+
immediately.
|
|
61
|
+
|
|
62
|
+
### Redistribution
|
|
63
|
+
|
|
64
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of
|
|
65
|
+
the Software.
|
|
66
|
+
|
|
67
|
+
If you redistribute any copies, modifications or derivatives of the Software,
|
|
68
|
+
you must include a copy of or a link to these Terms and Conditions and not
|
|
69
|
+
remove any copyright notices provided in or with the Software.
|
|
70
|
+
|
|
71
|
+
### Disclaimer
|
|
72
|
+
|
|
73
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
|
|
74
|
+
IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
|
|
75
|
+
PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
76
|
+
|
|
77
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
|
78
|
+
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
|
|
79
|
+
EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
80
|
+
|
|
81
|
+
### Trademarks
|
|
82
|
+
|
|
83
|
+
Except for displaying the License Details and identifying us as the origin of
|
|
84
|
+
the Software, you have no right under these Terms and Conditions to use our
|
|
85
|
+
trademarks, trade names, service marks or product names.
|
|
86
|
+
|
|
87
|
+
## Grant of Future License
|
|
88
|
+
|
|
89
|
+
We hereby irrevocably grant you an additional license to use the Software under
|
|
90
|
+
the Apache License, Version 2.0 that is effective on the second anniversary of
|
|
91
|
+
the date we make the Software available. On or after that date, you may use the
|
|
92
|
+
Software under the Apache License, Version 2.0, in which case the following
|
|
93
|
+
will apply:
|
|
94
|
+
|
|
95
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
96
|
+
this file except in compliance with the License.
|
|
97
|
+
|
|
98
|
+
You may obtain a copy of the License at
|
|
99
|
+
|
|
100
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
101
|
+
|
|
102
|
+
Unless required by applicable law or agreed to in writing, software distributed
|
|
103
|
+
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
104
|
+
CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
105
|
+
specific language governing permissions and limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
# @
|
|
1
|
+
# @keyboxed/cli
|
|
2
2
|
|
|
3
3
|
Give AI agents access to your APIs without giving them your keys.
|
|
4
4
|
|
|
5
5
|
Keybox is a Cloudflare Worker that you deploy to your own account. Agents get a scoped Keybox token. The real key is attached on the way out, bound to the hosts it belongs to, and scrubbed from responses.
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm install -g @
|
|
8
|
+
npm install -g @keyboxed/cli
|
|
9
9
|
npx wrangler login
|
|
10
10
|
keybox init
|
|
11
11
|
|
|
@@ -17,4 +17,8 @@ keybox audit --follow
|
|
|
17
17
|
|
|
18
18
|
Calls that would mint a new key or grant lasting access (OpenAI admin keys, GitHub deploy keys and collaborators, Cloudflare API tokens, and others) are always blocked. See them with `keybox blocked`.
|
|
19
19
|
|
|
20
|
-
Read the security model before storing production keys. It also covers what Keybox does not protect against, such as an agent running as your user being able to read your Keybox admin token.
|
|
20
|
+
Read the [security model](https://keybox.space/docs/security-model) before storing production keys. It also covers what Keybox does not protect against, such as an agent running as your user being able to read your Keybox admin token.
|
|
21
|
+
|
|
22
|
+
## License
|
|
23
|
+
|
|
24
|
+
[FSL-1.1-ALv2](https://fsl.software). You can use, modify and self-host Keybox for anything except offering a competing product or service. Each version becomes Apache-2.0 two years after its release. See [LICENSE.md](./LICENSE.md) for full terms.
|
package/dist/keybox.js
CHANGED
|
@@ -5,6 +5,7 @@ import { parseArgs } from "node:util";
|
|
|
5
5
|
|
|
6
6
|
// src/commands.ts
|
|
7
7
|
import { spawn } from "node:child_process";
|
|
8
|
+
import { readFileSync as readFileSync2 } from "node:fs";
|
|
8
9
|
|
|
9
10
|
// src/config.ts
|
|
10
11
|
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
@@ -188,6 +189,56 @@ async function secretsAdd(name, opts) {
|
|
|
188
189
|
process.stderr.write(`Stored ${r.name}. It will only ever be sent to ${r.hosts.join(", ")}.
|
|
189
190
|
`);
|
|
190
191
|
}
|
|
192
|
+
function parseDotenv(text) {
|
|
193
|
+
const out = [];
|
|
194
|
+
for (const line of text.split(/\r?\n/)) {
|
|
195
|
+
const m = /^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)$/.exec(line);
|
|
196
|
+
if (!m) continue;
|
|
197
|
+
let v = m[2].trim();
|
|
198
|
+
const q = v[0];
|
|
199
|
+
if ((q === '"' || q === "'") && v.lastIndexOf(q) > 0) v = v.slice(1, v.lastIndexOf(q));
|
|
200
|
+
else v = v.replace(/\s+#.*$/, "");
|
|
201
|
+
out.push([m[1], v]);
|
|
202
|
+
}
|
|
203
|
+
return out;
|
|
204
|
+
}
|
|
205
|
+
var SECRET_NAME = /(KEY|TOKEN|SECRET|PAT)$/;
|
|
206
|
+
var NOT_SECRET = /(PUBLISHABLE|PUBLIC)/;
|
|
207
|
+
async function secretsImport(file, opts) {
|
|
208
|
+
let text;
|
|
209
|
+
try {
|
|
210
|
+
text = readFileSync2(file, "utf8");
|
|
211
|
+
} catch {
|
|
212
|
+
throw new UserError(`Cannot read ${file}.`);
|
|
213
|
+
}
|
|
214
|
+
const existing = new Set((await api("GET", "/secrets")).map((x) => x.name));
|
|
215
|
+
const found = [];
|
|
216
|
+
const skipped = [];
|
|
217
|
+
for (const [name, value] of parseDotenv(text)) {
|
|
218
|
+
const preset = guessPreset(name);
|
|
219
|
+
if (!SECRET_NAME.test(name) || NOT_SECRET.test(name)) {
|
|
220
|
+
if (preset) skipped.push([name, "not a credential"]);
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
if (!preset) skipped.push([name, "no preset; add it with --host"]);
|
|
224
|
+
else if (value.length < 8) skipped.push([name, "empty or placeholder"]);
|
|
225
|
+
else found.push({ name, value, preset });
|
|
226
|
+
}
|
|
227
|
+
const rows = found.map((f) => [f.name, PRESETS[f.preset].hosts.join(","), existing.has(f.name) ? "replaces existing" : "new"]);
|
|
228
|
+
if (rows.length) process.stdout.write(table([["NAME", "ONLY SENT TO", ""], ...rows]));
|
|
229
|
+
for (const [name, why] of skipped) process.stderr.write(`skipped ${name}: ${why}
|
|
230
|
+
`);
|
|
231
|
+
if (!rows.length) return note(`Nothing to import from ${file}.`);
|
|
232
|
+
if (opts.dryRun) return note("Dry run. Nothing was stored.");
|
|
233
|
+
if (!opts.yes && !await confirm(`Store ${found.length} secret${found.length === 1 ? "" : "s"} in Keybox?`)) {
|
|
234
|
+
throw new UserError("Cancelled. Re-run with --yes to skip the prompt.");
|
|
235
|
+
}
|
|
236
|
+
for (const f of found) await api("PUT", `/secrets/${f.name}`, { ...PRESETS[f.preset], value: f.value });
|
|
237
|
+
process.stderr.write(
|
|
238
|
+
`Stored ${found.length}. ${file} still holds the original values. Delete them there and rotate the keys once you have checked Keybox works.
|
|
239
|
+
`
|
|
240
|
+
);
|
|
241
|
+
}
|
|
191
242
|
async function secretsList() {
|
|
192
243
|
const rows = await api("GET", "/secrets");
|
|
193
244
|
if (!rows.length) return note("No secrets yet. Add one with `keybox secrets add NAME`.");
|
|
@@ -340,17 +391,17 @@ async function blocked() {
|
|
|
340
391
|
|
|
341
392
|
// src/deploy.ts
|
|
342
393
|
import { createHash, randomBytes } from "node:crypto";
|
|
343
|
-
import { copyFileSync, existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as
|
|
394
|
+
import { copyFileSync, existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync4, writeFileSync as writeFileSync2 } from "node:fs";
|
|
344
395
|
import { join as join3 } from "node:path";
|
|
345
396
|
|
|
346
397
|
// src/wrangler.ts
|
|
347
398
|
import { spawn as spawn2 } from "node:child_process";
|
|
348
|
-
import { readFileSync as
|
|
399
|
+
import { readFileSync as readFileSync3 } from "node:fs";
|
|
349
400
|
import { createRequire } from "node:module";
|
|
350
401
|
import { dirname, join as join2 } from "node:path";
|
|
351
402
|
function bin() {
|
|
352
403
|
const pkgPath = createRequire(import.meta.url).resolve("wrangler/package.json");
|
|
353
|
-
const pkg = JSON.parse(
|
|
404
|
+
const pkg = JSON.parse(readFileSync3(pkgPath, "utf8"));
|
|
354
405
|
return join2(dirname(pkgPath), pkg.bin.wrangler);
|
|
355
406
|
}
|
|
356
407
|
function wrangler(args, opts = {}) {
|
|
@@ -378,7 +429,7 @@ function parseJson(out) {
|
|
|
378
429
|
// src/deploy.ts
|
|
379
430
|
var COMPAT_DATE = "2026-07-01";
|
|
380
431
|
var asset = (f) => new URL(`../assets/${f}`, import.meta.url).pathname;
|
|
381
|
-
var sha = (path) => createHash("sha256").update(
|
|
432
|
+
var sha = (path) => createHash("sha256").update(readFileSync4(path)).digest("hex");
|
|
382
433
|
function writeDeployFiles(name, d1Id) {
|
|
383
434
|
const dir = deployDir();
|
|
384
435
|
mkdirSync2(join3(dir, "worker"), { recursive: true, mode: 448 });
|
|
@@ -425,20 +476,20 @@ async function init(opts) {
|
|
|
425
476
|
if (!/^[a-z0-9][a-z0-9-]{0,62}$/.test(name)) throw new UserError("--name must be lowercase letters, digits and dashes.");
|
|
426
477
|
if (loadConfig()) throw new UserError(`Already set up (${configPath()}). Use \`keybox deploy\` to upgrade.`);
|
|
427
478
|
step("Checking your Cloudflare login");
|
|
428
|
-
await wrangler(["whoami"]).catch(() => {
|
|
479
|
+
await wrangler(["whoami"], { capture: true }).catch(() => {
|
|
429
480
|
throw new UserError("Log in to Cloudflare first: npx wrangler login");
|
|
430
481
|
});
|
|
431
482
|
step(`Creating D1 database "${name}"`);
|
|
432
483
|
let d1Id = await findDb(name);
|
|
433
484
|
if (d1Id) note("Database already exists; reusing it.");
|
|
434
485
|
else {
|
|
435
|
-
await wrangler(["d1", "create", name]);
|
|
486
|
+
await wrangler(["d1", "create", name], { capture: true });
|
|
436
487
|
d1Id = await findDb(name);
|
|
437
488
|
}
|
|
438
489
|
if (!d1Id) throw new UserError("Could not find the D1 database after creating it.");
|
|
439
490
|
const cfg = writeDeployFiles(name, d1Id);
|
|
440
491
|
step("Applying schema");
|
|
441
|
-
await wrangler(["d1", "execute", name, "--remote", "--file", join3(deployDir(), "schema.sql"), "--config", cfg]);
|
|
492
|
+
await wrangler(["d1", "execute", name, "--remote", "--yes", "--file", join3(deployDir(), "schema.sql"), "--config", cfg]);
|
|
442
493
|
step(`Deploying Worker "${name}"`);
|
|
443
494
|
const out = await wrangler(["deploy", "--config", cfg], { capture: true });
|
|
444
495
|
process.stderr.write(out);
|
|
@@ -483,12 +534,12 @@ async function deploy(opts) {
|
|
|
483
534
|
This replaces the Worker that holds your keys.
|
|
484
535
|
deployed ${current ?? "(unknown)"}
|
|
485
536
|
new ${next}
|
|
486
|
-
The new code comes from this copy of @
|
|
537
|
+
The new code comes from this copy of @keyboxed/cli. Only continue if you trust it.
|
|
487
538
|
`);
|
|
488
539
|
if (!opts.yes && !await confirm("Deploy?")) throw new UserError("Cancelled.");
|
|
489
540
|
const cfg = writeDeployFiles(c.name, c.d1Id);
|
|
490
541
|
step("Applying schema");
|
|
491
|
-
await wrangler(["d1", "execute", c.name, "--remote", "--file", join3(dir, "schema.sql"), "--config", cfg]);
|
|
542
|
+
await wrangler(["d1", "execute", c.name, "--remote", "--yes", "--file", join3(dir, "schema.sql"), "--config", cfg]);
|
|
492
543
|
step("Deploying");
|
|
493
544
|
await wrangler(["deploy", "--config", cfg]);
|
|
494
545
|
note("Done.");
|
|
@@ -518,6 +569,7 @@ Setup
|
|
|
518
569
|
Secrets (values are read from stdin or a hidden prompt, never from arguments)
|
|
519
570
|
keybox secrets add NAME [--preset openai|anthropic|github|stripe|cloudflare]
|
|
520
571
|
[--host HOST ... --header NAME --format bearer|raw|basic]
|
|
572
|
+
keybox secrets import FILE [--dry-run] [--yes] Move provider keys from a .env file (values never printed)
|
|
521
573
|
keybox secrets list
|
|
522
574
|
keybox secrets rm NAME
|
|
523
575
|
|
|
@@ -544,6 +596,7 @@ async function main(argv) {
|
|
|
544
596
|
name: { type: "string", default: "keybox" },
|
|
545
597
|
url: { type: "string" },
|
|
546
598
|
yes: { type: "boolean", short: "y", default: false },
|
|
599
|
+
"dry-run": { type: "boolean", default: false },
|
|
547
600
|
force: { type: "boolean", default: false },
|
|
548
601
|
preset: { type: "string" },
|
|
549
602
|
host: { type: "string", multiple: true },
|
|
@@ -573,6 +626,8 @@ async function main(argv) {
|
|
|
573
626
|
return status();
|
|
574
627
|
case "secrets add":
|
|
575
628
|
return secretsAdd(need(arg, "secret name"), { preset: o.preset, host: o.host, header: o.header, format: o.format });
|
|
629
|
+
case "secrets import":
|
|
630
|
+
return secretsImport(need(arg, "file"), { dryRun: o["dry-run"], yes: o.yes });
|
|
576
631
|
case "secrets list":
|
|
577
632
|
return secretsList();
|
|
578
633
|
case "secrets rm":
|
package/package.json
CHANGED
|
@@ -1,15 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@keyboxed/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Give AI agents access to your APIs without giving them your keys.",
|
|
5
|
-
"
|
|
5
|
+
"homepage": "https://keybox.space",
|
|
6
|
+
"license": "FSL-1.1-ALv2",
|
|
6
7
|
"type": "module",
|
|
7
8
|
"bin": {
|
|
8
9
|
"keybox": "dist/keybox.js"
|
|
9
10
|
},
|
|
10
11
|
"files": [
|
|
11
12
|
"dist",
|
|
12
|
-
"assets"
|
|
13
|
+
"assets",
|
|
14
|
+
"LICENSE.md"
|
|
15
|
+
],
|
|
16
|
+
"keywords": [
|
|
17
|
+
"ai",
|
|
18
|
+
"agent",
|
|
19
|
+
"security",
|
|
20
|
+
"credentials",
|
|
21
|
+
"proxy",
|
|
22
|
+
"cloudflare-worker"
|
|
13
23
|
],
|
|
14
24
|
"engines": {
|
|
15
25
|
"node": ">=20"
|
|
@@ -18,7 +28,7 @@
|
|
|
18
28
|
"build": "node build.mjs",
|
|
19
29
|
"test": "vitest run",
|
|
20
30
|
"typecheck": "tsc --noEmit",
|
|
21
|
-
"prepublishOnly": "npm run build -w @
|
|
31
|
+
"prepublishOnly": "npm run build -w @keyboxed/worker --prefix .. && npm run build"
|
|
22
32
|
},
|
|
23
33
|
"dependencies": {
|
|
24
34
|
"wrangler": "4.164.0"
|