Expand description
§mkit-server
A generic, runtime-agnostic mkit server core. Embedders build a deployment on
it (for example, the Cloudflare Workers adapter in this repository), and
mkit serve in the mkit CLI uses its fs and ssh pieces. It compiles for
native targets and wasm32-unknown-unknown.
§What it provides
- Identifiers (
RepoId,NamespaceKey,Addressing), principals and the typedOperationmodel. - A transport-neutral
ServerErrorwith redaction by construction, mapped to Connect and ssh error codes by the bindings. - The runtime model:
MaybeSend,BoxFuture, injectedClockandSpawner, andsend_wrap; plus aMetricsfacade with no metrics backend. - The storage contract (
store): a key-levelNamespaceStorewhose only write is one declarativeBatch, a content-addressedBlobStore, key layouts, value codecs and the replay-ledger model. - The request pipeline (
pipeline): stage traits, auth modes (open, bearer, auth v2, transport identity), shard routing, the unary RPCs, and resumable streaming upload and download. - Protocol helpers shared by every binding: ref CAS and name checks, upload and download framing, quota evaluation and storage-error redaction.
§Features
| Feature | Effect |
|---|---|
connect (default) | The mkit.transport.v1 Connect binding (connect::service), with its health service and auth interceptor. wasm-clean. |
memory | In-memory reference backends, a template for third-party backends. |
fs | std-only stores over the .mkit on-disk layout (FsBlobStore, FsLayoutStore). Native only. |
sql | A shared SQL backend (SqlKvStore) over a synchronous SqlConn trait; the embedder supplies the engine. |
ssh | The mkit.rpc.v1.ssh session (ssh::serve_session), with no async runtime of its own. |
remote-hooks | Signed mkit.server.hooks.v1 authorization, admission and outcome adapters over a HookChannel. |
http-objects | Runtime-agnostic HTTP object serving; requires explicit configuration and indexed mode. |
published-view | Published reader source; explicit adapter configuration. |
pack-ruzstd | Pure-Rust zstd decoding for wasm targets. |
test-faults | Test-only fault injection. Never enable it in a release build. |
§Related crates
mkit-server-worker: Cloudflare Workers adapter (R2 blobs, Durable Objects). Not published.mkit-server-conformance: backend and wire conformance suites. Not published.
See the crate documentation and docs/SPEC-SERVER.md in the repository for
details.
§License
Licensed under either of Apache License, Version 2.0 or MIT license, at your option.
This crate is runtime-agnostic: it compiles for the host and for
wasm32-unknown-unknown, never reads the wall clock directly (see
Clock) and never spawns on a concrete executor (see Spawner).
The shared vocabulary is re-exported at the crate root from private
modules. The protocol logic lives in public modules, so call sites name
the protocol they apply (refs::evaluate_cas, quota::evaluate_quota).
The storage contract lives in store: its contract types are also
re-exported at the root, its key layouts, value codecs and typed
readers stay namespaced (store::keys, store::codec, store::read),
as do the export/import helpers and the ContentIndex row types
(store::export_partition, store::Holder).
The memory feature adds the in-memory reference backends; the native
fs feature adds the fs module, the stores over the .mkit on-disk
layout; the sql feature adds sql::SqlKvStore, the store over any
synchronous sql::SqlConn; the ssh feature adds the ssh module, the
mkit.rpc.v1.ssh session over the pipeline. The connect feature
(default) adds the mkit.transport.v1 Connect binding over the pipeline
(connect::service); the remote-hooks feature adds the hooks module,
the mkit.server.hooks.v1 adapter over a transport-agnostic channel; the
http-objects feature adds the http_objects module and
Pipeline::serve_http_object (explicit indexed HTTP opt-in).
Re-exports§
pub use policy::GrantConfig;pub use store::Batch;pub use store::BatchOutcome;pub use store::BlobBody;pub use store::BlobKey;pub use store::BlobMeta;pub use store::BlobNamespace;pub use store::BlobStore;pub use store::BoxError;pub use store::ByteRange;pub use store::CommitOutcome;pub use store::ContentIndex;pub use store::Cursor;pub use store::Key;pub use store::KeyClasses;pub use store::MAX_BATCH_BYTES;pub use store::MAX_BATCH_OPS;pub use store::MAX_KEY_BYTES;pub use store::MAX_SCAN_RANGES;pub use store::MAX_VALUE_BYTES;pub use store::MembershipMode;pub use store::MultipartBlobStore;pub use store::NamespaceStore;pub use store::PackSink;pub use store::PartRef;pub use store::PartSink;pub use store::Partition;pub use store::PartitionStats;pub use store::Precondition;pub use store::RangeScan;pub use store::ScanPage;pub use store::StateCommitment;pub use store::StoreCapabilities;pub use store::StoreError;pub use store::StoreMaintenance;pub use store::UnsupportedPartSink;pub use store::Value;pub use store::Write;pub use store::is_reserved_pack_keyspace;pub use telemetry::METRIC_LATENCY;pub use telemetry::METRIC_REQUESTS;pub use telemetry::METRIC_UPLOAD_BYTES;pub use telemetry::Metrics;pub use telemetry::NEVER_ECHO;pub use telemetry::NEVER_LOG;pub use telemetry::NoopMetrics;pub use telemetry::REDACTED_VALUE;pub use telemetry::Redactor;pub use telemetry::is_never_echo;pub use telemetry::is_never_log;
Modules§
- admin
- Signed operator API (§16), durable replay and a gapless audit chain.
- auth_v2
- Auth v2 glue (SPEC-TRANSPORT-CONNECT §7.1): read the ten headers, run
mkit_core::write_auth::verify_headersand decode its result into aVerifiedAuth. Verification itself (canonical fields, validity window, strict Ed25519) stays inmkit-core; nothing here reimplements it. - authority
- Deployment-authority generation statements (SPEC-SERVER §6.2.1). The outer RPC is unsigned; this bounded statement is its authorization.
- connect
- The
mkit.transport.v1Connect binding (featureconnect, SPEC-TRANSPORT-CONNECT):servicemountsTransportServiceandgrpc.health.v1.Healthover aPipeline, behind theAuthInterceptor. It is runtime-agnostic and wasm-clean (connectrpc without itsserverandzstdfeatures), so the native adapter serves it through axum and the Workers adapter through its fetch bridge, both unchanged. - download
DownloadPackchunking (SPEC-TRANSPORT-CONNECT §6.2).- fs
- Stores over the
.mkiton-disk layout thatFileTransportuses today (PRD §5.1, §6.9):FsBlobStorefor<root>/packs/<64-hex>andFsLayoutStorefor refs as files under<root>/refs/, somkit serve <repo-path>(ssh) and anymkit-serverfs-layout deployment serve the same files localmkitcommands andmkit+file://remotes read. - hooks
- Remote hooks: the
mkit.server.hooks.v1adapter (SPEC-SERVER §§6-8), behind theremote-hooksfeature. - http_
objects - Runtime-agnostic HTTP object serving (SPEC-HTTP-OBJECTS; WP-4.12, R-169).
- indexed
- Indexed ingestion shared by native inline verification and future Worker
scheduling. Verification extracts large objects into the global object
store before a pack’s
Verifiedstate is written (WP-4.10). - pipeline
- The transport-neutral request pipeline (PRD §5.4): the unary RPCs of
mkit.transport.v1over the storage contract. - policy
- Deployment namespace and write policy (SPEC-TRANSPORT-CONNECT §7.5).
- purge
- Durable cache purge work and deployment-independent selectors (§16.7).
- quota
- Write quotas: the value types, the default limits and the fixed-window evaluation.
- refs
- Ref compare-and-swap and ref-name helpers (SPEC-TRANSPORT-CONNECT §3, SPEC-TRANSPORT §4.2.1, SPEC-REFS §3 and §4).
- relay
- Source-side, at-least-once outbox delivery. Target watermarks make redelivery idempotent, including a crash before source cleanup.
- scanner_
retrieval - Private raw-pack retrieval for synchronous scanners (SPEC-SERVER §11.4). Capabilities authorize only open ticket-bound bytes; public serving is unrelated.
- sql
- The shared SQL backend (
sqlfeature): theNamespaceStorecontract implemented once overSQLite, on the tiny synchronousSqlConntrait. - ssh
- The
mkit.rpc.v1.sshsession over the pipeline (PRD §6.9, D23; SPEC-TRANSPORT §4.2): theHellohandshake, per-verb dispatch, the streaming upload and download, the per-connection budgets and the CAS conflict reply ofmkit serve, moved here frommkit-cliso the ssh stdio path and any enc listener share one implementation. - storage_
error - Storage-failure redaction (issue #794).
- store
- The storage contract (PRD §5.3): the key-level
NamespaceStore, the content-addressedBlobStore, and the key layouts, value codecs and typed readers every backend shares. Nothing here needs SQL: a single-writer key-value store implements the whole contract. - takedown
- Lean denial and durable takedown intents; adapters control activation.
- telemetry
- Metrics facade and logging hygiene (PRD §8 M0: tracing, metrics, redaction).
- timers
- Partition-local timers, shared by native and Durable Object drivers.
- upload
UploadPackstream framing (SPEC-TRANSPORT-CONNECT §6.1, SPEC-TRANSPORT §4.2).- url_
token - Signed URL tokens (SPEC-WRITE-GRANTS §9.4): the
mkit-url-token:v1statement, its<statement>.<signature>encoding, the deployment’s Ed25519 key set andIssueObjectUrl’s mint.
Structs§
- Authz
Facts - Facts the Authorizer established, carried into
applyas preconditions. M1 establishesowner; M2 (WP-2.6) setsgrantso the pipeline can requiregrant.epochwhen it commits. - Creation
- Namespace and repository creation facts for a write.
- Elapsed
with_timeoutgave up before the future finished.- Error
Detail - A typed error detail (Connect
ErrorDetail): the fully qualified proto message name and its encoded bytes. - Grant
Ref - A grant the Authorizer matched, with the namespace epoch it was checked against.
- Manual
Clock - A clock that only moves when told to. Usable on every target, and shared across threads through interior mutability.
- Manual
Sleep - A
Sleepthat only completes when told to, for tests. Shared across clones;ManualSleep::elapsedstarts already fired. - Memory
Blob Store - An in-memory
BlobStorefor one keyspace. Clones share the blobs. - Memory
Kv - An in-memory
NamespaceStoreover aBTreeMapper partition. - Memory
Pack Sink - The upload handle of
MemoryBlobStore. It hashes incrementally and buffers the blob: the one exception toPackSink’s one-part memory bound, since this backend holds every blob in memory anyway. - Multi
Addressing - Multi-repository addressing with a deployment namespace policy.
- Namespace
Key - A namespace key. Under D34 it selects the namespace coordinator and prefixes every shard key. Single deployments use the reserved default; Multi deployments use a parsed self-certifying namespace (§7.4).
- Operation
- A decoded request, ready for policy and storage.
- Redacted
- A string that never prints its contents through
fmt::Debugorfmt::Display. OnlyRedacted::exposereads it, and only the server-side logging sink should call that. - RefUpdate
- One conditional ref write.
- Replay
Key - The replay key: auth v2
Authorized.scope,BLAKE3(audience \n repository \n pubkey \n nonce). - Replay
Record - A replay-ledger record.
- RepoId
- A repository’s full identity.
- Repo
Name - A repository name: 1..=255 bytes of printable ASCII with no whitespace
(bytes
0x21..=0x7e). - Resolved
Repo - A resolved request target and its byte-exact wire identity.
- Server
Error - A transport-neutral server error.
Displayshows the public message only.Debugshows the log detail asRedactedand replaces the value of everycrate::NEVER_LOGheader with a placeholder; a sink that knows deployment-configured names logs headers throughcrate::Redactorinstead. - Stored
Rejection - A storable rejection: a final code and its public message, with no error detail (so never an admission challenge).
- System
Clock - The host wall clock. Native targets only; Workers supply their own.
- Verified
Auth - A verified auth v2 authorization, decoded from
mkit_core::write_auth::Authorized.
Enums§
- Addressing
- How a deployment maps a request to a repository.
- Begin
Upload Result - A replayable ticket-opening result. Tokens are retained verbatim.
- Code
- Error category: the 16 Connect codes, one-to-one.
- Commitment
- The content commitment an auth v2 signature covers.
- Invalid
Header - Why a response header was refused.
- Memory
Fault - A one-shot failure a memory store injects, for tests of the layers above. Each store fires only the faults that apply to it.
- OpKind
- What an operation does, with its decoded arguments.
- Presence
Requirement - Server-local §8.2 condition carried from authorization to each plan.
The ref name makes an
AdvanceRefsconstraint apply to its head only. - Principal
- The identity a request was mapped to. Non-exhaustive: M2 may add a caller-view class.
- Procedure
- A
mkit.transport.v1.TransportServiceprocedure. - Replay
Decision - What stage 0 does with a request, given its record.
- Replay
State - Where a recorded operation stands.
- Stored
Result - A final result a retry gets back. There is deliberately no variant for
an admission challenge or
pending_verification, and aStoredRejectionholds only final codes and no error detail, so neither can ever be stored. - Update
RefResult - The result of an
UpdateRefcompare-and-swap.
Constants§
- ADMISSION_
CHALLENGE_ TYPE - Fully qualified proto name of the admission challenge detail (SPEC-TRANSPORT-CONNECT §5.1).
Traits§
- Clock
- Injected time source, in Unix epoch milliseconds.
- Maybe
Send Sendon native targets; implemented for every type on wasm32.- Maybe
Sync Syncon native targets; implemented for every type on wasm32.- Sleep
- Injected timer, the counterpart of
Clockfor deadlines:Instantandtokio::timeare not available on every target, so an adapter passes in its runtime’s sleep (tokio::time::sleepon native,worker::Delayon Workers) and core code bounds an external call withwith_timeout. - Spawner
- Injected task spawner: tokio on native,
wasm_bindgen_futuresorctx.wait_untilon Workers.
Functions§
- classify
- Classify a request with
fingerprintagainst its record, if any. - send_
wrap - Make a
MaybeSendfuture satisfy the+ Sendbound that generated connectrpc service traits require. On native targets the future is alreadySendand is returned unchanged. - with_
timeout - Run
fut, giving up withElapsedoncesleepsaysafterhas passed. A future that is ready wins over an elapsed timer, and a timed-out future is dropped, so the caller must not assume its side effects did not land.