Files
Build-System/docs/build-system/developer/registry-internals.md
T

11 KiB
Raw Blame History

title, description, section, badge, order, tags, updated
title description section badge order tags updated
Registry Service Internals HTTP routes, authentication, storage layout, package and binary endpoints, remote cache and worker protocol Registry & Remote registry 1
internals
registry
http
rbac
csrf
storage
cas
workers
leases
2026-12-06

Registry Service Internals

RegistryService is a POSIX-only HTTP/1.1 service built on a small socket loop (or Void::Net::HttpServer when linked). It serializes API mutations on one mutex, stores package blobs and action-cache blobs on disk, and keeps users, tokens, packages, releases and audit records in one JSON metadata file.

Startup and storage

RegistryService::open(RegistryConfig) creates:

<data-dir>/
├── metadata.v1.json                 # users, tokens, packages, releases, audit
├── registry.lock                    # per-save advisory lock
├── cas/blobs/<2>/<sha256>           # package + binary blobs, 0444
└── action-cache/
    ├── blobs/<2>/<sha256>           # remote-cache outputs
    └── actions/<2>/<sha256>.json    # action records

metadata.v1.json is rewritten synchronously on every mutation under registry.lock. Package blobs are published before the metadata commit that references them. Sessions, workers, leases and the action queue are in-memory only and disappear on restart.

Configuration defaults:

Setting Default
max_upload_bytes 32 MiB
max_storage_bytes 2 GiB (source-release digests only)
bootstrap_admin_user admin
Audit cap 2000 entries (oldest 500 trimmed)

--web-root defaults to <Bootstrap::source_dir>/registry/web, which is a source-tree path. Packaged deployments must point it at the installed assets.

Transport

  • HTTP/1.1, one request per connection (Connection: close).
  • Header limit 64 KiB; body limit max_upload_bytes; 10 s socket timeouts.
  • HEAD is routed as GET with the body suppressed and Content-Length preserved.
  • Every response sets X-Content-Type-Options: nosniff, X-Frame-Options: DENY, Referrer-Policy: no-referrer and a restrictive CSP.
  • Errors are {"error":{"code":"…","message":"…"}}.
  • OPTIONS is answered from route shape before authentication with 204 + Allow; no CORS Access-Control-* headers are emitted.
  • A single Range: bytes=… is supported (206 + Content-Range, 416 for unsatisfiable/multipart).

Authentication and authorization

Roles are reader, publisher, admin. Principal resolution order:

  1. Authorization: Bearer … (hash lookup, constant-time compare, revoked/expired/inactive checks);
  2. the vbs_session cookie.

Bearer requests are exempt from CSRF. Cookie-authenticated mutations require X-CSRF-Token matching the session token; if Origin is present it must be loopback HTTP or HTTPS.

Sessions:

  • 24-byte session id and 24-byte CSRF token;
  • stored hashed, 24-hour expiry, in memory only;
  • cookie is HttpOnly; SameSite=Strict; Path=/, not Secure (fine on loopback, must be terminated by TLS behind a proxy).

Tokens:

  • plaintext is vbs_tok_ + 48 hex, returned once; only SHA-256 is stored;
  • scopes are free-form, but only read, publish, admin are consulted;
  • API-created tokens have no expiry; revocation is a soft flag;
  • a token can mint another token up to its user's role, not beyond the calling token's scope (scope intersection is not implemented).

Private packages:

  • public listing excludes them;
  • anonymous access is 401; an authenticated principal with read can read them;
  • this is team visibility, not a per-user ACL;
  • first publisher becomes sole owner; admin bypasses ownership; removing the last owner is 409 last_owner.

Routes

Public/auth

Method + path Auth Purpose
GET /api/v1/health none {"status":"ok","schema_version":1}
POST /api/v1/auth/login none Session cookie + csrf_token; 401 on bad credentials
POST /api/v1/auth/logout principal (+CSRF for cookie) Clear session
GET /api/v1/auth/me principal Username, role, CSRF token
GET /api/v1/packages optional Search q + limit/offset envelope
GET /api/v1/packages/<name> optional Detail, owners, releases
PATCH /api/v1/packages/<name> publish + CSRF Description/private metadata
GET /api/v1/packages/<name>/owners optional Owner list
PUT/POST/DELETE .../owners/<user> publish + CSRF Owner management

Search q is a case-sensitive substring over name and description. limit defaults to 100 and is capped at 500; offset is capped at 1,000,000. The response is {packages,total,limit,offset}.

Releases and binaries

Method + path Auth Purpose
GET .../packages/<name>/<version> optional Release detail with digest, size, yank, publisher, signature, binary summaries
PUT .../packages/<name>/<version> publish + CSRF Raw source tar upload
GET .../<version>/download optional Tar download with X-Content-SHA256
PUT .../<version>/binaries/<variant> publish + CSRF Upload a binary variant
GET .../<version>/binaries optional List variants
GET .../<version>/binaries/<variant> optional Variant detail + download_url
GET .../binaries/<variant>/download optional Variant bytes
POST .../<version>/yank publish + CSRF Yank/unyank a release
POST .../binaries/<variant>/yank publish + CSRF Yank/unyank a variant

Publish headers:

  • X-Content-SHA256: must match the body (400 digest_mismatch);
  • X-Package-Description, X-Package-Private;
  • X-Package-Signature / X-Package-Public-Key (both-or-none, 128/64 hex);
  • binary variants use X-Binary-Signature / X-Binary-Public-Key.

Immutable release semantics:

  • identical bytes for an existing version → 200 already_published;
  • different bytes → 409 immutable_conflict;
  • malformed archive (traversal, symlink, duplicate, quota) → 422 invalid_archive;
  • storage quota → 413 quota_exceeded.

Signature metadata is stored and served but never verified by the server. Trust belongs to the consumer.

Release and binary detail/listing responses carry a strong ETag and Cache-Control: no-cache and honour If-None-Match (weak prefixes, lists, *) with a bodyless 304. Download ETags are the artifact digest. Downloads support single ranges and HEAD.

Yanking only flips a flag; download routes still serve yanked bytes. Clients hide yanked variants from selection.

Tokens, users, audit

Method + path Auth Purpose
GET /api/v1/tokens principal Own tokens; admin sees all
POST /api/v1/tokens principal + CSRF Create token, plaintext returned once
DELETE /api/v1/tokens/<id> principal + CSRF Revoke
GET/POST /api/v1/users admin (+CSRF) Paginated users / upsert
GET /api/v1/audit admin Filters actor, action substring, outcome; paginated
GET /api/v1/admin/storage admin Used/quota/package count
GET /api/v1/stats admin Counts + ETag

POST /api/v1/users is an upsert: it can overwrite a password and role. There is no deactivate/reactivate route in 1.0.0.

Audit entries record timestamp, actor, action, target, outcome and redacted detail. Logins, token operations, user changes, publish/update/yank, owner changes, binary operations, CAS writes, worker registration and queue/lease actions are audited. Most 401/403 denials are not.

Remote cache endpoints

Method + path Auth Purpose
GET/PUT /api/v1/cas/blobs/<sha256> any principal Raw blob store; PUT verifies the digest
GET/PUT /api/v1/cas/actions/<action-key> any principal JSON action record

PUT returns 200 when the object already exists and 201 when created. The client re-verifies downloaded blobs. The server does not enforce package ownership on CAS objects.

Worker and lease endpoints

Method + path Auth Purpose
POST /api/v1/workers any principal Register, returns wrk_…
POST /api/v1/workers/<id>/heartbeat owner/admin Refresh liveness
GET /api/v1/workers owner/admin List
POST /api/v1/queue publish/admin Enqueue up to 64-hex action keys
GET /api/v1/queue any principal Pending + leased keys
POST /api/v1/queue/lease any principal FIFO lease, optional worker_id, lease_seconds 1–3600
POST /api/v1/actions/lease any principal Lease a specific key, returns the record
POST /api/v1/actions/<key>/renew lease token Extend lease
POST /api/v1/actions/<key>/result lease token Store result, require all output blobs, erase lease, dequeue

Leases are pruned lazily. Results must reference an existing action record and every declared output blob must already be in the action-cache CAS; the endpoint then writes the record atomically. There is no per-tenant queue scoping, no worker affinity and no scheduling policy.

Web UI

The static UI supports package search/detail, source release upload, release download/yank, token management, storage, user creation and the audit log. It renders with textContent and sends CSRF on mutations.

It does not implement binary-variant browsing/publishing, owner management, metadata editing or upload progress in 1.0.0. There is no automated headless-browser coverage of the UI.

Backup and restore

RegistryService::backup_to(dir) and restore_from(dir) exist in the C++ API but have no CLI or HTTP route. They copy metadata and source-release blobs only; binary blobs and the entire action cache are excluded. Restore is additive and does not verify blob digests.

For a complete backup, stop the writer and copy the entire data directory. That is the only path that preserves binary variants, action-cache blobs and metadata together.

Security model and limits

  • Loopback default; TLS is expected from a reverse proxy.
  • No rate limiting, login throttling, automatic token expiry, user deactivation or per-user private-package ACL.
  • Private package existence is distinguishable: missing is 404, private is 401 anonymous.
  • Path segments are not percent-decoded; clients URL-encode names and versions.
  • Upload bodies are buffered in memory (32 MiB cap), not streamed.
  • Metadata is one JSON file; there is no SQLite registry backend.
  • Sessions/queue/leases are lost on restart.
  • OPTIONS is not a real CORS preflight.
  • Reason phrases for some non-200 statuses are emitted as OK.

These are operational constraints to plan around, not hidden behavior; the implementation fails explicitly rather than pretending a stronger guarantee.

Next: reproduce a self-hosted release.