overvues 0.0.1 → 0.4.10

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.
Files changed (78) hide show
  1. package/README.md +58 -2
  2. package/dist/ansi.js +24 -0
  3. package/dist/attach-client.js +586 -0
  4. package/dist/auth-connect-browser.js +112 -0
  5. package/dist/auth-connect.js +306 -0
  6. package/dist/browser-bootstrap.js +190 -0
  7. package/dist/browser-loopback.js +289 -0
  8. package/dist/build-identity.js +6 -0
  9. package/dist/codex-reviewer-apparmor.json +4 -0
  10. package/dist/codex-reviewer-seccomp.json +1238 -0
  11. package/dist/codex-runtime-protocol.js +1 -0
  12. package/dist/codex-subscription.js +53 -0
  13. package/dist/config.js +297 -0
  14. package/dist/connect-comparison-code.js +26 -0
  15. package/dist/development-runner.js +109 -0
  16. package/dist/dns-doctor.js +390 -0
  17. package/dist/docker-names.js +47 -0
  18. package/dist/doctor.js +114 -0
  19. package/dist/gadget-job.js +804 -0
  20. package/dist/health-check.js +112 -0
  21. package/dist/help.js +71 -0
  22. package/dist/host-auth.js +22 -0
  23. package/dist/host-diagnostics.js +20 -0
  24. package/dist/host-runtime-identity.js +39 -0
  25. package/dist/host-runtime-metadata.js +56 -0
  26. package/dist/host-service.js +377 -0
  27. package/dist/host-stack.js +484 -0
  28. package/dist/host-supervisor.js +237 -0
  29. package/dist/host-update.js +387 -0
  30. package/dist/hub-address.js +100 -0
  31. package/dist/hub-client.js +459 -0
  32. package/dist/hub-kind.js +88 -0
  33. package/dist/identity.js +73 -0
  34. package/dist/index.js +185 -0
  35. package/dist/init.js +295 -0
  36. package/dist/isolated-run-cache.js +116 -0
  37. package/dist/local-stack.js +685 -0
  38. package/dist/machine-capacity.js +128 -0
  39. package/dist/managed-runner-image.js +13 -0
  40. package/dist/os-acted-record.js +49 -0
  41. package/dist/os-adapter.js +8190 -0
  42. package/dist/os-command.js +292 -0
  43. package/dist/os-handoff.js +274 -0
  44. package/dist/os-keychain.js +247 -0
  45. package/dist/os-machine.js +818 -0
  46. package/dist/os-owner.js +61 -0
  47. package/dist/os-private-file.js +98 -0
  48. package/dist/os-protocol.js +468 -0
  49. package/dist/os-session-store.js +133 -0
  50. package/dist/os-status.js +102 -0
  51. package/dist/picker.js +863 -0
  52. package/dist/portable-workspace-capability.js +60 -0
  53. package/dist/project-environment-capability.js +62 -0
  54. package/dist/project-environment.js +28 -0
  55. package/dist/project-preparation.js +134 -0
  56. package/dist/readiness.js +28 -0
  57. package/dist/redaction.js +27 -0
  58. package/dist/reviewer-isolation-capability.js +61 -0
  59. package/dist/runner-api-auth.js +80 -0
  60. package/dist/runner-command-fence.js +536 -0
  61. package/dist/runner-inspection.js +57 -0
  62. package/dist/runner-inventory.js +587 -0
  63. package/dist/runner-server.js +2520 -0
  64. package/dist/runner-session.js +470 -0
  65. package/dist/runner-slug-folder.js +39 -0
  66. package/dist/runner-slug.js +40 -0
  67. package/dist/setup.js +139 -0
  68. package/dist/shutdown.js +102 -0
  69. package/dist/splash.js +65 -0
  70. package/dist/staged-workspaces.js +441 -0
  71. package/dist/staging-disk.js +97 -0
  72. package/dist/terminal-lane.js +339 -0
  73. package/dist/terminal-recovery.js +502 -0
  74. package/licenses/capnweb.txt +23 -0
  75. package/licenses/moby-profiles.txt +212 -0
  76. package/licenses/ws.txt +22 -0
  77. package/package.json +28 -7
  78. package/cli.js +0 -2
@@ -0,0 +1,247 @@
1
+ // The OS session in the Mac's login keychain.
2
+ //
3
+ // `tiller` talks to the keychain through `/usr/bin/security`, which is part of macOS: no native
4
+ // module is added.
5
+ //
6
+ // - Writing: the item is handed to `security -i` on its standard input, so the session is
7
+ // never a command-line argument and never in the environment.
8
+ // - Reading: `security find-generic-password -w` writes it to a pipe only `tiller` reads.
9
+ // - The keychain is named by its full path, the login keychain of the user `tiller` runs as.
10
+ // The search list is not used, so an item of the same name in another keychain is not read.
11
+ // Items in this keychain stay on this Mac: they are not synced by iCloud.
12
+ // - An item made by `security` may be read again by `security` without a prompt, while the
13
+ // keychain is unlocked. That is what lets the `tiller host` daemon use it unattended. It
14
+ // also means any program running as this person can ask `security` for it: the keychain
15
+ // protects against a copy, a backup or a mount of the home folder, not against that.
16
+ // - What is not secret (the OS address, the account, when the session ends) is kept beside it
17
+ // in `<config folder>/os/session-keychain.json`, so `tiller os status` and the daemon's
18
+ // report to the Hub never touch the keychain and can never cause an unlock prompt.
19
+ // - The item carries the OS address and account it was saved for. They must match the file
20
+ // beside it, so editing that file cannot send the session to another address.
21
+ // - A locked keychain, a refused prompt or a missing item is `OsSessionUnavailableError`. The
22
+ // caller shows "unlock"; nothing here falls back to the file store.
23
+ import { spawnSync } from "node:child_process";
24
+ import { createHash } from "node:crypto";
25
+ import { userInfo } from "node:os";
26
+ import { join } from "node:path";
27
+ import { osFolder, readPrivateFile, removePrivateFile, writePrivateFile } from "./os-private-file.js";
28
+ import { OsSessionUnavailableError, osSessionInfo } from "./os-session-store.js";
29
+ import { CLI, OS } from "./identity.js";
30
+ // `dev.paperwing.tiller.os-session` or `dev.paperwing.overvues.os-session` (identity.ts).
31
+ export const KEYCHAIN_SERVICE = CLI.keychainService;
32
+ const SECURITY = "/usr/bin/security";
33
+ const ITEM_PREFIX = "tiller-os-1.";
34
+ const KEYCHAIN_ACCOUNT = new RegExp(`^${CLI.keychainAccountPrefix}-[0-9a-f]{16}$`);
35
+ const ITEM_VALUE = /^tiller-os-1\.[A-Za-z0-9_-]+$/;
36
+ /** `security`'s exit status is the low byte of the keychain's own error number. */
37
+ const EXIT_NOT_FOUND = 44; // errSecItemNotFound, -25300
38
+ const EXIT_INTERACTION_NOT_ALLOWED = 36; // errSecInteractionNotAllowed, -25308: locked, and nobody to ask
39
+ const EXIT_AUTH_FAILED = 51; // errSecAuthFailed, -25293
40
+ const EXIT_USER_CANCELLED = 128; // userCanceledErr, -128
41
+ /** The daemon does not ask the keychain again for this long after it said no, so a prompt is not shown over and over. */
42
+ export const KEYCHAIN_RETRY_MS = 2 * 60_000;
43
+ const runSecurity = (args, input, timeoutMs) => {
44
+ // A test never reaches a real keychain: it names a stand-in for `security`.
45
+ if (process.env.VITEST)
46
+ throw new Error("The real keychain is not used in tests.");
47
+ const result = spawnSync(SECURITY, args, {
48
+ input: input ?? "", encoding: "utf8", timeout: timeoutMs, maxBuffer: 1024 * 1024, stdio: ["pipe", "pipe", "pipe"], windowsHide: true,
49
+ });
50
+ const code = result.error?.code;
51
+ return {
52
+ status: result.status, stdout: result.stdout ?? "", stderr: result.stderr ?? "",
53
+ timedOut: code === "ETIMEDOUT" || result.signal === "SIGTERM", failedToStart: Boolean(result.error) && code !== "ETIMEDOUT",
54
+ };
55
+ };
56
+ const isText = (value) => typeof value === "string" && value.length > 0;
57
+ /** The login keychain of the user this process runs as, from the system's own record of that user. */
58
+ export function loginKeychainPath() {
59
+ return join(userInfo().homedir, "Library", "Keychains", "login.keychain-db");
60
+ }
61
+ /** One item per config folder, so two installs on one Mac do not share a session. */
62
+ export function keychainAccountFor(configDir) {
63
+ return `${CLI.keychainAccountPrefix}-${createHash("sha256").update(configDir).digest("hex").slice(0, 16)}`;
64
+ }
65
+ function unlockMessage(what) {
66
+ return `${what} Unlock it (log in at this Mac, or open Keychain Access and unlock "login"), then try again. `
67
+ + "The session is still there; nothing else on this machine is used in its place.";
68
+ }
69
+ function failure(result, doing) {
70
+ if (result.failedToStart)
71
+ return new OsSessionUnavailableError("unreadable", `The Mac keychain could not be asked (${doing}): /usr/bin/security did not start.`);
72
+ if (result.timedOut || result.status === EXIT_INTERACTION_NOT_ALLOWED || /interaction is not allowed/i.test(result.stderr)) {
73
+ return new OsSessionUnavailableError("locked", unlockMessage(`The Mac keychain that holds this machine's ${OS.noun} session is locked.`));
74
+ }
75
+ if (result.status === EXIT_USER_CANCELLED || result.status === EXIT_AUTH_FAILED || /user canceled|not correct|authorization/i.test(result.stderr)) {
76
+ return new OsSessionUnavailableError("denied", unlockMessage(`The Mac keychain did not let ${CLI.command} use this machine's ${OS.noun} session.`));
77
+ }
78
+ // The status only: `security`'s own words may name the item, and are not needed.
79
+ return new OsSessionUnavailableError("unreadable", `The Mac keychain could not be used (${doing}, status ${result.status ?? "none"}).`);
80
+ }
81
+ /** The session in the Mac's login keychain, with its non-secret parts in a file beside `tiller`'s settings. */
82
+ export function keychainOsSessionStore(configDir, options = {}) {
83
+ const run = options.runSecurity ?? runSecurity;
84
+ const now = options.now ?? Date.now;
85
+ const timeoutMs = options.interactive ? 120_000 : 4_000;
86
+ const recordPath = join(osFolder(configDir), "session-keychain.json");
87
+ const keychainPath = () => {
88
+ const path = options.keychainPath ?? loginKeychainPath();
89
+ // The path is written into a line `security -i` reads; these would end or split that line.
90
+ if (/["\\\r\n\0]/.test(path))
91
+ throw new OsSessionUnavailableError("unreadable", "The path of the Mac keychain cannot be used.");
92
+ return path;
93
+ };
94
+ /** The session last read, for the record it was read under, so the daemon does not ask the keychain for every request. */
95
+ let held = null;
96
+ let refused = null;
97
+ const readRecord = () => {
98
+ const text = readPrivateFile(recordPath);
99
+ if (text === null)
100
+ return null;
101
+ let parsed;
102
+ try {
103
+ parsed = JSON.parse(text);
104
+ }
105
+ catch {
106
+ parsed = null;
107
+ }
108
+ const record = parsed;
109
+ if (!record || record.version !== 1 || record.store !== "keychain" || !isText(record.osUrl) || !isText(record.savedAt)
110
+ || !record.account || !isText(record.account.id) || typeof record.account.name !== "string"
111
+ || record.keychain?.service !== KEYCHAIN_SERVICE || !KEYCHAIN_ACCOUNT.test(record.keychain.account ?? "")) {
112
+ throw new OsSessionUnavailableError("unreadable", `This machine's note of its ${OS.noun} session cannot be read. Run \`${CLI.command} os forget\`, then \`${CLI.command} os connect\`.`);
113
+ }
114
+ return {
115
+ store: "keychain", osUrl: record.osUrl, account: { id: record.account.id, name: record.account.name }, savedAt: record.savedAt,
116
+ ...(isText(record.expiresAt) ? { expiresAt: record.expiresAt } : {}),
117
+ ...(record.connectedBy === "handoff" ? { connectedBy: record.connectedBy } : {}),
118
+ keychain: { service: KEYCHAIN_SERVICE, account: record.keychain.account },
119
+ };
120
+ };
121
+ const readItem = (account) => {
122
+ const result = run(["find-generic-password", "-a", account, "-s", KEYCHAIN_SERVICE, "-w", keychainPath()], undefined, timeoutMs);
123
+ if (result.status === 0 && !result.timedOut)
124
+ return { value: result.stdout.replace(/\r?\n$/, ""), result };
125
+ return { value: null, result };
126
+ };
127
+ const deleteItem = (account) => {
128
+ const result = run(["delete-generic-password", "-a", account, "-s", KEYCHAIN_SERVICE, keychainPath()], undefined, timeoutMs);
129
+ if (result.status === 0 && !result.timedOut)
130
+ return true;
131
+ if (result.status === EXIT_NOT_FOUND)
132
+ return false;
133
+ throw failure(result, "removing the session");
134
+ };
135
+ return {
136
+ describe() {
137
+ const record = readRecord();
138
+ if (!record)
139
+ return null;
140
+ const { keychain: _item, ...info } = record;
141
+ return info;
142
+ },
143
+ unavailable() {
144
+ if (!refused)
145
+ return null;
146
+ let record = null;
147
+ try {
148
+ record = readRecord();
149
+ }
150
+ catch {
151
+ record = null;
152
+ }
153
+ return record && JSON.stringify(record) === refused.key ? refused.error : null;
154
+ },
155
+ load() {
156
+ const record = readRecord();
157
+ if (!record) {
158
+ held = null;
159
+ refused = null;
160
+ return null;
161
+ }
162
+ const key = JSON.stringify(record);
163
+ if (held?.key === key)
164
+ return { ...held.stored, account: { ...held.stored.account } };
165
+ held = null;
166
+ if (!options.interactive && refused?.key === key && now() - refused.at < KEYCHAIN_RETRY_MS)
167
+ throw refused.error;
168
+ refused = null;
169
+ const { value, result } = readItem(record.keychain.account);
170
+ if (value === null) {
171
+ const error = result.status === EXIT_NOT_FOUND
172
+ ? new OsSessionUnavailableError("missing", `The Mac keychain no longer holds this machine's ${OS.noun} session. Run \`${CLI.command} os connect\` at this machine.`)
173
+ : failure(result, "reading the session");
174
+ refused = { key, at: now(), error };
175
+ throw error;
176
+ }
177
+ let inside = null;
178
+ if (ITEM_VALUE.test(value)) {
179
+ try {
180
+ inside = JSON.parse(Buffer.from(value.slice(ITEM_PREFIX.length), "base64url").toString("utf8"));
181
+ }
182
+ catch {
183
+ inside = null;
184
+ }
185
+ }
186
+ if (!inside || !isText(inside.session) || inside.osUrl !== record.osUrl || inside.accountId !== record.account.id || inside.savedAt !== record.savedAt) {
187
+ // Says nothing about the content: part of it may be a session.
188
+ const error = new OsSessionUnavailableError("unreadable", `The ${OS.noun} session in the Mac keychain does not belong with this machine's note of it. Run \`${CLI.command} os forget\`, then \`${CLI.command} os connect\`.`);
189
+ refused = { key, at: now(), error };
190
+ throw error;
191
+ }
192
+ const { keychain: _item, store: _store, ...rest } = record;
193
+ const stored = { ...rest, session: inside.session };
194
+ held = { key, stored };
195
+ return { ...stored, account: { ...stored.account } };
196
+ },
197
+ save(session) {
198
+ held = null;
199
+ refused = null;
200
+ const account = keychainAccountFor(configDir);
201
+ const value = ITEM_PREFIX + Buffer.from(JSON.stringify({
202
+ osUrl: session.osUrl, session: session.session, accountId: session.account.id, savedAt: session.savedAt,
203
+ }), "utf8").toString("base64url");
204
+ // One line for `security -i`. Every part is from a fixed alphabet but the path, which is quoted and was checked.
205
+ const line = `add-generic-password -U -a ${account} -s ${KEYCHAIN_SERVICE} -l "Overvues session" -D "application password" -w ${value} "${keychainPath()}"\n`;
206
+ const added = run(["-i"], line, timeoutMs);
207
+ if (added.status !== 0 || added.timedOut)
208
+ throw failure(added, "saving the session");
209
+ // Believed only when it reads back: the daemon will read it the same way.
210
+ const { value: back, result } = readItem(account);
211
+ if (back !== value) {
212
+ try {
213
+ deleteItem(account);
214
+ }
215
+ catch { /* nothing more can be done here */ }
216
+ throw back === null ? failure(result, "reading the session back") : new OsSessionUnavailableError("unreadable", "The Mac keychain did not keep the session as it was given. Nothing was stored.");
217
+ }
218
+ const record = { version: 1, ...osSessionInfo(session, "keychain"), store: "keychain", keychain: { service: KEYCHAIN_SERVICE, account } };
219
+ try {
220
+ writePrivateFile(recordPath, `${JSON.stringify(record, null, 2)}\n`);
221
+ }
222
+ catch (error) {
223
+ try {
224
+ deleteItem(account);
225
+ }
226
+ catch { /* the note is what makes the item used; without it the item is inert */ }
227
+ throw error;
228
+ }
229
+ },
230
+ forget() {
231
+ held = null;
232
+ refused = null;
233
+ let record = null;
234
+ let unreadable = false;
235
+ try {
236
+ record = readRecord();
237
+ }
238
+ catch {
239
+ unreadable = true;
240
+ }
241
+ // An item may be there without a readable note of it (a save that was cut short).
242
+ const removed = deleteItem(record?.keychain.account ?? keychainAccountFor(configDir));
243
+ const hadRecord = removePrivateFile(recordPath);
244
+ return removed || hadRecord || unreadable;
245
+ },
246
+ };
247
+ }