Public: anyone can read this; the crew can change it.

Home devices: declare the LAN printer once; an app with a grant prints through the forge #10481

Parked opened this in answer to
Closed without merging

A site admin can now declare a LAN printer, grant it to an app, and the app can print a PDF through the forge. tsc, the gate and the affected test files pass here, including a new test/devices.test.ts that runs against a fake IPP printer.

Notes

stopped parked by the crew deploy 997103c

opened this

A site admin can now declare a LAN printer, grant it to an app, and the app can print a PDF through the forge. tsc, the gate and the affected test files pass here, including a new test/devices.test.ts that runs against a fake IPP printer. Not run: the forge's full check, which runs on this push, and bun scripts/fast.ts, which found the diff too broad to name tests. The only probe and print I ran was against the fake printer, so nothing has been tried against the Brother at 192.168.1.161.

What it does

  • Declare: a site admin declares a device at /settings/devices (Settings → This forge → Devices) or with POST /api/v1/devices {name, kind:"printer", url}.
  • Probe: the forge probes it with IPP Get-Printer-Attributes. The device page shows model, state and supplies on one line, or the problem instead when it can't reach the printer.
  • Grant: POST /api/v1/devices/:name/grants {repo, daily_cap} or the device page. The default cap is 10 jobs a day.
  • Print: POST /api/v1/repos/:owner/:name/print?device=NAME with the PDF as the body and a write-scope token. It is limited to 10 MB and 20 pages, and returns {jobId, state, pages}.
  • Refusals: 403 no_grant, 429 cap, 413 for too big or too many pages, 400 for a non-PDF, 502 when the printer is unreachable or refuses the job.
  • Log: every attempt (printed, failed or refused) is logged with app, pages and outcome, and shown on the device page.
  • LAN reach: a device address must be a private IPv4 literal (10/8, 172.16/12, 192.168/16). Names, loopback, link-local and the forge's cluster ranges are refused. The address is checked again at print time, so the relay only ever contacts a declared device's address. The new tests cover the grant check, the caps, the PDF limits and refused addresses.

What I left out

  • Page counting: it counts /Type /Page objects, so a PDF that hides its pages in compressed object streams is refused as invalid rather than counted.
  • No MCP tool, and the job state comes only from the Print-Job reply. The job is not polled afterwards.
  • Printer only: no other device kinds.
  • Caps use UTC days.

To try it

  1. As a site admin, open /settings/devices and declare ipp://192.168.1.161:631/ipp/print.
  2. Grant it to trevato/morning-paper.
  3. POST a PDF to /api/v1/repos/trevato/morning-paper/print?device=NAME.

Docs are in docs/features/devices.md. Beyond the feature files, I added one entry to test/security-floor-routes.test.ts (the list of routes the seed can't fill). The migration pin was committed as a second commit by the pre-push hook.

Closes #10413

3 earlier comments
commented

A site admin can now declare a LAN printer, grant it to an app, and the app can print a PDF through the forge. tsc, the gate and the affected test files pass here, including a new test/devices.test.ts that runs against a fake IPP printer. Not run: the forge's full check, which runs on this push, and bun scripts/fast.ts, which found the diff too broad to name tests. The only probe and print I ran was against the fake printer, so nothing has been tried against the Brother at 192.168.1.161.

What it does

  • Declare: a site admin declares a device at /settings/devices (Settings → This forge → Devices) or with POST /api/v1/devices {name, kind:"printer", url}.
  • Probe: the forge probes it with IPP Get-Printer-Attributes. The device page shows model, state and supplies on one line, or the problem instead when it can't reach the printer.
  • Grant: POST /api/v1/devices/:name/grants {repo, daily_cap} or the device page. The default cap is 10 jobs a day.
  • Print: POST /api/v1/repos/:owner/:name/print?device=NAME with the PDF as the body and a write-scope token. It is limited to 10 MB and 20 pages, and returns {jobId, state, pages}.
  • Refusals: 403 no_grant, 429 cap, 413 for too big or too many pages, 400 for a non-PDF, 502 when the printer is unreachable or refuses the job.
  • Log: every attempt (printed, failed or refused) is logged with app, pages and outcome, and shown on the device page.
  • LAN reach: a device address must be a private IPv4 literal (10/8, 172.16/12, 192.168/16). Names, loopback, link-local and the forge's cluster ranges are refused. The address is checked again at print time, so the relay only ever contacts a declared device's address. The new tests cover the grant check, the caps, the PDF limits and refused addresses.

What I left out

  • Page counting: it counts /Type /Page objects, so a PDF that hides its pages in compressed object streams is refused as invalid rather than counted.
  • No MCP tool, and the job state comes only from the Print-Job reply. The job is not polled afterwards.
  • Printer only: no other device kinds.
  • Caps use UTC days.

To try it

  1. As a site admin, open /settings/devices and declare ipp://192.168.1.161:631/ipp/print.
  2. Grant it to trevato/morning-paper.
  3. POST a PDF to /api/v1/repos/trevato/morning-paper/print?device=NAME.

Docs are in docs/features/devices.md. Beyond the feature files, I added one entry to test/security-floor-routes.test.ts (the list of routes the seed can't fill). The migration pin was committed as a second commit by the pre-push hook.

commented

I fixed four of the five failing checks and pushed. The fifth, child quota > room for small but not large is refused only for large, I could not reproduce. It passed in my local run, so I changed nothing for it. The forge's re-check on this push will show whether it still fails. The local suites I re-ran (design-audit, unreached, attention, server-timing-sweep, child-quota, devices) pass. gate.ts, tsc --noEmit and design-lint are clean.

  • Server-Timing: /settings/devices and /settings/devices/:name now report render time next to session, as the other settings pages do (src/web/pages/devices.ts).
  • Design audit: docs/design/audit.md now has an entry for /settings/devices.
  • First-view budget: the new "Devices" row in the settings navigation adds one visible word, so I raised the settings word budget from 137 to 138 at both widths in docs/design/attention-budget.json. I kept the nav row so the page is reachable.
  • Unreached list: I removed src/kernel/why_now.ts from scripts/unreached-allow.json. The file was deleted on main in 64e585b98, but the entry stayed, so main fails this test too. It is not from this pull.
commented

The check failure my pull caused is fixed and pushed. The other eight failures don't touch devices or printing, and I haven't fixed them. The forge's rerun on this push will show whether they were environmental.

The fix. The migration adds device_job.detail, which holds a short outcome note for each print job and never a credential. The data browser's audit test failed because the column's name matches its "could hold a secret" pattern and nobody had reviewed it. I added device_job.detail to the reviewed-clear list in test/data-browser.test.ts. That test passes now, and bun x tsc --noEmit is clean.

The other eight failures. These are the two child-forge boot tests, the shell-sandbox policy tests (#560), and the crew-shell member-actor test. I expect they depend on cells and the sandbox, which this clone can't run.

  • Child quota and idle-preview tests: both pass locally, so I treated them as unrelated to this pull.
  • Child-forge boot, shell-sandbox and member-actor tests: I couldn't run these here and haven't traced them.

What changed in the pull.

  • Printer: a LAN printer is declared once as a device.
  • Grants and cap: an app with a grant prints through the forge, under a daily page cap.
  • Job log: every print job is logged.
  • Surfaces: devices have API routes and a settings page.

What I left out. Printer kinds other than printer.

To try it. Open the devices page in settings on the preview at lab--10481. Run bun test test/devices.test.ts for the behaviour.

commented

Parked by the crew: the check stayed red through 2 automatic tries

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs