Skip to content

Run LibreOffice inside the jail through a socket shim - #18

Merged
TomasPalsson merged 8 commits into
apro-deployfrom
flow/soffice-socket-shim
Dec 2, 2026
Merged

TomasPalsson merged 8 commits into
apro-deployfrom
flow/soffice-socket-shim

Conversation

@TomasPalsson

Copy link
Copy Markdown

Why

The upstream sync of 12 Nov denies socket() and socketpair() in the jail. LibreOffice needs both to start (oosplash forks soffice.bin over a socketpair, and soffice.bin opens an AF_UNIX single-instance pipe), so every conversion fails with ERROR 4 forking process.

What

  • docker/lo-socket-shim.c: a preload library that answers socketpair(AF_UNIX) and socket(AF_UNIX) with pipes. Every call on a descriptor it did not create goes to the real libc symbol. It also tracks descriptors through close, close_range, dup2 and dup3.
  • api/Dockerfile: builds the shim in the gcc stage and diverts program/oosplash to a two-line launcher that preloads it. Every entry (soffice, libreoffice, loffice, program/soffice) goes through oosplash, and no other job sees the shim.
  • The seccomp policy is unchanged: scripts/apro-policy-unchanged.sh proves the rendered policy is byte-identical to upstream 4b41f3a, and that nsjail.ts and sandbox.cfg are unchanged.
  • tests/soffice_in_jail_image.ts: runs real conversions through the production guest image inside the real jail, at production limits. It includes a control that must fail with ERROR 4 without the shim, checks that job code still gets EPERM for sockets, and checks that a job loading the shim itself gains nothing.
  • .github/workflows/apro-soffice.yml: runs the test on amd64 and arm64, and the policy check, on pull requests and on pushes to sync/**. It is kept apart from upstream's ci.yml, so syncs never conflict with it.
  • docs/apro-libreoffice-in-jail.md: why the shim exists, and what breaks it.

Test

docker build --target sandbox-build -t soffice-jail-test -f api/Dockerfile .
docker run --rm --privileged --network none --mount type=bind,source=$PWD,target=/work,readonly --entrypoint bun soffice-jail-test /work/tests/soffice_in_jail_image.ts
bash scripts/apro-policy-unchanged.sh 4b41f3a 369337fa1

Ticket: GENAI-2291

…p production limits in the LibreOffice jail test

A listener's write end closed outside the shim no longer causes a later
close of the listener to close a reused descriptor. Non-blocking accept on
a fake listener returns EAGAIN. The oosplash launcher is diverted with
dpkg-divert, the shim build has its own RUN line, and the policy script
requires bun 1.4.4 instead of stubbing perf_hooks.

Ticket: GENAI-2291
…the in-jail shim test

A listener's write end replaced through dup3 must stay open when the listener closes, a failing dup3 must leave the listener fake, and close_range with CLOSE_RANGE_CLOEXEC must neither close nor forget descriptors.

Ticket: GENAI-2291
…ument the policy check

The policy check now runs bun ci in each checkout, so a new package
release cannot change or break the render. The test comment says which
limits are raised and why. The fork note covers the policy check and
how to move its refs after a sync.

Ticket: GENAI-2291
@TomasPalsson
TomasPalsson merged commit 02f03a8 into apro-deploy Dec 2, 2026
39 of 41 checks passed
@TomasPalsson
TomasPalsson deleted the flow/soffice-socket-shim branch December 2, 2026 11:02
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