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. Version 95 of shared· pinch· Oct 10 (2026-10-10 13:36 UTC) · Not checked
Version 94 · Files at version 95
4 files, 137 lines added, 7 removed.
--- a/client/src/config.ts
+++ b/client/src/config.ts
@@ -2,7 +2,8 @@
2 2 // them, and the token. 4 4 // The token is never in the folder: it comes from the ABSO_TOKEN environment 5 − // variable, or else from ~/.avcs/token, outside every repo.
5 + // variable, or else from ~/.avcs/token, outside every repo. A pipeline run's 6 + // key comes from the file ABSO_KEY_FILE names, and is only ever held in memory. 7 8 import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs"; 8 9 import { homedir } from "node:os"; @@ -97,12 +98,14 @@
99 100 env: Readonly<Record<string, string | undefined>> = process.env, 100 − ): { kind: "agent key" | "shared token" | "none"; id: string | null } {
101 + ): { kind: "agent key" | "shared token" | "pipeline run key" | "none"; id: string | null } { 101 102 const key = readKeyFile(root); 103 104 if (originOf(key.server) !== originOf(server)) return { kind: "none", id: null }; 104 105 return { kind: "agent key", id: key.id }; 107 + if (fromEnv(env, "TOKEN")) return { kind: "shared token", id: null }; 108 + if (fromEnv(env, "KEY_FILE")) return { kind: "pipeline run key", id: null }; 106 109 return { kind: readToken(env) ? "shared token" : "none", id: null }; @@ -184,7 +187,7 @@
187 − const token = readToken(env);
190 + const token = fromEnv(env, "TOKEN")?.trim() || runKey(env) || readToken(env); 188 191 const trusted = trustedServers(env); 189 192 if (token === undefined || tokenGoesTo(server, trusted)) return token; 190 193 throw new UsageError( @@ -213,6 +216,25 @@
213 216 return trustedList(fromEnv(env, "TRUSTED_SERVERS"), readMachineServers(env)); 220 + * A pipeline run's key, from the file ABSO_KEY_FILE names (the runner writes it, mode 600, holding the bare key). 221 + * Read each time and kept in memory only; nothing abso writes or prints holds it, errors included. 223 + export function runKey(env: Readonly<Record<string, string | undefined>> = process.env): string | undefined { 224 + const path = fromEnv(env, "KEY_FILE"); 225 + if (!path) return undefined; 228 + text = readFileSync(path, "utf8"); 230 + throw new UsageError(`ABSO_KEY_FILE names ${path}, which abso can't read`); 232 + const key = text.trim(); 233 + if (!/^abso_sk_[A-Za-z0-9_-]+$/.test(key)) 234 + throw new UsageError(`ABSO_KEY_FILE names ${path}, which doesn't hold an abso key`); 216 238 /** ABSO_TOKEN if set, else ~/.abso/token, else ~/.avcs/token, else none. */ 217 239 export function readToken(env: Readonly<Record<string, string | undefined>> = process.env): string | undefined { 218 240 const fromVar = fromEnv(env, "TOKEN"); --- a/client/src/doctor.ts
+++ b/client/src/doctor.ts
@@ -83,7 +83,13 @@
84 84 function credentialWords(root: string, server: string, env: Readonly<Record<string, string | undefined>>): string { 85 85 const c = credentialLabel(root, server, env); 86 − return c.kind === "agent key" ? `the agent key ${c.id}` : c.kind === "shared token" ? "the shared token" : "no key";
86 + return c.kind === "agent key" 87 + ? `the agent key ${c.id}` 88 + : c.kind === "shared token" 90 + : c.kind === "pipeline run key" 91 + ? "a pipeline run's key" 89 95 export async function whoami( --- a/client/src/join-commands.ts
+++ b/client/src/join-commands.ts
@@ -36,8 +36,8 @@
37 37 const NAME = /^[A-Za-z0-9][A-Za-z0-9._-]*$/; 39 − function agentFrom(args: Parsed): string {
40 − const agent = str(args, "agent");
39 + function agentFrom(args: Parsed, named?: string): string { 40 + const agent = named ?? str(args, "agent"); 41 41 if (!agent) throw new UsageError("give this folder's agent name with --agent <name>"); 42 42 if (!NAME.test(agent)) 43 43 throw new UsageError(`agent names are letters, digits, dot, dash and underscore (got ${JSON.stringify(agent)})`); @@ -193,7 +193,13 @@
193 193 let minted: { key: string; id: string } | undefined; 194 194 if (str(args, "agent") !== undefined) { 195 195 agent = agentFrom(args); 196 − minted = box && !hasKey ? await mintKey(box, project, agent) : undefined;
196 + minted = box && !hasKey && !fromEnv(env.env, "KEY_FILE") ? await mintKey(box, project, agent) : undefined; 197 + } else if (fromEnv(env.env, "KEY_FILE")) { 198 + // A pipeline run's key (ABSO_KEY_FILE) belongs to one agent, which the runner names in ABSO_AGENT. 199 + const named = fromEnv(env.env, "AGENT"); 201 + throw new UsageError("a pipeline run's key joins as its own agent: give it with --agent <name> or ABSO_AGENT"); 202 + agent = agentFrom(args, named); 198 204 // No --agent: the box's name, or the next free -2, -3. Not signed in, --reader reads a public project signed out. 199 205 if (!box && reader && !hasKey && (await isPublic(server, project))) --- /dev/null
+++ b/client/test/run-key.test.ts
@@ -0,0 +1,96 @@
1 + // A pipeline run's key (ABSO_KEY_FILE): read from the file the runner wrote, sent only where a token may go, 2 + // held in memory only, and a run key's refusals reach the job as the server wrote them. 4 + import assert from "node:assert/strict"; 5 + import { mkdtempSync, writeFileSync } from "node:fs"; 6 + import { createServer } from "node:http"; 7 + import type { AddressInfo } from "node:net"; 8 + import { tmpdir } from "node:os"; 9 + import { join } from "node:path"; 10 + import { test } from "node:test"; 11 + import { Api, ApiError } from "../src/api.ts"; 12 + import { credentialLabel, installKey, readConfig, runKey, tokenFor, writeConfig } from "../src/config.ts"; 14 + const KEY = "abso_sk_runkeyabcdefghijklmnopqrstuvwx"; 15 + const LOCAL = "http://127.0.0.1:8787"; 17 + function keyFile(text: string): string { 18 + const path = join(mkdtempSync(join(tmpdir(), "abso-run-key-")), "key"); 19 + writeFileSync(path, text); 23 + function folder(server = LOCAL) { 24 + const root = mkdtempSync(join(tmpdir(), "abso-run-key-")); 25 + writeConfig(root, { server, project: "p", agent: "run-7-check-test" }); 29 + const NO_SERVERS = { ABSO_SERVERS_FILE: "no-servers.json" }; 31 + test("ABSO_KEY_FILE's key is the credential when no token or folder key is set", () => { 32 + const env = { ...NO_SERVERS, ABSO_KEY_FILE: keyFile(KEY) }; 33 + assert.equal(runKey(env), KEY); 34 + assert.equal(tokenFor(LOCAL, env, folder()), KEY); 35 + assert.deepEqual(credentialLabel(folder(), LOCAL, env), { kind: "pipeline run key", id: null }); 36 + assert.equal(readConfig(folder(), env).token, KEY); 39 + test("a trailing newline in the key file is not part of the key", () => { 40 + assert.equal(runKey({ ABSO_KEY_FILE: keyFile(`${KEY}\n`) }), KEY); 43 + test("ABSO_TOKEN and a folder's own key both come before the run key", () => { 44 + const env = { ...NO_SERVERS, ABSO_KEY_FILE: keyFile(KEY), ABSO_TOKEN: "shared-token-value" }; 45 + assert.equal(tokenFor(LOCAL, env, folder()), "shared-token-value"); 46 + assert.deepEqual(credentialLabel(folder(), LOCAL, env), { kind: "shared token", id: null }); 47 + const root = folder(); 48 + installKey(root, JSON.stringify({ key: "abso_sk_folderkeyabcdefghijklmnopqrstu", id: "k_ab12cd34" })); 50 + tokenFor(LOCAL, { ...NO_SERVERS, ABSO_KEY_FILE: keyFile(KEY) }, root), 51 + "abso_sk_folderkeyabcdefghijklmnopqrstu", 55 + test("the run key goes only where a token may, and the refusal doesn't hold it", () => { 56 + const env = { ...NO_SERVERS, ABSO_KEY_FILE: keyFile(KEY) }; 58 + () => tokenFor("https://someone-else.example", env, folder("https://someone-else.example")), 59 + (err: Error) => /sends your token only to/.test(err.message) && !err.message.includes(KEY), 63 + test("a key file abso can't read, or that holds no key, is named without its contents", () => { 64 + const missing = join(tmpdir(), "abso-no-such-key-file"); 65 + assert.throws(() => runKey({ ABSO_KEY_FILE: missing }), /can't read/); 66 + const wrong = keyFile("not-a-key secret-looking-text"); 68 + () => runKey({ ABSO_KEY_FILE: wrong }), 69 + (err: Error) => /doesn't hold an abso key/.test(err.message) && !err.message.includes("secret-looking-text"), 73 + test("a run key's refusal reaches the job as the server wrote it, and without the key", async () => { 75 + const server = createServer((req, res) => { 76 + sent = req.headers.authorization ?? ""; 77 + res.writeHead(403, { "content-type": "application/json" }); 78 + res.end(JSON.stringify({ error: "a pipeline run's key can't land" })); 80 + await new Promise<void>((ok) => server.listen(0, "127.0.0.1", ok)); 82 + const url = `http://127.0.0.1:${(server.address() as AddressInfo).port}`; 83 + const config = readConfig(folder(url), { ...NO_SERVERS, ABSO_KEY_FILE: keyFile(KEY) }); 84 + await assert.rejects( 85 + new Api(config).land("try"), 87 + err instanceof ApiError && 88 + err.status === 403 && 89 + /a pipeline run's key can't land/.test(err.message) && 90 + !err.message.includes(KEY), 92 + assert.equal(sent, `Bearer ${KEY}`);