Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions apps/desktop/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -591,11 +591,23 @@ Gateway and runs Agents. The daemon exits with the app.
RTX DCH WHQL downloads (allowlisted CDN, Windows Authenticode check, elevated
`-s -noreboot -noeula` install, `PowerGuard` sleep block, and `config.json`
`pendingDriverUpdate` post-reboot resume) with `getInstallState` /
`onInstallState` / `startInstall` / `clearInstallState`; and
`onInstallState` / `startInstall` / `clearInstallState`;
`localServer.owned()` reports whether the window points at this app's own
local installation regardless of startup/resume readiness, so the SPA can hide
CLI daemon download entry points even during hot start or install-time
preload.
preload; and `localGateway`
(`src/main/local-gateway.ts`) resolves this home's Bifrost gateway through
`resolveLocalmodelsBifrostLocation` in `@linger/local-installation` and gives
Settings › Models Advanced local-only metadata (`username`, loopback
`adminUrl`, `hasPassword`, `inferenceAuthDisabled`), explicit-action password
reveal, 60 s auto-clearing clipboard copy (shared with `SetupAccount` via
`src/main/secret-clipboard.ts`), loopback admin console launch, and gateway
folder reveal. The `serverUrl` origin check in `DesktopIpcModule` is the
security boundary — any script running on the configured TeamHub origin can
read the enrolled `computerId` from `computer.status` and invoke
`revealPassword`; the `computerId` check only routes the UI to this desktop's
enrolled computer. Passwords never cross TeamHub APIs and are read fresh from
the private `0600` `admin-password` file in the main process.
- `src/shared/api.ts`, `src/shared/shell.ts`: preload contract types and IPC
channel names.
- `src/main/computer-daemon.ts`: ComputerDaemon. While the computer is
Expand Down
104 changes: 102 additions & 2 deletions apps/desktop/src/main/desktop-ipc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ const fixture = async (
servesWindow?: () => Promise<boolean>;
signInWithAccount?: () => Promise<void>;
} = {},
options: {
computerId?: string;
localGateway?: {
getInfo?: () => Promise<unknown>;
revealPassword?: () => Promise<{ readonly password: string }>;
copyPassword?: () => Promise<{
readonly copied: boolean;
readonly clearAfterMs: number;
}>;
openAdmin?: () => Promise<void>;
openFolder?: () => Promise<void>;
dispose?: () => void;
};
} = {},
) => {
const local = {
...stubModule("LocalServer"),
Expand Down Expand Up @@ -82,6 +96,24 @@ const fixture = async (
})),
clearInstallState: vi.fn(),
};
const gateway = options.localGateway
? {
getInfo: vi.fn(
options.localGateway.getInfo ?? (async () => ({ available: false })),
),
revealPassword: vi.fn(
options.localGateway.revealPassword ??
(async () => ({ password: PASSWORD })),
),
copyPassword: vi.fn(
options.localGateway.copyPassword ??
(async () => ({ copied: true, clearAfterMs: 60_000 })),
),
openAdmin: vi.fn(options.localGateway.openAdmin ?? (async () => {})),
openFolder: vi.fn(options.localGateway.openFolder ?? (async () => {})),
dispose: vi.fn(options.localGateway.dispose ?? (() => {})),
}
: undefined;
const send = vi.fn();
const windows = {
...stubModule("WindowManager"),
Expand All @@ -102,9 +134,16 @@ const fixture = async (
stubModule("WorkspaceGrants"),
updater as never,
local as never,
new DesktopIpcModule({ defaultDisplayName: "Desk", driverUpdater }),
new DesktopIpcModule({
defaultDisplayName: "Desk",
driverUpdater,
...(gateway ? { localGateway: gateway as never } : {}),
}),
],
{ serverUrl: SERVER },
{
serverUrl: SERVER,
...(options.computerId ? { computerId: options.computerId } : {}),
},
bus,
);
await host.start();
Expand All @@ -119,6 +158,7 @@ const fixture = async (
bus,
diagnostics,
driverUpdater,
gateway,
language,
local,
power,
Expand Down Expand Up @@ -429,3 +469,63 @@ describe("DesktopIpcModule driverUpdate", () => {
await f.host.stop("quit");
});
});

describe("DesktopIpcModule local gateway", () => {
it("serves local Bifrost metadata and secret actions only for this desktop's enrolled computer and server origin", async () => {
const f = await fixture(
{},
{
computerId: "computer-this-mac",
localGateway: {
getInfo: async () => ({
available: true,
adminUrl: "http://127.0.0.1:18480",
username: "admin",
hasPassword: true,
inferenceAuthDisabled: true,
}),
},
},
);

expect(
await f.invoke(IPC.localGatewayInfo, SERVER, "computer-this-mac"),
).toEqual({
available: true,
adminUrl: "http://127.0.0.1:18480",
username: "admin",
hasPassword: true,
inferenceAuthDisabled: true,
});
expect(
await f.invoke(IPC.localGatewayInfo, SERVER, "computer-other"),
).toEqual({ available: false });
expect(() =>
f.invoke(IPC.localGatewayRevealPassword, SERVER, "computer-other"),
).toThrow("Not allowed");
expect(() =>
f.invoke(
IPC.localGatewayRevealPassword,
"https://evil.example.com",
"computer-this-mac",
),
).toThrow("Not allowed");

expect(
await f.invoke(
IPC.localGatewayRevealPassword,
SERVER,
"computer-this-mac",
),
).toEqual({ password: PASSWORD });
expect(
await f.invoke(IPC.localGatewayCopyPassword, SERVER, "computer-this-mac"),
).toEqual({ copied: true, clearAfterMs: 60_000 });
await f.invoke(IPC.localGatewayOpenAdmin, SERVER, "computer-this-mac");
await f.invoke(IPC.localGatewayOpenFolder, SERVER, "computer-this-mac");
expect(f.gateway!.openAdmin).toHaveBeenCalledOnce();
expect(f.gateway!.openFolder).toHaveBeenCalledOnce();
await f.host.stop("quit");
expect(f.gateway!.dispose).toHaveBeenCalledOnce();
});
});
43 changes: 43 additions & 0 deletions apps/desktop/src/main/desktop-ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { z } from "zod";
import {
IPC,
type ComputerStatus,
type DesktopLocalGatewayInfo,
type DesktopSettings,
type DesktopUpdateState,
type LocalAccountSignIn,
Expand All @@ -17,6 +18,7 @@ import type { DiagnosticsModule } from "./diagnostics.js";
import type { DriverUpdaterHost } from "./driver-updater.js";
import type { EnrollmentModule } from "./enrollment.js";
import type { LanguageModule } from "./language.js";
import type { LocalGatewayService } from "./local-gateway.js";
import type { LocalServerModule } from "./local-server.js";
import type { Module, ModuleContext } from "./modules.js";
import { sameOrigin } from "./navigation.js";
Expand All @@ -30,6 +32,7 @@ import type { WindowManagerModule } from "./window-manager.js";
import type { WorkspaceGrantsModule } from "./workspace-grants.js";

const grantIdInput = z.string().min(1).max(128);
const computerIdInput = z.string().min(1).max(128);
const languageInput = z.enum(LANGUAGES);
// The server address is not settable from the SPA: a page served by one
// server must not be able to repoint the app. It changes on app://offline.
Expand Down Expand Up @@ -105,16 +108,19 @@ export class DesktopIpcModule implements Module {
// Set on macOS only.
readonly #permissions: DesktopPermissionHost | undefined;
readonly #driverUpdater: DriverUpdaterHost | undefined;
readonly #localGateway: LocalGatewayService | undefined;
readonly #unsubscribe: (() => void)[] = [];

constructor(options: {
defaultDisplayName: string;
permissions?: DesktopPermissionHost;
driverUpdater?: DriverUpdaterHost;
localGateway?: LocalGatewayService;
}) {
this.#defaultDisplayName = options.defaultDisplayName;
this.#permissions = options.permissions;
this.#driverUpdater = options.driverUpdater;
this.#localGateway = options.localGateway;
}

async start(ctx: ModuleContext): Promise<void> {
Expand Down Expand Up @@ -258,6 +264,43 @@ export class DesktopIpcModule implements Module {
handle(IPC.updateInstall, () => updater.install());
handle(IPC.updateCheck, () => updater.check());

const localGateway = this.#localGateway;
// Security boundary is `handle()`'s `serverUrl` origin check; `isOwnComputer`
// is a UI-routing guard so calls only target this desktop's enrolled computer.
const isOwnComputer = (computerId: unknown): boolean => {
const requested = computerIdInput.parse(computerId);
const enrolled = ctx.config.get().computerId;
return Boolean(enrolled && requested === enrolled);
};
const requireOwnGateway = (computerId: unknown): LocalGatewayService => {
if (!localGateway || !isOwnComputer(computerId)) {
throw new Error("Not allowed");
}
return localGateway;
};
handle(
IPC.localGatewayInfo,
async (computerId): Promise<DesktopLocalGatewayInfo> => {
if (!localGateway || !isOwnComputer(computerId)) {
return { available: false };
}
return localGateway.getInfo();
},
);
handle(IPC.localGatewayRevealPassword, (computerId) =>
requireOwnGateway(computerId).revealPassword(),
);
handle(IPC.localGatewayCopyPassword, (computerId) =>
requireOwnGateway(computerId).copyPassword(),
);
handle(IPC.localGatewayOpenAdmin, (computerId) =>
requireOwnGateway(computerId).openAdmin(),
);
handle(IPC.localGatewayOpenFolder, (computerId) =>
requireOwnGateway(computerId).openFolder(),
);
this.#unsubscribe.push(() => localGateway?.dispose());

const permissions = this.#permissions;
if (permissions)
handle(IPC.permissionAct, (step) =>
Expand Down
15 changes: 15 additions & 0 deletions apps/desktop/src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { fileURLToPath } from "node:url";
import {
Notification,
app,
clipboard,
desktopCapturer,
dialog,
powerMonitor,
Expand Down Expand Up @@ -36,6 +37,7 @@ import {
} from "./windows-driver-platform.js";
import { EnrollmentModule } from "./enrollment.js";
import { LanguageModule } from "./language.js";
import { LocalGatewayService } from "./local-gateway.js";
import {
LocalServerModule,
signInWithPassword,
Expand Down Expand Up @@ -395,6 +397,19 @@ async function main(): Promise<void> {
new TrayModule({ quit: () => void quit() }),
new DesktopIpcModule({
defaultDisplayName,
localGateway: new LocalGatewayService({
home: () => home,
clipboard: {
writeText: async (text) => clipboard.writeText(text),
readText: async () => clipboard.readText(),
clear: () => clipboard.clear(),
},
openExternal: (url) =>
process.platform === "linux"
? openWithXdg(url)
: shell.openExternal(url),
showFile: (file) => shell.showItemInFolder(file),
}),
...(desktopPermissions ? { permissions: desktopPermissions } : {}),
driverUpdater,
}),
Expand Down
Loading