Linger is An Open-Source Personal Agent That Runs Fully on Your PC. We aim to break Big Tech’s grip on AI by bringing powerful local AI to everyday computers through efficient model–harness co-design, so everyone can run their own.
fix(local-installation): drop the unshipped key move; restart TeamHub on a new key
claude-opus-5-5-mediumb494c01157db
diff --git a/apps/desktop/AGENTS.md b/apps/desktop/AGENTS.mdindex 41a6113c..69270d2f 100644--- a/apps/desktop/AGENTS.md+++ b/apps/desktop/AGENTS.md@@ -90,10 +90,8 @@ Gateway and runs Agents. The daemon exits with the app.instance's private `local-identity.key`, read by `readLocalIdentity`) overthe nonce and the window's origin. The installer puts the key only inTeamHub's process environment, never in `services.env`, `native.env` or- another service's environment, so no other local service can answer. An- earlier version kept it in `services.env`; the installer moves it out- unchanged, and until then `readLocalIdentity` reads it there, because a- TeamHub that version started still uses it. It asks TeamHub's port rather than the web+ another service's environment, so no other local service can answer. A+ new key restarts TeamHub. It asks TeamHub's port rather than the webport, which a program could take and relay through. "Sign in with thiscomputer's account": `localAccount.signIn()` reads the file in the mainprocess and signs the window's session in with `signInWithPassword`,diff --git a/packages/local-installation/src/account.test.ts b/packages/local-installation/src/account.test.tsindex 3aceebf3..36fea7a1 100644--- a/packages/local-installation/src/account.test.ts+++ b/packages/local-installation/src/account.test.ts@@ -272,20 +272,11 @@ it("reads the server identity from the private instance files", async () => {JSON.stringify({ source: { ports: { teamhub: 4100, web: 3000 } } }),{ mode: 0o600 },);- const services = path.join(f.instance.root, "services.env");- await writeFile(services, "LINGER_SECRET_SEED=x\n", { mode: 0o600 });- // An instance the installer has not upgraded yet has no key.+ // An instance without a key file yet, or with an invalid one, has none.await expect(readLocalIdentity(f.instance)).rejects.toThrow(/identity/);- // A TeamHub an earlier version started still uses the key it kept in- // services.env until the installer moves it.- const legacy = Buffer.alloc(32, 3);- await writeFile(- services,- `TEAMHUB_LOCAL_IDENTITY_KEY=${legacy.toString("base64")}\n`,- { mode: 0o600 },- );- expect((await readLocalIdentity(f.instance)).key).toEqual(legacy);const keyFile = path.join(f.instance.root, "local-identity.key");+ await writeFile(keyFile, "not a key\n", { mode: 0o600 });+ await expect(readLocalIdentity(f.instance)).rejects.toThrow(/identity/);await writeFile(keyFile, `${key.toString("base64")}\n`, { mode: 0o600 });expect(await readLocalIdentity(f.instance)).toEqual({teamhub: "http://127.0.0.1:4100",diff --git a/packages/local-installation/src/account.ts b/packages/local-installation/src/account.tsindex f5151fef..09a51724 100644--- a/packages/local-installation/src/account.ts+++ b/packages/local-installation/src/account.ts@@ -2,7 +2,6 @@ import { windowsPrivatePath } from "./windows-private.js";import { randomBytes } from "node:crypto";import { lstat, readFile } from "node:fs/promises";import path from "node:path";-import { parseEnv } from "node:util";import { readLocalIdentityKey, type Instance } from "./instance.js";import { atomicPrivate, readPrivate } from "./private-files.js";@@ -60,8 +59,6 @@ export async function readLocalLogin(// How the desktop app checks that the server it sends the owner password to// is this instance's TeamHub: TeamHub's own loopback address and the key// only TeamHub's process and this file's owner hold (see TeamHub's /v0/local/identity).-// Until the installer next starts the services, a TeamHub an earlier-// version started still uses the key that version kept in services.env.export interface LocalIdentity {teamhub: string;key: Buffer;@@ -71,16 +68,11 @@ export async function readLocalIdentity(): Promise<LocalIdentity> {const unavailable = () =>new Error("Linger on this computer has no server identity yet.");- const [settings, encoded, services] = await Promise.all([+ const [settings, encoded] = await Promise.all([readPrivate(path.join(instance.root, "instance.json")),readLocalIdentityKey(instance.root),- readPrivate(path.join(instance.root, "services.env")),]);- const key = Buffer.from(- encoded ?? parseEnv(services ?? "").TEAMHUB_LOCAL_IDENTITY_KEY ?? "",- "base64",- );- if (settings === undefined || key.length !== 32) throw unavailable();+ if (settings === undefined || encoded === undefined) throw unavailable();let port: unknown;try {port = (JSON.parse(settings) as Partial<Instance>).source?.ports?.teamhub;@@ -93,6 +85,7 @@ export async function readLocalIdentity((port as number) > 65535)throw unavailable();+ const key = Buffer.from(encoded, "base64");return { teamhub: `http://127.0.0.1:${port as number}`, key };}interface LocalAccount {diff --git a/packages/local-installation/src/instance.test.ts b/packages/local-installation/src/instance.test.tsindex 78b811a1..455775bc 100644--- a/packages/local-installation/src/instance.test.ts+++ b/packages/local-installation/src/instance.test.ts@@ -91,25 +91,6 @@ it("gives every instance its own private identity key outside services.env", asyawait initializeInstance({ name: "one", home: root });expect(await readLocalIdentityKey(one.root)).toBe(first);});-// An earlier version kept the key in services.env; it moves unchanged so the-// app and the TeamHub it already trusts keep matching.-it("moves an identity key from services.env without changing it", async () => {- const root = await home();- const instance = await initializeInstance({ name: "older", home: root });- const file = path.join(instance.root, "services.env");- const others = await readFile(file, "utf8");- const legacy = Buffer.alloc(32, 9).toString("base64");- await rm(path.join(instance.root, "local-identity.key"));- await writeFile(file, `TEAMHUB_LOCAL_IDENTITY_KEY=${legacy}\n${others}`);- await initializeInstance({ name: "older", home: root });- expect(await readLocalIdentityKey(instance.root)).toBe(legacy);- expect(await readFile(file, "utf8")).toBe(others);- // Interrupted after the key file was written: the copy left behind goes.- await writeFile(file, `${others}TEAMHUB_LOCAL_IDENTITY_KEY=${legacy}\n`);- await initializeInstance({ name: "older", home: root });- expect(await readLocalIdentityKey(instance.root)).toBe(legacy);- expect(await readFile(file, "utf8")).toBe(others);-});it("rejects path traversal names and invalid ports", async () => {const root = await home();await expect(diff --git a/packages/local-installation/src/instance.ts b/packages/local-installation/src/instance.tsindex 59946c60..f8f76019 100644--- a/packages/local-installation/src/instance.ts+++ b/packages/local-installation/src/instance.ts@@ -290,26 +290,13 @@ async function writeMissingCredentials(root: string): Promise<void> {`${current}${current && !current.endsWith("\n") ? "\n" : ""}${added.join("")}`,);}-// Writes the identity key once. An earlier version kept it in services.env,-// which the services were started with; it moves from there unchanged, so a-// desktop app and TeamHub already paired by it stay paired.+// Writes the identity key once; an instance keeps it from then on.async function writeLocalIdentityKey(root: string): Promise<void> {- const services = path.join(root, "services.env");- const current = (await readPrivate(services)) ?? "";- const legacy = parseEnv(current).TEAMHUB_LOCAL_IDENTITY_KEY;- if (!(await readLocalIdentityKey(root)))- await atomicPrivate(- localIdentityKeyFile(root),- `${legacy && validIdentityKey(legacy) ? legacy : randomBytes(32).toString("base64")}\n`,- );- if (legacy !== undefined)- await atomicPrivate(- services,- current- .split(/(?<=\n)/)- .filter((line) => !line.startsWith("TEAMHUB_LOCAL_IDENTITY_KEY="))- .join(""),- );+ if (await readLocalIdentityKey(root)) return;+ await atomicPrivate(+ localIdentityKeyFile(root),+ `${randomBytes(32).toString("base64")}\n`,+ );}export async function withInstanceLock<T>(instance: Instance,diff --git a/packages/local-installation/src/native-source-flow.test.ts b/packages/local-installation/src/native-source-flow.test.tsindex 7ed179f8..1612721a 100644--- a/packages/local-installation/src/native-source-flow.test.ts+++ b/packages/local-installation/src/native-source-flow.test.ts@@ -245,6 +245,45 @@ test("only TeamHub's process gets the server identity key", async () => {);expect(events.join("\n")).not.toContain(key);});+test("a new identity key restarts TeamHub alone", async () => {+ const f = await fixture();+ vi.mocked(prepareRuntime).mockResolvedValue({+ code: 0,+ state: "ready",+ message: "ready",+ });+ const install = async () => {+ vi.mocked(startNativeProcess).mockClear();+ await installNativeSource({+ home: f.home,+ repo: f.repo,+ name: "native-rekey",+ setupChoice: "pi",+ externalComputer: true,+ signal: new AbortController().signal,+ onEvent: () => {},+ });+ return Object.fromEntries(+ vi+ .mocked(startNativeProcess)+ .mock.calls.map(([options]) => [options.name, options.settings]),+ );+ };+ const before = await install();+ const file = path.join(+ f.home,+ "instances",+ "native-rekey",+ "local-identity.key",+ );+ const key = Buffer.alloc(32, 5).toString("base64");+ await writeFile(file, `${key}\n`, { mode: 0o600 });+ const after = await install();+ expect(after.teamhub).not.toBe(before.teamhub);+ expect(after.teamhub).not.toContain(key);+ expect(after["node-services"]).toBe(before["node-services"]);+ expect(after.web).toBe(before.web);+});test("an external Computer skips the Go Computer release and enrollment", async () => {const f = await fixture();vi.mocked(prepareRuntime).mockResolvedValue({diff --git a/packages/local-installation/src/native-source.ts b/packages/local-installation/src/native-source.tsindex 5b5ef39e..4b2858b8 100644--- a/packages/local-installation/src/native-source.ts+++ b/packages/local-installation/src/native-source.ts@@ -601,9 +601,16 @@ async function runNativeSource(// The services read user.env, the credentials and the voice tools from// their environment, which their command line does not cover: a// change restarts them.- const settings = JSON.stringify({+ const shared = {env: configured.env,voice: voice ? voice.bin : voiceKeys ? "off" : undefined,+ };+ const settings = JSON.stringify(shared);+ // TeamHub also restarts for a new identity key; the digest keeps the+ // key itself out of the process record.+ const teamhubSettings = JSON.stringify({+ ...shared,+ identity: createHash("sha256").update(identityKey).digest("hex"),});await timed("Protecting the instance data directories", () =>Promise.all(@@ -814,7 +821,7 @@ async function runNativeSource(signal,redactions: secrets,// A changed user.env, port, credential or voice tool restarts it.- settings,+ settings: name === "teamhub" ? teamhubSettings : settings,restartOnConfigurationChange: true,});// Stop the Agent Service only when TeamHub is about to restart for a