Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed
MCP
show on this site's /mcp
CLI
abso show 95 --json
JSON
/christopher/abso-core/versions/95?format=json

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.

of shared·pinch··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 @@
22// them, and the token.
33//
44// 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.
67
78import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
89import { homedir } from "node:os";
@@ -97,12 +98,14 @@
9798 root: string,
9899 server: string,
99100 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 } {
101102 const key = readKeyFile(root);
102103 if (key) {
103104 if (originOf(key.server) !== originOf(server)) return { kind: "none", id: null };
104105 return { kind: "agent key", id: key.id };
105106 }
107+ if (fromEnv(env, "TOKEN")) return { kind: "shared token", id: null };
108+ if (fromEnv(env, "KEY_FILE")) return { kind: "pipeline run key", id: null };
106109 return { kind: readToken(env) ? "shared token" : "none", id: null };
107110}
108111
@@ -184,7 +187,7 @@
184187 return key.key;
185188 }
186189 }
187− const token = readToken(env);
190+ const token = fromEnv(env, "TOKEN")?.trim() || runKey(env) || readToken(env);
188191 const trusted = trustedServers(env);
189192 if (token === undefined || tokenGoesTo(server, trusted)) return token;
190193 throw new UsageError(
@@ -213,6 +216,25 @@
213216 return trustedList(fromEnv(env, "TRUSTED_SERVERS"), readMachineServers(env));
214217}
215218
219+/**
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.
222+ */
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;
226+ let text: string;
227+ try {
228+ text = readFileSync(path, "utf8");
229+ } catch {
230+ throw new UsageError(`ABSO_KEY_FILE names ${path}, which abso can't read`);
231+ }
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`);
235+ return key;
236+}
216238/** ABSO_TOKEN if set, else ~/.abso/token, else ~/.avcs/token, else none. */
217239export function readToken(env: Readonly<Record<string, string | undefined>> = process.env): string | undefined {
218240 const fromVar = fromEnv(env, "TOKEN");
--- a/client/src/doctor.ts
+++ b/client/src/doctor.ts
@@ -83,7 +83,13 @@
8383
8484function credentialWords(root: string, server: string, env: Readonly<Record<string, string | undefined>>): string {
8585 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"
89+ ? "the shared token"
90+ : c.kind === "pipeline run key"
91+ ? "a pipeline run's key"
92+ : "no key";
8793}
8894
8995export async function whoami(
--- a/client/src/join-commands.ts
+++ b/client/src/join-commands.ts
@@ -36,8 +36,8 @@
3636
3737const NAME = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
3838
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");
4141 if (!agent) throw new UsageError("give this folder's agent name with --agent <name>");
4242 if (!NAME.test(agent))
4343 throw new UsageError(`agent names are letters, digits, dot, dash and underscore (got ${JSON.stringify(agent)})`);
@@ -193,7 +193,13 @@
193193 let minted: { key: string; id: string } | undefined;
194194 if (str(args, "agent") !== undefined) {
195195 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");
200+ if (!named)
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);
197203 } else {
198204 // No --agent: the box's name, or the next free -2, -3. Not signed in, --reader reads a public project signed out.
199205 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.
3+
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);
20+ return path;
21+}
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" });
26+ return root;
27+}
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);
37+});
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);
41+});
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" }));
49+ assert.equal(
50+ tokenFor(LOCAL, { ...NO_SERVERS, ABSO_KEY_FILE: keyFile(KEY) }, root),
51+ "abso_sk_folderkeyabcdefghijklmnopqrstu",
52+ );
53+});
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) };
57+ assert.throws(
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),
60+ );
61+});
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");
67+ assert.throws(
68+ () => runKey({ ABSO_KEY_FILE: wrong }),
69+ (err: Error) => /doesn't hold an abso key/.test(err.message) && !err.message.includes("secret-looking-text"),
70+ );
71+});
73+test("a run key's refusal reaches the job as the server wrote it, and without the key", async () => {
74+ let sent = "";
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" }));
79+ });
80+ await new Promise<void>((ok) => server.listen(0, "127.0.0.1", ok));
81+ try {
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"),
86+ (err: Error) =>
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),
91+ );
92+ assert.equal(sent, `Bearer ${KEY}`);
93+ } finally {
94+ server.close();
95+ }
96+});