mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 06:37:38 +01:00
* feat(runner): agents get an allowlisted environment; the cloud builder asks Loki what to clone
Track 1, PRs 2 and 3 of docs/architecture/private-builders.md, together.
- src/lib/agent-execution/agent-env.ts: with LOKI_AGENT_ENV=allowlist (set
by the box units) an agent PTY is born with a shell's environment, the
engine keys the unit holds and what its own spec passes — never
DATABASE_URL, never the org GITHUB_TOKEN. Off the box nothing changes.
- GET /api/control/workspace-source?tab=: a runner asks with its own token
and gets its own account's repository and a token that account may write
with (github-org-token.ts). box-workspace.ts reads no database any more;
the runner passes the run's token to the one agent that needs it
(GITHUB_TOKEN/GH_TOKEN in the spec env).
- mint-box-runner-token.ts --user <id>: a token per tenant.
- Records: changelog {#agent-env} {#runner-no-db}; roadmap milestone ticked.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NZqZujmXpupVDC1Hi5Jbsx
* feat(cloud): a private builder per account — the flag, the sealed unit, reconciled on the box
Track 1, PRs 4 and 5 of docs/architecture/private-builders.md.
- users.private_builder (migration 0122) is the one switch, set from
System → Plans (/api/system/private-builder). It grants cloud BUILDING
only: isCloudBuilderAllowed (founder or flag) for routing, Sessions and
the kickoff path; isFleetInfrastructureAllowed is the founder alone and
gates the org GitHub token, studio CD, own domains and the server's own
PTYs. LOKI_CLOUD_BUILDER_USER_IDS is retired.
- scripts/hetzner/loki-box-runner@.service: one unit per tenant as
lk-<short>, ProtectSystem=strict, ProtectHome=tmpfs with its own home
bound, the app and the runner env invisible, MemoryMax/CPUQuota/TasksMax,
its own dev root, the agent env allowlist, no database password.
- scripts/hetzner/new-tenant.sh: user, clean shell, dev root, a runner
token minted for THAT user, the agent contract, claude in its own home,
an env file for its engine keys, the unit. reconcile-tenants.sh runs
every minute from loki-tenants.timer (install-tenant-reconcile.sh, run by
the deploy) and brings units into step with the flag. The deploy ships
the scripts and template and drains and restarts every unit, each in its
own transient unit.
- A tenant's project path is written under its own root
(tenantDevRoot), which counts as box-rooted for routing.
- Records: changelog {#new-tenant} {#private-builder-flag}; roadmap.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NZqZujmXpupVDC1Hi5Jbsx
* chore(runner): Fleet Runner 0.8.50 — the allowlisted environment and the API-backed clone
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NZqZujmXpupVDC1Hi5Jbsx
---------
Co-authored-by: Claude <noreply@anthropic.com>
74 lines
2.7 KiB
TypeScript
74 lines
2.7 KiB
TypeScript
/**
|
|
* An agent on the box gets a shell's environment and its own engine key —
|
|
* never the runner's database password or the org GitHub token. Off the box
|
|
* (no LOKI_AGENT_ENV) nothing changes: the laptop runner keeps inheriting.
|
|
* Run: npx tsx scripts/test/agent-env.ts
|
|
*/
|
|
import assert from "node:assert/strict";
|
|
import { readFileSync } from "node:fs";
|
|
import { agentEnvironment, agentEnvAllowlisted } from "../../src/lib/agent-execution/agent-env";
|
|
|
|
const box = {
|
|
LOKI_AGENT_ENV: "allowlist",
|
|
PATH: "/home/lk-a/.local/bin:/usr/bin",
|
|
HOME: "/home/lk-a",
|
|
USER: "lk-a",
|
|
SHELL: "/bin/bash",
|
|
TERM: "xterm-color",
|
|
LANG: "C.UTF-8",
|
|
LC_ALL: "C.UTF-8",
|
|
DATABASE_URL: "postgres://loki:secret@localhost/loki",
|
|
DATABASE_POOL_URL: "postgres://loki:secret@localhost/loki",
|
|
GITHUB_TOKEN: "ghp_org",
|
|
LOKI_WEB_URL: "https://loki.orangecat.ch",
|
|
LOKI_RUNNER_PRESENCE_CHANNEL: "cloud",
|
|
ANTHROPIC_API_KEY: "sk-ant-tenant",
|
|
EMBEDDINGS_BASE_URL: "http://localhost:11434",
|
|
};
|
|
|
|
assert.equal(agentEnvAllowlisted(box), true);
|
|
const env = agentEnvironment(box, { GH_TOKEN: "ghs_run", GITHUB_TOKEN: "ghs_run" });
|
|
for (const secret of ["DATABASE_URL", "DATABASE_POOL_URL", "LOKI_WEB_URL", "EMBEDDINGS_BASE_URL"])
|
|
assert.equal(env[secret], undefined, `${secret} never reaches an agent`);
|
|
assert.equal(env.GITHUB_TOKEN, "ghs_run", "the run's own repository token, not the org's");
|
|
assert.equal(env.GH_TOKEN, "ghs_run");
|
|
assert.equal(env.ANTHROPIC_API_KEY, "sk-ant-tenant", "the tenant's own engine key travels");
|
|
for (const name of ["PATH", "HOME", "USER", "SHELL", "TERM", "LANG", "LC_ALL"])
|
|
assert.equal(env[name], box[name as keyof typeof box], `${name} is what a shell needs`);
|
|
assert.equal(
|
|
agentEnvironment(
|
|
{
|
|
...box,
|
|
LOKI_AGENT_ENV_EXTRA: "PLAYWRIGHT_BROWSERS_PATH, HTTPS_PROXY",
|
|
PLAYWRIGHT_BROWSERS_PATH: "/opt/pw",
|
|
},
|
|
undefined,
|
|
).PLAYWRIGHT_BROWSERS_PATH,
|
|
"/opt/pw",
|
|
"a box may name extras",
|
|
);
|
|
|
|
// Off the box: today's behaviour, untouched.
|
|
const laptop = {
|
|
PATH: "/usr/bin",
|
|
HOME: "/home/g",
|
|
SSH_AUTH_SOCK: "/tmp/agent",
|
|
DATABASE_URL: "x",
|
|
};
|
|
assert.equal(agentEnvAllowlisted(laptop), false);
|
|
assert.deepEqual(agentEnvironment(laptop, { A: "1" }), { ...laptop, A: "1" });
|
|
|
|
// The box units switch it on; the executor reads it.
|
|
assert.match(
|
|
readFileSync("scripts/hetzner/install-box-runner.sh", "utf8"),
|
|
/^Environment=LOKI_AGENT_ENV=allowlist$/m,
|
|
"the box-runner unit allowlists the agent environment",
|
|
);
|
|
assert.match(
|
|
readFileSync("src/lib/agent-execution/local-pty.ts", "utf8"),
|
|
/env: agentEnvironment\(process\.env, spec\.env\)/,
|
|
"the one place a PTY is born reads it",
|
|
);
|
|
|
|
console.log("✓ agent-env: a shell, the tenant's engine, the run's token — nothing else");
|