Skip to content

feat(workspaces): pass cloud-init user_data to kubernetes workspaces - #1777

Merged
edenreich merged 1 commit into
mainfrom
feat/workspace-user-data
Nov 9, 2026
Merged

edenreich merged 1 commit into
mainfrom
feat/workspace-user-data

Conversation

@edenreich

Copy link
Copy Markdown
Contributor

Summary

A computer-use workspace needs software its image does not ship, such as a browser with the opentask extension. Instead of a custom image per client, a kubernetes workspace now takes user_data: a cloud-init user-data script its pod runs as root when it boots, before the daemon starts, the way a cloud VM runs it.

workspaces:
  - name: ubuntu-desktop
    kind: kubernetes
    namespace: agents
    image: ghcr.io/inference-gateway/computer:latest
    user_data: |
      #!/bin/sh
      apt-get update
      apt-get install -y --no-install-recommends gimp

The script never lands in the Orchestrator. It goes into the session's Secret under the key userdata, the key KubeVirt's cloudInitNoCloud volume reads, and the Orchestrator's spec.userData.secretRef points at it. A later VM runtime can boot from the same Secret, and clients do not change.

Changes

  • config/daemon.go:
    • WorkspaceEntry.UserData (user_data).
    • It is kubernetes-only. The existing check is extracted into setsKubernetesOnlyFields().
    • It must start with #!, since #cloud-config is not supported yet.
  • internal/agent/infrastructure/kubernetes/workspace.go:
    • ensureSecret writes the script under userdata. Like an instance's user-data, it is fixed for the session.
    • orchestrator() sets spec.userData.secretRef.
    • requiredOperatorVersion names v0.35.0 when an older operator rejects the Orchestrator.
  • Tests: config validation for the kind and the format, the spec reference with no script in the Orchestrator, and the Secret key.
  • Docs: docs/daemon.md (workspaces) and docs/configuration-reference.md.

Depends on inference-gateway/operator#337, which runs the pod in a user namespace and mounts the script for the image to run. Related: the computer image PR (runs the script) and the browser-extension loopback fix, both in this repo.

task lint passes with 0 issues, and the config and kubernetes workspace tests pass.

A kubernetes workspace takes user_data, a cloud-init user-data script its
pod runs as root when it boots, before the daemon starts - for example to
install a browser on the computer image. It must start with #!, as
cloud-config is not supported yet.

The script lands in the session's Secret under the key userdata, never in
the Orchestrator, and spec.userData.secretRef points the operator at it. The
key is the one KubeVirt's cloudInitNoCloud volume reads, so a VM runtime can
take the same Secret. A workspace with user_data names operator v0.35.0 when
an older operator rejects the Orchestrator.
@github-project-automation github-project-automation Bot moved this to Todo in 2026 Nov 9, 2026
@edenreich
edenreich marked this pull request as ready for review November 9, 2026 17:04
@edenreich
edenreich requested a review from a team as a code owner November 9, 2026 17:04
@edenreich
edenreich merged commit bebc06d into main Nov 9, 2026
1 check passed
@edenreich
edenreich deleted the feat/workspace-user-data branch November 9, 2026 17:11
edenreich added a commit that referenced this pull request Nov 9, 2026
…rkspaces (#1778)

## Summary

The desktop app built its own computer-use image locally: Ubuntu, Xvfb,
openbox and Firefox, and nothing else. When an agent closed the browser,
the screen went black. Only the bare X root window was left, with
nothing to click. The image pins and runs `infer` and depends on cli
contracts (X11 capture, the daemon binding, the browser relay), so the
cli now owns and publishes it.

`ghcr.io/inference-gateway/computer`, released with the CLI under the
same tags, is a minimal Ubuntu 26.04 desktop:
- `infer daemon` runs on an Xvfb display (`:99`, 1280x800) with openbox
and a wallpaper.
- A tint2 taskbar has launchers for the installed apps, the open windows
and a clock.
- Normal windows open maximized above the taskbar.

It ships no browser. Clients install what they need with cloud-init
`user_data`. The entrypoint is the container's stand-in for cloud-init:
started as root, it runs the script from the NoCloud seed path, then
drops to `infer` and starts the desktop. The pattern is the same as
linuxserver.io's `/custom-cont-init.d` and cloud-init on a VM.

## Changes

- `computer/Dockerfile`:
- Base is `ubuntu:26.04` with xvfb, openbox, `python3-xdg` (openbox's
XDG autostart), tint2, xterm, fonts, the Adwaita icons, git and curl.
- The `ubuntu` user is replaced with `infer` (uid 1000), and `USER
infer` is set.
  - openbox maximizes normal windows.
- `computer/entrypoint.sh`:
- As root, it runs `/var/lib/cloud/seed/nocloud/user-data`. It must
start with `#!`. Output is teed to `/var/log/cloud-init-output.log`.
- It then runs `HOME=/home/infer setpriv --reuid=infer --regid=infer
--init-groups` back into itself.
- As `infer`, it starts Xvfb, `xsetroot`, `openbox-session` (which runs
XDG autostart) and tint2, then `exec infer "$@"`.
- tint2 17.0.1 aborts (`buffer overflow detected`) with
`launcher_apps_dir`. The entrypoint writes `launcher_item_app` lines for
the apps in `/usr/share/applications` instead, after user-data has run,
so apps the script installs show up.
- `computer/tint2rc`: the taskbar.
- `Taskfile.yml`: `container:build:computer` and
`container:push:computer` (amd64 and arm64).
`.github/workflows/release.yml` pushes both images.
- `docs/computer-use.md`: a "The computer image" section with a
`user_data` example.

Verified locally (arm64):
- **As root with a seed script:** the script ran and `infer daemon`
became PID 1 as `infer`. Xvfb, openbox and tint2 also run as `infer`.
- **With the desktop app's default script** (Firefox ESR plus opentask):
Firefox autostarted maximized, the extension connected to the daemon,
and the taskbar showed XTerm and Firefox launchers.
- **As uid 1000 with no seed:** it boots straight to the desktop.

The image is 1.07GB. Most of it is Mesa/LLVM (Xvfb's GL stack) and GTK3
(tint2), which a browser needs anyway.

Related:
- `user_data` for workspaces: #1777
- Operator delivery: inference-gateway/operator#337
edenreich added a commit that referenced this pull request Nov 9, 2026
… needs client certs (#1779)

## Summary

A computer-use workspace pod now runs Firefox with the opentask
extension, so its agent can use the cheaper `browser_*` tools. The
extension dials the daemon at plain `ws://127.0.0.1:<port>/ws` and
authenticates with a token in its `browser_hello`. In a Kubernetes pod,
though, the operator serves the daemon's AG-UI binding as
`0.0.0.0:52789` with mutual TLS. That binding was the only listener, so
the extension could never connect.

When the extension backend is on and the binding requires client
certificates, the daemon now also listens on plain
`127.0.0.1:<browser_use.extension.port>` for the extension. That
listener uses the extension token, the same handshake, origin check and
handler, and none of the binding's HTTP routes, so the terminal, screen,
artifacts and peer A2A endpoint stay behind mTLS. Every other
configuration keeps its single listener.

## Changes

- `config/daemon.go`: `(*Config).ExtensionLoopback()` is a pure config
rule. It answers whether the loopback listener is needed and what it
serves, and it fails boot clearly in two cases:
- the extension port equals the binding port, including an unset
`daemon.binding.port` that falls back to it
  - the extension token is empty

  `servesMutualTLS()` is TLS on with client certificates required.
- `config/browser_use.go`: an `extensionBackend()` helper.
- `cmd/daemon/daemon.go`:
- `startExtensionLoopback` starts the listener after the main binding,
closes the main binding if the loopback fails, and closes the loopback
on stop.
  - `startThreads` builds the handler once.
- `config/daemon_test.go`: a table test covering when the listener is
needed, the port fallback, and both errors.
- `tests/e2e/daemon_test.go`: with a binding that requires client certs:
  - a TLS dial without a certificate is refused
- a `chrome-extension://` WebSocket on the loopback port gets
`browser_hello_ack`
  - `/terminal/` on the loopback port answers 404

  This test fails against the daemon without this change.
- `docs/daemon.md`: one paragraph in "The binding".

Verified:
- `task lint` reports 0 issues, and the `config`, `cmd`, `agui` and
`browser` tests pass.
- `task test:e2e` passes.
- With the computer image and Firefox ESR plus opentask configured by
policy, the extension attaches on its own (`browser extension
attached`).

Related:
- Computer image: #1778
- `user_data`: #1777
- Operator: inference-gateway/operator#337
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.251.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@inference-gateway-releaser inference-gateway-releaser Bot added the released Shipped in a release label Nov 9, 2026
@edenreich edenreich moved this from Todo to Done in 2026 Nov 9, 2026
edenreich added a commit that referenced this pull request Nov 9, 2026
## Summary

A kubernetes workspace's `user_data` reached the pod with every shell
variable blanked. The daemon ran `os.ExpandEnv` over the whole
`daemon.yaml` text before parsing it, so `"$OPENTASK_DIR"` in the script
became `""` and the desktop's default user data failed at boot with
`install: '': chmod failed`, putting the computer in a restart loop.
There was no way to escape it either, as `os.ExpandEnv` turns `$$X` into
`X`.

Sidecar files now expand `${VAR}` references after parsing, value by
value, and skip `user_data`, whose `$VARS` belong to the shell that runs
it.

## Changes

- `cmd/runtime/config.go`: `readYAMLMap` parses into a `yaml.Node` and
`expandEnvValues` expands every scalar except a `user_data` value. An
unquoted scalar takes the type of its expanded value, so `port: ${PORT}`
is still a number, also through the fixups that re-marshal their file.
An expanded value can no longer add YAML structure. An empty file still
reads as nil.
- `cmd/runtime/isolation_test.go`:
`TestWorkspaceUserDataKeepsItsShellVariables` (fails before this change)
and `TestExpandedUnquotedValueKeepsItsType`.
- `docs/daemon.md`: `user_data` is the one value whose `$VAR` references
are never expanded.

Follow-up to #1777.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Shipped in a release

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant