Skip to content

Latest commit

 

History

History
290 lines (223 loc) · 12.2 KB

Programmer's Worksheet Container.md

File metadata and controls

290 lines (223 loc) · 12.2 KB

pwsc — System Report

A deposit → publish → update system with data containers that carry absolute paths. Companion to Programmer's Worksheet, and a separate entity from it.

Python 3.10+ · zero dependencies · 19 modules · 6,429 lines · 245 functions · 27 CLI commands · 125 tests, all passing


1. What this is

One cycle, end to end:

flowchart LR
    W["Programmer's<br/>Worksheet"] -->|submission| I[Intake]
    I --> V[Vault]
    V --> R[Release<br/>container]
    R --> S[Server]
    S -->|check → download| C[Client]
    C --> X["verify → back up<br/>→ apply → record"]
Loading

A developer selects, from the worksheet, the files that changed and sends them. The system stores them, builds a signed release, and publishes it on a channel. A client machine asks "is there an update?", downloads it, verifies it, and installs it at the required path — with rollback if anything fails. Whatever nobody selected stays exactly as it is on the client.


2. Modules

Module Lines Responsibility
format.py 348 The .pwsc container: manifest, entries, writing, reading, verification
ingest.py 222 Packing from absolute paths, excludes, secret detection
restore.py 292 Three restore modes, the plan, execution, the refusals
seal.py 60 Ed25519 signing and verification
_ed25519.py 138 Pure-Python implementation, carried over from the worksheet
release.py 201 Releases, channels, version comparison, the update decision, the publish index
deposit.py 372 Publisher side: selection, base computation, full and partial releases
update.py 444 Client side: install, backup, rollback, state, drift detection
intake.py 197 The receiving boundary: envelope, validation, refusal by name
vault.py 270 File management: index, objects, log, history, staging
control.py 330 The command interface the worksheet drives, and its allowlist
server.py 323 Optional server: storage, publication, update decisions, health
client.py 138 Push, pull, publish, check — with local verification after every download
net.py 197 Reachability, LAN announcement and discovery
errors.py 154 27 error codes, 7 warnings
adapters/worksheet.py 323 The only module that knows the worksheet's schema
cli.py 804 27 commands

3. The container format

container.json          the manifest — the only place a user path appears
blobs/ab/cdef…          content, addressed by sha256
SEAL.json               optional Ed25519 seal over the manifest digest

The governing rule: recording is not writing. Restoring an absolute path verbatim is the Zip Slip vulnerability class by definition. So:

  • No archive member is ever named after a user path. Member names are blobs/<2 hex>/<62 hex> — fixed length, fixed alphabet, no separator the sender chose. The absolute path lives inside container.json as data. Unzipping the archive with any tool cannot write outside the blob store.
  • Exactly one step writes to a real path (restore), and it plans first: an inspectable plan is printed and nothing touches disk until --apply.

Content addressing means an identical file is stored once however many absolute paths point at it.

Restore modes

Mode Behaviour
rooted (default) Rebuilds the full path shape under a root you choose
mapped Prefix rules the receiver chooses; an entry no rule matches is refused, never guessed
literal The recorded absolute path — behind two gates, refused for protected system locations (C13) and for a path grammar the host does not use (C14)

4. The receiving boundary

The single envelope shared between sender and receiver:

{ "envelope": "pwsc-submission/1",
  "producer": "programmers-worksheet/4",
  "root": "/home/dev/ws",
  "items": [ {"path": "cells/g01/f01.py", "content_b64": "…", "coord": "G01/F01"} ],
  "removals": [], "meta": {} }
  • Logical paths, not filesystem paths. The sender's root travels in one field for provenance and is never composed into a local path — files are staged locally and the container is built from those.
  • Validation is refusal, not repair. .., an absolute path, a drive letter, a backslash or a control character is rejected with the item named (C25). Silently normalising would mean the receiver deciding what the sender meant.
  • Unknown fields are ignored, not refused — a producer that grows a field must not break a receiver that has not learned it.
  • Provenance cannot overwrite release fields. A sender cannot set kind or base, or it could turn a partial release into a full one and delete a customer's files.

The worksheet's schema is known to exactly one file, adapters/worksheet.py. When the worksheet changes, one file is wrong and the core keeps working.


5. The vault

<vault>/index.json          logical path -> current record
<vault>/objects/ab/cdef…    content, addressed by sha256
<vault>/log.jsonl           one line per accepted submission, append-only
  • An edit adds one object; the previous one is already there and stays → history for free.
  • Nothing is deleted from objects/ when a path is removed. History that vanishes when the current state changes is not history.
  • The index answers "what is here now" in one read; the log answers "how did it get here" without rewriting a byte already written.
  • A file arriving byte-identical counts as unchanged and does not bump its revision — recording an edit that did not happen makes the log lie.
pwsc vault ls | cat <path> | rm <path> | mv <path> --to <new> | history <path> | log

6. Full and partial releases

Kind What a missing path means
full removed — the release is the whole product
partial unchanged — the release is a selection, and what is not in it is not touched

The kind is declared inside the sealed manifest and never inferred. A partial release read as full would delete everything the publisher chose not to ship, so removals in a partial release are explicit (--remove).

Two independent selections. The publisher chooses what to ship (--cell G01/F01, --route main, --changed-since); the recipient chooses what to accept (--only, --skip). Both mean the same thing: a file nobody chose is left exactly as it is.

The base is computed before selection, never after — otherwise a one-file release would land app.py at the install root instead of in bin/.

The state records a selection honestly: "1.1.0 partial", naming what was skipped, with the placing version kept per file.


7. Installing on a client

Four steps, none skippable: verify → back up what is about to change → apply → record. A write that fails halfway restores the backup and reports failure. Not a transaction — POSIX offers none across many files — but recoverable, which is the achievable property.

  • <root>/.pwsc/state.json — the version, and every file with its digest and origin
  • <root>/.pwsc/backups/<version>/ — what was overwritten, so rollback can return it
  • The install root belongs to the client. A release carries a suggestion; with no root supplied the install stops rather than guessing.

8. The command interface

POST /v1/command   {"command": "vault.list", "args": {"prefix": "cells"}}
-> {"ok": true,  "result": …}          or          {"ok": false, "error": {...}}

Exactly two reply shapes, so a caller never parses prose to learn whether something worked. Eighteen commands: ping, submit, vault.list/get/remove/move/history/log, release.deposit/publish, update.check/plan/install/status/rollback, net.peers/reachable/interfaces.

The constraints are deliberate: loopback only, a token generated on first run at 0600, and a non-loopback bind is refused, not warned about. The command set is an explicit allowlist — no exec, no shell. A command service is remote code execution with a polite name.


9. Connections

The internet. A reachability check that separates "no route" from "connection refused" from "answered, but not a pwsc server" — three causes that look identical in a failed download and need three different fixes. This is why /v1/health answers without a token.

The local network. A UDP beacon every few seconds carrying name, URL, products and the publisher's public-key fingerprint. An announcement carries existence, never content and never authority. Broadcast is unauthenticated by nature, and that is tolerable for exactly one reason: discovery changes nothing about how a release is trusted. A discovered peer still has to hand over a sealed container, checked against a key the client pinned in advance. Discovery may say where to look, never what to accept.


10. Security posture

Layer Control
Archive No member named from a user path → Zip Slip structurally impossible
Restore Mandatory preview, protected-location list, foreign path grammar refused
Integrity Per-blob digests plus the manifest digest; both passes required
Authenticity Ed25519 seal — it does not identify a signer unless the receiver pins a key with --key
Publication --require-seal and --pinned-key: a stolen token allows reading and deleting, not publishing
Boundary Malicious paths refused by name; release fields closed to senders
Commands Loopback, 0600 token, allowlist
Secrets Warned (WC05), not blocked — a container is a data vessel, and blocking pushes people around the tool

11. Tests

File Count What it defends
test_pwsc.py 30 Format, integrity, restore, server, refusals
test_release.py 26 Versions, base, deposit, upgrade, rollback, full cycle
test_partial.py 24 Both selections, and the survival of what was not selected
test_worksheet.py 20 The real schema, unshippable cells, coordinates
test_system.py 25 Boundary, vault, commands, network

The suite is weighted towards refusals rather than happy paths: every interesting failure is a case where a container asks to write where it should not.


12. Four defects the build surfaced

  1. An empty release published successfully. The default excludes contained */build/* and the build tree sat under it → zero files, no complaint. Fixed with a separate RELEASE_EXCLUDES and an explicit refusal (C22). Found by a live run after 53 green tests.
  2. The worksheet reader was reading an imagined schema. It assumed cells was a map keyed by coordinate; it is a list of records. It attached no coordinates and never complained. Found by reading pws/store.py itself.
  3. Provenance was built and then dropped. Had it been passed through as written, a sender could have overwritten kind, turning a partial release into a full one and deleting a customer's files.
  4. A container with no common base broke the error path; it is now refused as a release (C21) and pointed at pwsc restore.

13. Known limits

  • Uploads are read whole into server memory (512 MB ceiling).
  • Installs write file by file, not atomically across the tree.
  • The protected-location list is blunt enough to refuse a legitimate /var/lib/myapp.
  • No delta containers: an update ships the included files in full.
  • No TLS, no accounts, no encryption of the vault at rest.
  • manifest.json does not ship with a partial update; merging registries is a worksheet operation, not a container one.

Missing for real deployment: a system service (systemd) for the agent, TLS for public publication, and vault encryption at rest.


Quick start

# publisher
pwsc keygen
pwsc agent &                                   # control service on 127.0.0.1:8790
pwsc send ~/acme-worksheet --cell G01/F01 --apply
pwsc ctl release.deposit --arg product=acme --arg version=1.1.0
pwsc publish https://updates.example.com acme-1.1.0.pwsc --token …

# client
pwsc check   https://updates.example.com acme --root /opt/acme
pwsc update  https://updates.example.com acme --root /opt/acme --key <public> --apply
pwsc status  --root /opt/acme
pwsc rollback --root /opt/acme