Skip to content

The document extractor ships as its own image, beside the server in compose and Helm - #194

Merged
zlareb1 merged 37 commits into
mainfrom
feat/extractor-image
Nov 3, 2026
Merged

zlareb1 merged 37 commits into
mainfrom
feat/extractor-image

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Related: #157

Changelog category (leave one):

  • New Feature

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

The document extractor service ships as its own image, ghcr.io/clickhouse/loom-extractor, and runs beside the server: as the extractor service of the Compose stack (on by default, with a token the installer generates) and as extractor.enabled in the Helm chart, in both cases holding no credential but its token. Each extraction now runs under a seccomp filter under which it can make no socket, so an extraction a hostile file takes over reaches nothing, the Loom server on the same network included, while extractions run one at a time (the default).

Why

The server sends originals to a separate extractor service and parses none itself (docs/architecture/document-extraction.md); the service and its wire contract landed in the previous step of the related issue, but nothing built, released or ran it. This adds the image and runs it where Loom runs, with the isolation the design asks for: least privilege, bounded resources, and no way out, so a parser taken over by a hostile file holds nothing worth taking and can send it nowhere.

Scope and risk

  • Image (extractor/Dockerfile, built from the repository root): the package and its dependencies from a new extractor/uv.lock (uv sync --locked, hashes checked) into /opt/venv, owned by root; the service runs as uid 10001, which owns nothing in the image, so no file on a child's sys.path is writable to the child. No package beyond the base image's; the same pinned python:3.12-slim digest as the server's image. Listens on 8790; /healthz healthcheck. The lock holds the root lock's versions of every package both name (a test pins this), so the image runs what the unit tests ran.
  • Socket filter (extractor/loom_extractor/child.py, no_sockets): an internal Compose network has no route out but lets its members reach each other, and loom listens on 7777 there (unauthenticated in a default single-user install). So each child, after no-new-privileges and before it reads the source, installs a seccomp filter (no privilege needed) that makes socket, socketpair and io_uring_setup fail with EPERM, and so do ptrace, process_vm_readv/process_vm_writev and pidfd_getfd, the direct ways into another process. A concurrent sibling (only with LOOM_EXTRACTOR_CONCURRENCY above 1; the default is 1) stays writable through /proc/<pid>/mem until it makes itself non-dumpable, so a taken-over child could still patch one before it filters itself; the docs say so, as they already said such a child could read a sibling's source then. Installing the filter before exec would close that window and needs an exec wrapper (the service is threaded, so not preexec_fn); it is left for a follow-up. On x86_64 the x32 syscall range is refused too, and a process of another architecture is killed by the filter. The service refuses to start, and a child to extract, on an architecture with no filter (x86_64 and aarch64 are the image's). This holds wherever the service runs, Helm and a bare install included; the service's own process (which runs no parser) is not filtered.
  • Compose (compose.yaml): an extractor service at LOOM_VERSION (LOOM_EXTRACTOR_IMAGE_REPOSITORY names another image; it is in NON_SETTINGS_ENV, so the server does not warn about it), on a network of its own that is internal: true (no route out) and that only loom shares; no published port, no env_file (it gets one variable, its token), read_only, cap_drop: [ALL], no-new-privileges, and a memory, CPU and process bound. The server gets LOOM_DOCUMENT_EXTRACTOR_URL from .env and LOOM_DOCUMENT_EXTRACTOR_TOKEN through the same interpolation as the extractor's, so a shell export cannot split them. make dev builds it from the checkout. The stacks that bring their own ClickHouse (dev/docker-compose.cloud.yml, dev/docker-compose.replicas.yml, the blue/green colours) are left as they are and say in the deployment guide to point the two settings at an extractor the operator runs; until then the server reports every format unavailable (it fails closed).
  • Installer and bootstrap: deploy/standalone/env.example carries the URL and a token placeholder; install.sh writes a fresh 48-hex-character token per install and adds a token, and the URL unless one is there, to an .env from before this change (a rerun keeps an existing token); LOOM_EXTRACTOR_IMAGE_REPOSITORY is one of the settings the installer keeps. loom up / make bootstrap write a token into a new .env from .env.example, and add one to an existing .env that has none (or an empty one), once.
  • Helm (extractor.enabled, off by default): a Deployment (2 replicas, one extraction each), a Service and a NetworkPolicy, rendered whatever networkPolicy.enabled says, that admits the release's Loom pods on 8790 and allows no egress. The pods read one key of the release Secret (LOOM_DOCUMENT_EXTRACTOR_TOKEN, from secrets.extractorToken or secrets.existingSecret), mount no service-account token, disable service links, and run as uid 10001 with a read-only root filesystem, every capability dropped and the RuntimeDefault seccomp profile. Their pod template carries checksum/secret (loom.secretChecksum, which now hashes the token too), so a new secrets.extractorToken restarts the Loom and the extractor pods together. They carry a name label of their own: with the chart's shared selector labels, the web pods' NetworkPolicy (which allows egress to 443 anywhere) and the web Service would select them too. With networkPolicy.enabled, the Loom pods' policy allows egress to them. The Loom pods get LOOM_DOCUMENT_EXTRACTOR_URL unless env or extraEnv sets one. The chart refuses an enabled extractor without a token, a token under 16 characters, the token in secrets.extra, env, extraEnv or settingsFile (any of those would reach the Loom pods alone, and every format would read as unavailable; LOOM_DOCUMENT_EXTRACTOR_TOKENS_JSON stays open for an operator's own routed services), and extractor.env setting the token, host or port.
  • Release: the docker job becomes a two-entry matrix (the server's image, with its build cache scope unchanged, and the extractor's), so each builds amd64 and arm64 (the extractor's image with its own OCI title and description; the server's keeps the repository's) with provenance and an SBOM, pushes by digest and fails on a critical fixed CVE (Trivy, both architectures); a docker-tag job then tags both images X.Y.Z, X.Y and latest, and tags neither until both have scanned (a failure in that job can leave one tagged; re-running it tags both, from the scans' artifacts, which also name each image and its pin); the released-quickstart smoke and the GitHub Release wait for docker-tag. A package GitHub creates on its first push is private, so the release process now says to make loom-extractor public once (an install pulls it without signing in; until then the released quickstart fails to pull it).
  • Smoke: docker-smoke.yml builds the extractor image beside the server's and runs on changes under extractor/ and to compose.yaml (no CI job runs the dev overlay; test_compose_extractor_service.py checks its extractor entries). docker_quickstart_smoke.py takes --extractor-image (tagged as --image, since compose runs both at LOOM_VERSION) and, in the installed stack, runs scripts/gates/docker_extractor_smoke.py inside the loom container (the server's own client reaches the service at its configured URL with its token, lists the five formats and reads a TOML extraction back through the contract's checks) and, inside the extractor container, checks that a plain connection out fails with ENETUNREACH or EHOSTUNREACH (or times out), and that one made under the child's filter to loom:7777 fails with EPERM. scripts/gates/helm_extractor_isolation.py renders the chart (both overlays, the workers and network policies on) and checks that no Service, NetworkPolicy, PDB or Deployment of Loom's selects the extractor's pods, that their policy admits only Loom's pods and has no egress rule, that they read the one Secret key and no envFrom, that a new token changes every Deployment's pod template (on the kind overlay; the EKS overlay's Secret is the operator's), and that the Loom pods get http://loom-extractor:8790 by default and an env or extraEnv URL instead; the CI Helm job runs it.

Nothing calls the client yet; ingestion (the next step) does. Server code changes: the bootstrap's token, loom up recreating the extractor with loom on a running stack, and one NON_SETTINGS_ENV entry; extractor code: the socket filter.

Compatibility, rollout and rollback

  • Wire, schema, settings: none (the two settings exist; LOOM_EXTRACTOR_IMAGE_REPOSITORY is a compose variable).
  • Operator steps: a Compose install picks the service up by rerunning the installer (it adds the token and URL to .env); a docker compose up on an .env without the token starts the server as before, and the extractor container (restart: unless-stopped) restarts in a loop, logging each time that it needs LOOM_EXTRACTOR_TOKEN. make dev, make dev-cloud and loom up run the bootstrap first, which adds a token to a clone's older .env; loom up on a stack already running recreates the extractor with loom (never ClickHouse), so a stack started before this change gains it. Helm: nothing until extractor.enabled: true with secrets.extractorToken. Each side holds one token, so changing secrets.extractorToken interrupts extraction until the Loom Deployments (web, and workers when enabled) and the extractor's finish rolling (the Kubernetes guide says so); accepting a previous token, as LOOM_JWT_SECRET_PREVIOUS does, is a follow-up. env or extraEnv naming LOOM_DOCUMENT_EXTRACTOR_URL keeps the chart from setting it (the URL is a secret setting, so the settings file cannot hold it).
  • Rolling upgrade: the extractor holds no state; builds N-1 and N of the server read the same two settings.
  • Rollback: a revert removes the service, the chart objects and the release job; an .env keeps the two lines, which the server reads harmlessly.

Tests

  • The socket filter in a container on an internal network beside a listening server: an unfiltered process connected (the reach the filter closes); under the filter, EPERM; to 1.1.1.1:443, ENETUNREACH. Under the filter, pipes, file reads and importing sqlglot work.
  • docker build -f extractor/Dockerfile ., then the image run with --read-only --cap-drop ALL --security-opt no-new-privileges: healthy; /v1/capabilities lists the five formats; TOML and SQL extracted; inside it, uid 10001, CapPrm 0, the root filesystem read-only and the package owned by root. 221 MB.
  • scripts/gates/docker_quickstart_smoke.py with images built from this branch: the installed stack came up with the extractor healthy, extractor: reached, declared five formats, extraction checked, the extractor's connection out failed (Network is unreachable), and every compiler-indexing check passed; the run then stopped at the dashboard provider step for want of the browser-test dependencies on this machine (ERR_MODULE_NOT_FOUND), which the CI job installs first. The script removed its stack.
  • Helm: helm lint --strict and helm template | kubeconform -strict on both overlays with every optional object on, the extractor included (EKS overlay 24 objects, kind 30), and each refusal above checked; the CI job runs both.
  • Unit: new tests/unit/test_compose_extractor_service.py (the service holds only its token, has no env_file, port or volume, is on the internal network only loom shares, runs read-only with no capabilities and bounded; the dev stack builds it and points the server at it); test_install_script.py (a new install's URL and 48-character token, no placeholder left; an upgrade from before the service gets both, a rerun keeps the token, an upgrade keeps an operator's own LOOM_DOCUMENT_EXTRACTOR_URL); test_cli_up.py (the bootstrap's token, an older .env given one once, and loom up on a running stack recreating the extractor with loom); test_stack_bundle.py (the bundle's compose names the extractor image, the template the token placeholder); test_distribution_licenses.py (the image carries the licence files); test_docker_quickstart_smoke.py (an extractor image of another tag refused; both workflows build or pull it and pass it; the release's docker-tag step, run against two scans' artifacts and a stub docker, tags both and prints both pins, and with one scan missing tags neither); test_extractor_service.py (a child can make no IPv4, IPv6 or Unix socket nor a socket pair, and io_uring_setup, ptrace, process_vm_readv, process_vm_writev, pidfd_getfd and, on x86_64, an x32-numbered call get EPERM, each of those syscall probes, the x32 one included, against an unfiltered baseline so a host that refuses one itself does not pass the test; the test fails with pidfd_getfd removed from the filter; another architecture refuses to extract; the image's lock and the root lock agree on every shared package); test_compose_extractor_service.py runs the Helm isolation check where helm is installed, runs the quickstart's extractor probe against the reference service in process, and checks that loom and the extractor read the token from one interpolation; test_stock_env_matches_docs.py lists LOOM_EXTRACTOR_IMAGE_REPOSITORY among the quickstart's non-settings. The isolation check was confirmed to fail when the extractor's pods carry the shared selector labels (the web NetworkPolicy then selects them).
  • make format-check, make lint, the mypy gate: pass. pytest tests/unit: CI's pytest unit + coverage passed on the branch before its last rebase (the local full run was stopped by the host for memory); the CLI snapshot, extractor, compose, bootstrap, installer, quickstart, env-docs, doc-link and chunking tests pass on the rebased head (513). CI's Quickstart (amd64 and arm64), N-1/N, sandbox and frontend jobs passed; its integration job's two failures (tests/integration/same_key/test_retirement_ch.py, a cap keyword) were on main too and are fixed there by The same-key retirement tests' conflict-check double accepts the keyword the bulk write passes #227, which this branch now includes.
  • The last commit formats one table in docs/features/knowledge.md, which main's format check fails on after knowledge.search's lexical leg scores each chunk's title and section path with its text #206; it is not part of this change otherwise.

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated (an agent wrote most of the diff): Claude Code.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • make format-check, make lint, make typecheck and make test-unit pass; the integration suite passes if server behaviour changed.
  • Generated files are regenerated in this PR, not by hand: the SDK op tables, docs/reference/configuration.md and the docs/reference/ tables (python scripts/codegen/docs_reference.py), the reach manifest, schemas/schema.sql (make schema-dump) and the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py).
  • Docs under docs/ describe the system as it now is, and this description names any operator steps and wire changes.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers; the history goes in this description (tests/unit/test_public_copy.py).
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.

🤖 Generated with Claude Code

@zlareb1
zlareb1 force-pushed the feat/extractor-image branch 2 times, most recently from d711b91 to f4534a2 Compare November 3, 2026 15:27
zlareb1 and others added 28 commits November 3, 2026 16:48
…ompose and Helm

Related: #157

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…tstrap and release job follow review

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…from distances, and keep docs in step

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…he io_uring probe to a host that allows it

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…er-service token map stays open in the chart

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…o gets the token

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…t the installer keeps both images

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… the environment reference name what it keeps

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ibed, label the extractor image as its own, and list its gates

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…cs and dev-setup skill name the extractor where they list the stack

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…upgrades page and threat model describe the stack

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…gers, skill row and reflowed docs say what is checked

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…writable through /proc

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ndition, and loom up's help names the extractor

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…st probes every call the filter refuses

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…tor image setting among the quickstart's non-settings

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… socket test probes process_vm_writev

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…, and the stack's test file is formatted

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…server's token line follows its ClickHouse block

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… change interrupts extraction while both sides roll

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…maries name the one-at-a-time condition

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… an operator's own wins

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ler keeps an operator's URL and the README pins the image

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…the token note counts every Loom Deployment

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
zlareb1 and others added 9 commits November 3, 2026 16:49
…s both, and the release doc covers both images

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ents and a help-text wrap

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…e gets a host baseline, and the bootstrap fills its token in one pass

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…es, and say what the socket filter covers

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…rmat check fails on

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 force-pushed the feat/extractor-image branch from af7e462 to 5d3be76 Compare November 3, 2026 16:51
@zlareb1
zlareb1 merged commit 41c59e9 into main Nov 3, 2026
22 checks passed
@zlareb1
zlareb1 deleted the feat/extractor-image branch November 3, 2026 16:52
@pufit pufit mentioned this pull request Nov 4, 2026
9 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant