{"version":95,"agent":"pinch","message":"Pipeline run key: when ABSO_KEY_FILE names a file holding an agent key and no token or folder key is set, the client sends that key (only to servers a token may go to), keeps it in memory only, and never prints it. abso join takes the agent from ABSO_AGENT for such a key; status and doctor name it as a pipeline run's key.","time":1791639382910,"timeIso":"2026-10-10T13:36:22.910Z","changes":5,"change":1062,"files":["client/src/config.ts","client/src/doctor.ts","client/src/join-commands.ts","client/test/run-key.test.ts"],"draft":null,"diff":[{"path":"client/src/config.ts","added":25,"removed":3,"diff":"--- a/client/src/config.ts\n+++ b/client/src/config.ts\n@@ -2,7 +2,8 @@\n // them, and the token.\n //\n // The token is never in the folder: it comes from the ABSO_TOKEN environment\n-// variable, or else from ~/.avcs/token, outside every repo.\n+// variable, or else from ~/.avcs/token, outside every repo. A pipeline run's\n+// key comes from the file ABSO_KEY_FILE names, and is only ever held in memory.\n \n import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from \"node:fs\";\n import { homedir } from \"node:os\";\n@@ -97,12 +98,14 @@\n \troot: string,\n \tserver: string,\n \tenv: Readonly<Record<string, string | undefined>> = process.env,\n-): { kind: \"agent key\" | \"shared token\" | \"none\"; id: string | null } {\n+): { kind: \"agent key\" | \"shared token\" | \"pipeline run key\" | \"none\"; id: string | null } {\n \tconst key = readKeyFile(root);\n \tif (key) {\n \t\tif (originOf(key.server) !== originOf(server)) return { kind: \"none\", id: null };\n \t\treturn { kind: \"agent key\", id: key.id };\n \t}\n+\tif (fromEnv(env, \"TOKEN\")) return { kind: \"shared token\", id: null };\n+\tif (fromEnv(env, \"KEY_FILE\")) return { kind: \"pipeline run key\", id: null };\n \treturn { kind: readToken(env) ? \"shared token\" : \"none\", id: null };\n }\n \n@@ -184,7 +187,7 @@\n \t\t\treturn key.key;\n \t\t}\n \t}\n-\tconst token = readToken(env);\n+\tconst token = fromEnv(env, \"TOKEN\")?.trim() || runKey(env) || readToken(env);\n \tconst trusted = trustedServers(env);\n \tif (token === undefined || tokenGoesTo(server, trusted)) return token;\n \tthrow new UsageError(\n@@ -213,6 +216,25 @@\n \treturn trustedList(fromEnv(env, \"TRUSTED_SERVERS\"), readMachineServers(env));\n }\n \n+/**\n+ * A pipeline run's key, from the file ABSO_KEY_FILE names (the runner writes it, mode 600, holding the bare key).\n+ * Read each time and kept in memory only; nothing abso writes or prints holds it, errors included.\n+ */\n+export function runKey(env: Readonly<Record<string, string | undefined>> = process.env): string | undefined {\n+\tconst path = fromEnv(env, \"KEY_FILE\");\n+\tif (!path) return undefined;\n+\tlet text: string;\n+\ttry {\n+\t\ttext = readFileSync(path, \"utf8\");\n+\t} catch {\n+\t\tthrow new UsageError(`ABSO_KEY_FILE names ${path}, which abso can't read`);\n+\t}\n+\tconst key = text.trim();\n+\tif (!/^abso_sk_[A-Za-z0-9_-]+$/.test(key))\n+\t\tthrow new UsageError(`ABSO_KEY_FILE names ${path}, which doesn't hold an abso key`);\n+\treturn key;\n+}\n+\n /** ABSO_TOKEN if set, else ~/.abso/token, else ~/.avcs/token, else none. */\n export function readToken(env: Readonly<Record<string, string | undefined>> = process.env): string | undefined {\n \tconst fromVar = fromEnv(env, \"TOKEN\");"},{"path":"client/src/doctor.ts","added":7,"removed":1,"diff":"--- a/client/src/doctor.ts\n+++ b/client/src/doctor.ts\n@@ -83,7 +83,13 @@\n \n function credentialWords(root: string, server: string, env: Readonly<Record<string, string | undefined>>): string {\n \tconst c = credentialLabel(root, server, env);\n-\treturn c.kind === \"agent key\" ? `the agent key ${c.id}` : c.kind === \"shared token\" ? \"the shared token\" : \"no key\";\n+\treturn c.kind === \"agent key\"\n+\t\t? `the agent key ${c.id}`\n+\t\t: c.kind === \"shared token\"\n+\t\t\t? \"the shared token\"\n+\t\t\t: c.kind === \"pipeline run key\"\n+\t\t\t\t? \"a pipeline run's key\"\n+\t\t\t\t: \"no key\";\n }\n \n export async function whoami("},{"path":"client/src/join-commands.ts","added":9,"removed":3,"diff":"--- a/client/src/join-commands.ts\n+++ b/client/src/join-commands.ts\n@@ -36,8 +36,8 @@\n \n const NAME = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;\n \n-function agentFrom(args: Parsed): string {\n-\tconst agent = str(args, \"agent\");\n+function agentFrom(args: Parsed, named?: string): string {\n+\tconst agent = named ?? str(args, \"agent\");\n \tif (!agent) throw new UsageError(\"give this folder's agent name with --agent <name>\");\n \tif (!NAME.test(agent))\n \t\tthrow new UsageError(`agent names are letters, digits, dot, dash and underscore (got ${JSON.stringify(agent)})`);\n@@ -193,7 +193,13 @@\n \tlet minted: { key: string; id: string } | undefined;\n \tif (str(args, \"agent\") !== undefined) {\n \t\tagent = agentFrom(args);\n-\t\tminted = box && !hasKey ? await mintKey(box, project, agent) : undefined;\n+\t\tminted = box && !hasKey && !fromEnv(env.env, \"KEY_FILE\") ? await mintKey(box, project, agent) : undefined;\n+\t} else if (fromEnv(env.env, \"KEY_FILE\")) {\n+\t\t// A pipeline run's key (ABSO_KEY_FILE) belongs to one agent, which the runner names in ABSO_AGENT.\n+\t\tconst named = fromEnv(env.env, \"AGENT\");\n+\t\tif (!named)\n+\t\t\tthrow new UsageError(\"a pipeline run's key joins as its own agent: give it with --agent <name> or ABSO_AGENT\");\n+\t\tagent = agentFrom(args, named);\n \t} else {\n \t\t// No --agent: the box's name, or the next free -2, -3. Not signed in, --reader reads a public project signed out.\n \t\tif (!box && reader && !hasKey && (await isPublic(server, project)))"},{"path":"client/test/run-key.test.ts","added":96,"removed":0,"diff":"--- /dev/null\n+++ b/client/test/run-key.test.ts\n@@ -0,0 +1,96 @@\n+// A pipeline run's key (ABSO_KEY_FILE): read from the file the runner wrote, sent only where a token may go,\n+// held in memory only, and a run key's refusals reach the job as the server wrote them.\n+\n+import assert from \"node:assert/strict\";\n+import { mkdtempSync, writeFileSync } from \"node:fs\";\n+import { createServer } from \"node:http\";\n+import type { AddressInfo } from \"node:net\";\n+import { tmpdir } from \"node:os\";\n+import { join } from \"node:path\";\n+import { test } from \"node:test\";\n+import { Api, ApiError } from \"../src/api.ts\";\n+import { credentialLabel, installKey, readConfig, runKey, tokenFor, writeConfig } from \"../src/config.ts\";\n+\n+const KEY = \"abso_sk_runkeyabcdefghijklmnopqrstuvwx\";\n+const LOCAL = \"http://127.0.0.1:8787\";\n+\n+function keyFile(text: string): string {\n+\tconst path = join(mkdtempSync(join(tmpdir(), \"abso-run-key-\")), \"key\");\n+\twriteFileSync(path, text);\n+\treturn path;\n+}\n+\n+function folder(server = LOCAL) {\n+\tconst root = mkdtempSync(join(tmpdir(), \"abso-run-key-\"));\n+\twriteConfig(root, { server, project: \"p\", agent: \"run-7-check-test\" });\n+\treturn root;\n+}\n+\n+const NO_SERVERS = { ABSO_SERVERS_FILE: \"no-servers.json\" };\n+\n+test(\"ABSO_KEY_FILE's key is the credential when no token or folder key is set\", () => {\n+\tconst env = { ...NO_SERVERS, ABSO_KEY_FILE: keyFile(KEY) };\n+\tassert.equal(runKey(env), KEY);\n+\tassert.equal(tokenFor(LOCAL, env, folder()), KEY);\n+\tassert.deepEqual(credentialLabel(folder(), LOCAL, env), { kind: \"pipeline run key\", id: null });\n+\tassert.equal(readConfig(folder(), env).token, KEY);\n+});\n+\n+test(\"a trailing newline in the key file is not part of the key\", () => {\n+\tassert.equal(runKey({ ABSO_KEY_FILE: keyFile(`${KEY}\\n`) }), KEY);\n+});\n+\n+test(\"ABSO_TOKEN and a folder's own key both come before the run key\", () => {\n+\tconst env = { ...NO_SERVERS, ABSO_KEY_FILE: keyFile(KEY), ABSO_TOKEN: \"shared-token-value\" };\n+\tassert.equal(tokenFor(LOCAL, env, folder()), \"shared-token-value\");\n+\tassert.deepEqual(credentialLabel(folder(), LOCAL, env), { kind: \"shared token\", id: null });\n+\tconst root = folder();\n+\tinstallKey(root, JSON.stringify({ key: \"abso_sk_folderkeyabcdefghijklmnopqrstu\", id: \"k_ab12cd34\" }));\n+\tassert.equal(\n+\t\ttokenFor(LOCAL, { ...NO_SERVERS, ABSO_KEY_FILE: keyFile(KEY) }, root),\n+\t\t\"abso_sk_folderkeyabcdefghijklmnopqrstu\",\n+\t);\n+});\n+\n+test(\"the run key goes only where a token may, and the refusal doesn't hold it\", () => {\n+\tconst env = { ...NO_SERVERS, ABSO_KEY_FILE: keyFile(KEY) };\n+\tassert.throws(\n+\t\t() => tokenFor(\"https://someone-else.example\", env, folder(\"https://someone-else.example\")),\n+\t\t(err: Error) => /sends your token only to/.test(err.message) && !err.message.includes(KEY),\n+\t);\n+});\n+\n+test(\"a key file abso can't read, or that holds no key, is named without its contents\", () => {\n+\tconst missing = join(tmpdir(), \"abso-no-such-key-file\");\n+\tassert.throws(() => runKey({ ABSO_KEY_FILE: missing }), /can't read/);\n+\tconst wrong = keyFile(\"not-a-key secret-looking-text\");\n+\tassert.throws(\n+\t\t() => runKey({ ABSO_KEY_FILE: wrong }),\n+\t\t(err: Error) => /doesn't hold an abso key/.test(err.message) && !err.message.includes(\"secret-looking-text\"),\n+\t);\n+});\n+\n+test(\"a run key's refusal reaches the job as the server wrote it, and without the key\", async () => {\n+\tlet sent = \"\";\n+\tconst server = createServer((req, res) => {\n+\t\tsent = req.headers.authorization ?? \"\";\n+\t\tres.writeHead(403, { \"content-type\": \"application/json\" });\n+\t\tres.end(JSON.stringify({ error: \"a pipeline run's key can't land\" }));\n+\t});\n+\tawait new Promise<void>((ok) => server.listen(0, \"127.0.0.1\", ok));\n+\ttry {\n+\t\tconst url = `http://127.0.0.1:${(server.address() as AddressInfo).port}`;\n+\t\tconst config = readConfig(folder(url), { ...NO_SERVERS, ABSO_KEY_FILE: keyFile(KEY) });\n+\t\tawait assert.rejects(\n+\t\t\tnew Api(config).land(\"try\"),\n+\t\t\t(err: Error) =>\n+\t\t\t\terr instanceof ApiError &&\n+\t\t\t\terr.status === 403 &&\n+\t\t\t\t/a pipeline run's key can't land/.test(err.message) &&\n+\t\t\t\t!err.message.includes(KEY),\n+\t\t);\n+\t\tassert.equal(sent, `Bearer ${KEY}`);\n+\t} finally {\n+\t\tserver.close();\n+\t}\n+});"}],"ci":null}