Files
loki/scripts/hetzner/loki-box-runner@.service
CatoandClaude Fable 5.1 944ed15747 feat(cloud): private builders — an allowlisted agent environment, a runner without the database, one sealed unit per account (#1346)
* 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>
2026-10-20 12:05:27 +02:00

56 lines
2.5 KiB
Desktop File

[Unit]
# One private builder per account (docs/architecture/private-builders.md).
# %i is the tenant's short id — the first eight characters of their user id —
# and the unit runs as the system user lk-%i in /home/lk-%i, with its own
# runner token, its own clones, its own agent sign-ins. Nothing of the app,
# the other tenants or the box's secrets is reachable from inside it.
# Installed by scripts/hetzner/new-tenant.sh and refreshed by the deploy
# (scripts/deploy-hetzner.sh); instances are created by reconcile-tenants.sh
# from users.private_builder.
Description=Loki private builder for tenant %i
After=network-online.target loki-app.service
Wants=network-online.target
StartLimitIntervalSec=0
[Service]
Type=simple
User=lk-%i
Group=lk-%i
WorkingDirectory=/opt/loki/runner
# The tenant's whole world is its home. The runner code is read-only and
# shared; the rest of the filesystem is read-only or invisible.
ProtectSystem=strict
ProtectHome=tmpfs
BindPaths=/home/lk-%i
ReadOnlyPaths=/opt/loki/runner
InaccessiblePaths=-/opt/loki/app -/opt/loki/runner/.env -/etc/loki -/opt/orangecat -/opt/kivvi -/opt/botsmann -/opt/datacat-api -/opt/datacat-web -/opt/petvity -/opt/printcraft -/opt/reparaturbonus-zh -/opt/revamp-info -/opt/evig -/opt/sbb-fundbuero -/opt/solon -/opt/surf-your-life -/opt/vitareba -/opt/aoz-wohnen -/opt/supabase -/opt/backups -/opt/monitoring -/opt/_appcron
PrivateTmp=true
NoNewPrivileges=true
# One tenant cannot take the box down: the CX43 carries roughly six to ten
# concurrent agent sessions in all, and the first symptom of growth must be a
# queue on the System page, never a crash.
MemoryMax=3G
CPUQuota=200%
TasksMax=512
# The tenant's engine keys (Settings → Your engine) and nothing else. No
# database password: the runner asks the control plane for what it needs
# with its own token (src/lib/agent-execution/box-workspace.ts).
EnvironmentFile=-/etc/loki/runners/%i.env
Environment=HOME=/home/lk-%i
Environment=PATH=/home/lk-%i/.local/bin:/home/lk-%i/.npm-global/bin:/usr/local/bin:/usr/bin:/bin
Environment=NODE_ENV=production
Environment=LOKI_BOX_PREPARE=true
Environment=LOKI_AGENT_ENV=allowlist
Environment=LOKI_BOX_DEV_ROOT=/home/lk-%i/dev
Environment=LOKI_RUNNER_PRESENCE_CHANNEL=cloud
Environment=LOKI_WEB_URL=https://loki.orangecat.ch
ExecStart=/opt/loki/runner/node_modules/.bin/tsx scripts/box-runner.ts
Restart=always
RestartSec=5
# One OOM-killed child must not take every agent with it (see the legacy
# unit in install-box-runner.sh for the 2026-09-25 incident).
OOMPolicy=continue
[Install]
WantedBy=multi-user.target