@celljs/ta-secrets 4.33.0 → 4.35.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/extension/index.mjs +0 -41
- package/host/index.mjs +90 -28
- package/package.json +4 -3
package/extension/index.mjs
CHANGED
|
@@ -169,47 +169,6 @@ var TaDoubleLookUtil;
|
|
|
169
169
|
}
|
|
170
170
|
TaDoubleLookUtil2.given = given;
|
|
171
171
|
})(TaDoubleLookUtil || (TaDoubleLookUtil = {}));
|
|
172
|
-
var TA_ASK_ENTRY = "ta-ask";
|
|
173
|
-
var TaAskUtil;
|
|
174
|
-
(function(TaAskUtil2) {
|
|
175
|
-
const LENGTH = 120;
|
|
176
|
-
function entry(question) {
|
|
177
|
-
const line = question.replace(/\s+/g, " ").trim();
|
|
178
|
-
return { question: line.length > LENGTH ? `${line.slice(0, LENGTH - 1)}…` : line };
|
|
179
|
-
}
|
|
180
|
-
TaAskUtil2.entry = entry;
|
|
181
|
-
function asking(entries) {
|
|
182
|
-
var _a;
|
|
183
|
-
for (let i = entries.length - 1;i >= 0; i--) {
|
|
184
|
-
const entry2 = entries[i];
|
|
185
|
-
if (entry2.type === "message" && ((_a = entry2.message) === null || _a === undefined ? undefined : _a.role) === "user") {
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
if (entry2.type === "custom" && entry2.customType === TA_ASK_ENTRY) {
|
|
189
|
-
return read(entry2);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
TaAskUtil2.asking = asking;
|
|
195
|
-
function next(asked, entry2) {
|
|
196
|
-
var _a;
|
|
197
|
-
if (entry2.type === "message" && ((_a = entry2.message) === null || _a === undefined ? undefined : _a.role) === "user") {
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
return entry2.type === "custom" && entry2.customType === TA_ASK_ENTRY ? read(entry2) : asked;
|
|
201
|
-
}
|
|
202
|
-
TaAskUtil2.next = next;
|
|
203
|
-
function read(found) {
|
|
204
|
-
var _a;
|
|
205
|
-
const question = (_a = found.data) === null || _a === undefined ? undefined : _a.question;
|
|
206
|
-
if (typeof question !== "string" || !question.trim()) {
|
|
207
|
-
return;
|
|
208
|
-
}
|
|
209
|
-
const at = found.timestamp ? Date.parse(found.timestamp) : Number.NaN;
|
|
210
|
-
return { question: entry(question).question, at: Number.isNaN(at) ? 0 : at };
|
|
211
|
-
}
|
|
212
|
-
})(TaAskUtil || (TaAskUtil = {}));
|
|
213
172
|
|
|
214
173
|
// web-src/command-prelude.ts
|
|
215
174
|
var CommandPrelude;
|
package/host/index.mjs
CHANGED
|
@@ -1,20 +1,85 @@
|
|
|
1
1
|
// web-src/proxy-certs.ts
|
|
2
2
|
import { generateKeyPairSync, randomBytes } from "node:crypto";
|
|
3
|
-
import { mkdtemp, readFile as readFile2, rm, writeFile as writeFile2 } from "node:fs/promises";
|
|
3
|
+
import { mkdtemp, readFile as readFile2, rm as rm2, writeFile as writeFile2 } from "node:fs/promises";
|
|
4
4
|
import { isIP } from "node:net";
|
|
5
5
|
import { tmpdir } from "node:os";
|
|
6
|
-
import { join as
|
|
6
|
+
import { join as join3 } from "node:path";
|
|
7
7
|
import * as tls from "node:tls";
|
|
8
8
|
|
|
9
9
|
// web-src/vault-store.ts
|
|
10
10
|
import { spawn } from "node:child_process";
|
|
11
|
-
import { mkdir
|
|
12
|
-
import { dirname, join } from "node:path";
|
|
11
|
+
import { mkdir as mkdir2, readFile } from "node:fs/promises";
|
|
12
|
+
import { dirname as dirname2, join as join2 } from "node:path";
|
|
13
|
+
|
|
14
|
+
// ../../packages/core/esm/node/fs/file-util.js
|
|
15
|
+
import { chmodSync, mkdirSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
16
|
+
import { chmod, mkdir, rename, rm, writeFile } from "node:fs/promises";
|
|
17
|
+
import { basename, dirname, join } from "node:path";
|
|
18
|
+
var written = 0;
|
|
19
|
+
var FileUtil;
|
|
20
|
+
(function(FileUtil2) {
|
|
21
|
+
function temporary(file, hidden = false) {
|
|
22
|
+
const n = `${process.pid}.${++written}`;
|
|
23
|
+
return hidden ? join(dirname(file), `.${basename(file)}.${n}.tmp`) : `${file}.${n}.tmp`;
|
|
24
|
+
}
|
|
25
|
+
FileUtil2.temporary = temporary;
|
|
26
|
+
function ownTemporary(name) {
|
|
27
|
+
return new RegExp(`\\.${process.pid}\\.\\d+\\.tmp$`).test(name);
|
|
28
|
+
}
|
|
29
|
+
FileUtil2.ownTemporary = ownTemporary;
|
|
30
|
+
function write(file, data, options = {}) {
|
|
31
|
+
if (options.mkdir !== false) {
|
|
32
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
33
|
+
}
|
|
34
|
+
const draft = temporary(file, options.hidden);
|
|
35
|
+
try {
|
|
36
|
+
writeFileSync(draft, data, options.mode === undefined ? undefined : { mode: options.mode });
|
|
37
|
+
if (options.mode !== undefined) {
|
|
38
|
+
chmodSync(draft, options.mode);
|
|
39
|
+
}
|
|
40
|
+
renameSync(draft, file);
|
|
41
|
+
} catch (error) {
|
|
42
|
+
rmSync(draft, { force: true });
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
FileUtil2.write = write;
|
|
47
|
+
async function writeAsync(file, data, options = {}) {
|
|
48
|
+
if (options.mkdir !== false) {
|
|
49
|
+
await mkdir(dirname(file), { recursive: true });
|
|
50
|
+
}
|
|
51
|
+
const draft = temporary(file, options.hidden);
|
|
52
|
+
try {
|
|
53
|
+
await writeFile(draft, data, options.mode === undefined ? undefined : { mode: options.mode });
|
|
54
|
+
if (options.mode !== undefined) {
|
|
55
|
+
await chmod(draft, options.mode);
|
|
56
|
+
}
|
|
57
|
+
await rename(draft, file);
|
|
58
|
+
} catch (error) {
|
|
59
|
+
await rm(draft, { force: true });
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
FileUtil2.writeAsync = writeAsync;
|
|
64
|
+
function writeJson(file, value, options = {}) {
|
|
65
|
+
write(file, json(value, options.pretty), options);
|
|
66
|
+
}
|
|
67
|
+
FileUtil2.writeJson = writeJson;
|
|
68
|
+
function writeJsonAsync(file, value, options = {}) {
|
|
69
|
+
return writeAsync(file, json(value, options.pretty), options);
|
|
70
|
+
}
|
|
71
|
+
FileUtil2.writeJsonAsync = writeJsonAsync;
|
|
72
|
+
function json(value, pretty = false) {
|
|
73
|
+
return pretty ? `${JSON.stringify(value, undefined, 2)}
|
|
74
|
+
` : JSON.stringify(value);
|
|
75
|
+
}
|
|
76
|
+
})(FileUtil || (FileUtil = {}));
|
|
77
|
+
// web-src/vault-store.ts
|
|
13
78
|
var VaultStores;
|
|
14
79
|
((VaultStores) => {
|
|
15
80
|
VaultStores.SERVICE = "Ta secrets";
|
|
16
81
|
function of(agentDir, env = process.env, platform = process.platform) {
|
|
17
|
-
return platform === "darwin" && env.TA_SECRETS_STORE !== "file" ? new MacKeychain : new FileVault(
|
|
82
|
+
return platform === "darwin" && env.TA_SECRETS_STORE !== "file" ? new MacKeychain : new FileVault(join2(agentDir, "secrets", "vault.json"));
|
|
18
83
|
}
|
|
19
84
|
VaultStores.of = of;
|
|
20
85
|
function run(command, args, input) {
|
|
@@ -92,11 +157,8 @@ class FileVault {
|
|
|
92
157
|
const next = this.queue.then(async () => {
|
|
93
158
|
const values = await this.read();
|
|
94
159
|
apply(values);
|
|
95
|
-
await
|
|
96
|
-
|
|
97
|
-
await writeFile(temporary, `${JSON.stringify(values, null, 2)}
|
|
98
|
-
`, { mode: 384 });
|
|
99
|
-
await rename(temporary, this.path);
|
|
160
|
+
await mkdir2(dirname2(this.path), { recursive: true, mode: 448 });
|
|
161
|
+
await FileUtil.writeJsonAsync(this.path, values, { mode: 384, pretty: true, mkdir: false });
|
|
100
162
|
});
|
|
101
163
|
this.queue = next.catch(() => {
|
|
102
164
|
return;
|
|
@@ -130,7 +192,7 @@ class ProxyCerts {
|
|
|
130
192
|
return (await this.made()).cert;
|
|
131
193
|
}
|
|
132
194
|
async cacertFile() {
|
|
133
|
-
const file =
|
|
195
|
+
const file = join3(await this.dir(), "ca-only.pem");
|
|
134
196
|
await writeFile2(file, await this.ca(), { mode: 384 });
|
|
135
197
|
return file;
|
|
136
198
|
}
|
|
@@ -158,7 +220,7 @@ class ProxyCerts {
|
|
|
158
220
|
})();
|
|
159
221
|
const extra = await Promise.all([process.env.NODE_EXTRA_CA_CERTS, process.env.SSL_CERT_FILE].filter(Boolean).map((file2) => readFile2(file2, "utf8").catch(() => "")));
|
|
160
222
|
const all = [...new Set([...tls.rootCertificates, ...system].map((cert) => cert.trim()))];
|
|
161
|
-
const file =
|
|
223
|
+
const file = join3(await this.dir(), "bundle.pem");
|
|
162
224
|
await writeFile2(file, `${[...all, ...extra.map((text) => text.trim()).filter(Boolean), (await this.ca()).trim()].join(`
|
|
163
225
|
`)}
|
|
164
226
|
`, { mode: 384 });
|
|
@@ -176,21 +238,21 @@ class ProxyCerts {
|
|
|
176
238
|
this.bundled = undefined;
|
|
177
239
|
this.leaves.clear();
|
|
178
240
|
if (folder) {
|
|
179
|
-
await
|
|
241
|
+
await rm2(await folder, { recursive: true, force: true }).catch(() => {
|
|
180
242
|
return;
|
|
181
243
|
});
|
|
182
244
|
}
|
|
183
245
|
}
|
|
184
246
|
dir() {
|
|
185
|
-
this.folder ??= mkdtemp(
|
|
247
|
+
this.folder ??= mkdtemp(join3(tmpdir(), "ta-vault-proxy-"));
|
|
186
248
|
return this.folder;
|
|
187
249
|
}
|
|
188
250
|
made() {
|
|
189
251
|
this.authority ??= (async () => {
|
|
190
252
|
const dir = await this.dir();
|
|
191
|
-
const key =
|
|
192
|
-
const cert =
|
|
193
|
-
const config =
|
|
253
|
+
const key = join3(dir, "ca.key");
|
|
254
|
+
const cert = join3(dir, "ca.pem");
|
|
255
|
+
const config = join3(dir, "ca.cnf");
|
|
194
256
|
await writeFile2(key, ProxyCerts.key(), { mode: 384 });
|
|
195
257
|
await writeFile2(config, CONFIG, { mode: 384 });
|
|
196
258
|
await this.run(["req", "-x509", "-new", "-key", key, "-out", cert, "-days", "365", "-sha256", "-config", config, "-extensions", "ca"]);
|
|
@@ -204,7 +266,7 @@ class ProxyCerts {
|
|
|
204
266
|
async sign(host) {
|
|
205
267
|
await this.made();
|
|
206
268
|
const dir = await this.dir();
|
|
207
|
-
const stem =
|
|
269
|
+
const stem = join3(dir, `leaf-${randomBytes(6).toString("hex")}`);
|
|
208
270
|
const key = ProxyCerts.key();
|
|
209
271
|
const san = isIP(host) ? `IP:${host}` : `DNS:${host}`;
|
|
210
272
|
await writeFile2(`${stem}.key`, key, { mode: 384 });
|
|
@@ -222,9 +284,9 @@ subjectAltName = ${san}
|
|
|
222
284
|
"-in",
|
|
223
285
|
`${stem}.csr`,
|
|
224
286
|
"-CA",
|
|
225
|
-
|
|
287
|
+
join3(dir, "ca.pem"),
|
|
226
288
|
"-CAkey",
|
|
227
|
-
|
|
289
|
+
join3(dir, "ca.key"),
|
|
228
290
|
"-set_serial",
|
|
229
291
|
`0x1${randomBytes(15).toString("hex")}`,
|
|
230
292
|
"-days",
|
|
@@ -238,7 +300,7 @@ subjectAltName = ${san}
|
|
|
238
300
|
`${stem}.pem`
|
|
239
301
|
]);
|
|
240
302
|
const cert = await readFile2(`${stem}.pem`, "utf8");
|
|
241
|
-
await Promise.all([".key", ".csr", ".cnf", ".ext", ".pem"].map((suffix) =>
|
|
303
|
+
await Promise.all([".key", ".csr", ".cnf", ".ext", ".pem"].map((suffix) => rm2(stem + suffix, { force: true })));
|
|
242
304
|
return { key, cert };
|
|
243
305
|
}
|
|
244
306
|
async run(args) {
|
|
@@ -607,9 +669,9 @@ ${auth}\r
|
|
|
607
669
|
|
|
608
670
|
// web-src/vault-service.ts
|
|
609
671
|
import { createHmac, randomBytes as randomBytes3 } from "node:crypto";
|
|
610
|
-
import { mkdtemp as mkdtemp2, readFile as readFile3, rm as
|
|
672
|
+
import { mkdtemp as mkdtemp2, readFile as readFile3, rm as rm3, writeFile as writeFile3 } from "node:fs/promises";
|
|
611
673
|
import { homedir, tmpdir as tmpdir2 } from "node:os";
|
|
612
|
-
import { join as
|
|
674
|
+
import { join as join4, resolve, sep } from "node:path";
|
|
613
675
|
|
|
614
676
|
// ../ta-protocol/esm/common/boundary-protocol.js
|
|
615
677
|
var TA_BOUNDARY_KINDS = ["general", "work", "private", "guest"];
|
|
@@ -1504,7 +1566,7 @@ class Vault {
|
|
|
1504
1566
|
return this.add({ name, value, note, source: "asked" });
|
|
1505
1567
|
}
|
|
1506
1568
|
isRemote(cwd) {
|
|
1507
|
-
const root = this.host.agentDir ?
|
|
1569
|
+
const root = this.host.agentDir ? join4(this.host.agentDir, "remote") : undefined;
|
|
1508
1570
|
return !!root && !!cwd && (cwd === root || cwd.startsWith(root + sep));
|
|
1509
1571
|
}
|
|
1510
1572
|
async prepare(command, place = {}) {
|
|
@@ -1573,16 +1635,16 @@ class Vault {
|
|
|
1573
1635
|
};
|
|
1574
1636
|
}
|
|
1575
1637
|
}
|
|
1576
|
-
const folder = await mkdtemp2(
|
|
1638
|
+
const folder = await mkdtemp2(join4(tmpdir2(), "ta-secrets-"));
|
|
1577
1639
|
const keyFiles = [];
|
|
1578
1640
|
for (const [index, entry] of keys.entries()) {
|
|
1579
|
-
const file2 =
|
|
1641
|
+
const file2 = join4(folder, `key-${index}`);
|
|
1580
1642
|
await writeFile3(file2, values.get(entry.name), { mode: 384 });
|
|
1581
1643
|
keyFiles.push(file2);
|
|
1582
1644
|
}
|
|
1583
|
-
const file =
|
|
1645
|
+
const file = join4(folder, "prelude");
|
|
1584
1646
|
await writeFile3(file, CommandPrelude.script({ env, git: credentials, keys: keyFiles, proxy }), { mode: 384 });
|
|
1585
|
-
setTimeout(() => void
|
|
1647
|
+
setTimeout(() => void rm3(folder, { recursive: true, force: true }), PRELUDE_MS).unref?.();
|
|
1586
1648
|
const bound = new Set(proxied.map((one) => one.name));
|
|
1587
1649
|
const how = [
|
|
1588
1650
|
...named.some((name) => !bound.has(name)) ? ["env"] : [],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@celljs/ta-secrets",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.35.0",
|
|
4
4
|
"description": "A pi package for Ta: a vault of secrets kept in the keychain, which Ta uses in commands by name without the model ever seeing them",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package"
|
|
@@ -27,8 +27,9 @@
|
|
|
27
27
|
"watch": "tsc -b -w --preserveWatchOutput"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@celljs/
|
|
31
|
-
"@celljs/ta-
|
|
30
|
+
"@celljs/core": "4.35.0",
|
|
31
|
+
"@celljs/ta-protocol": "4.35.0",
|
|
32
|
+
"@celljs/ta-web": "4.35.0",
|
|
32
33
|
"@types/react": "^19.3.0"
|
|
33
34
|
},
|
|
34
35
|
"publishConfig": {
|