Keyboard shortcuts

Press ← or → to navigate between chapters

Press ? to show this help

Press Esc to hide this help

Mod permissions, channels and blob storage

Three host services that Enki B specifies for every mod (Enki B (docs/superpowers/specs/2026-09-27-enki-b-mod-platform-contract-design.md) §4, §7, §8). Their native Rust APIs and host plumbing exist on both hosts, and guests reach them through manifold:perms/permissions, manifold:net/mod-channel and manifold:storage/blob-store, published in the open 0.2 track (see Guest interfaces). Mods’ permission and channel declarations reach the host in their ModDeclarations (see Declaring).

Declaring

A mod writes its permissions in mod.toml and its channels in Plugin::build:

[permissions]
# Platform nodes (and limits) the mod's own (mod-self) operations use.
uses = ["build.load-chunks"]

[[permissions.declare]]
name = "enki.use"
default = "admin"         # who holds it without configuration: player | admin

[[limits]]
name = "enki.cells.max"
default = { player = 65_536, admin = 8_388_608 }
max = 134_217_728
let edit = app.add_channel(ChannelDecl {
    requires: Some("enki.use".into()),
    ..ChannelDecl::client_to_server("edit")
});
  • Into the declarations. #[mod_entry] reads the crate’s mod.toml at build time and bakes [permissions] and [[limits]] into ModDeclarations::permissions; add_channel registrations become ModDeclarations::channels, numbered by position (ModChannel). Both are format 13 fields. cargo mod build refuses a component whose declarations disagree with its manifest.
  • The rules. One rule set, platform_decls (crates/manifold-modloader/src/platform_decls.rs), runs in the manifest parser, cargo mod build, the loader on both hosts and the catalogue: nodes and limits only under the mod’s own id (a platform namespace is refused naming its owner); uses names platform nodes or the mod’s own declarations; no name twice; limits <ns>.<thing>.max with 0 <= default <= max; channel names [a-z0-9_-], unique, and a requires that is a platform node or one the mod declares. A module that breaks one fails its load with an error naming the mod and the name.
  • Joining the services. The server registers every loaded mod’s declarations at boot, after the orchestrator loads and before any connection (mod_platform::install_server_declarations (crates/manifold-host-core/src/mod_platform.rs)). A client registers its loaded mods’ channels before each client tick (sync_client_channels), so modules delivered after the handshake join too. Labels are implied catalog keys: <mod-id>.permission.<local>, with .description.

Permission nodes

A player has a level (Player < Admin) and a set of permission nodes, dotted names <namespace>.<name> such as build.edit. A limit is a valued node, an i64 per player, named <namespace>.<thing>.max.

  • One catalogue. PermissionCatalogue (crates/manifold-server-state/src/permissions/catalogue.rs) holds every node and limit. The platform programs register theirs at boot (permissions::platform (crates/manifold-server-state/src/permissions/platform.rs)): Enki’s build.* and world.*, Pygmalion’s animation.* and Talos’s talos_observe::nodes::NODES (crates/manifold-server-state/src/talos_observe/nodes.rs), each with its own defaults. A loaded mod’s declarations join through register_mod, namespaced by its id.
  • One seam. Every check goes through anim_contract::player_has_node (crates/manifold-server-state/src/anim_contract.rs), a bit test in the player’s resolved set in ConnectionPermission (crates/manifold-server-state/src/connection_permission.rs). Admin and the local host hold every node; a node the catalogue does not know is Admin’s only; an unknown connection holds nothing.
  • Resolution. A connection’s set is resolved at accept and on change, never per check, from its level, local-host status and its proven account’s entry in permissions.ron. A node is held when its default is player or the file grants it, unless the file denies it; deny never removes anything from Admin or the local host. Limits take the local host’s max, else the declared default for the level.
  • mod-self. An operation a mod makes on its own authority (a transaction, animation or physics op with actor mod-self) needs every node it would need from a player, held only if the mod declares it or lists it in uses; a mod’s uses list is its whole scope, not documentation (#584). Every boundary that accepts a mod-self actor checks through one fail-closed seam in permissions (crates/manifold-server-state/src/permissions/mod.rs): mod_self_check(world, mod_id, node) -> Result<(), ModSelfDenied> (mod_self_has_node is its boolean form). Without the permission table, or for a mod that registered nothing, nothing is held. The refusal, ModSelfDenied { mod_id, node }, names the mod and the missing entry: mod `enki` used `build.state` without declaring it in [permissions] uses, and ModSelfDenied::to_text gives the same message as the localized key engine.permissions.mod_self_undeclared ($mod, $node). A boundary whose wire refusal already names the node keeps it (a transaction or animation op is refused not-permitted(node)) and logs the named refusal at debug level.
  • mod-self limits. A mod’s value for a limit is mod_self_limit(world, mod_id, name) -> Result<i64, ModSelfDenied> (PermissionCatalogue::mod_self_limit on a catalogue): the limit’s operator ceiling, its max, when the mod declares it or lists it in uses, and refused otherwise (also for an unknown limit or an unregistered mod). A mod is never given a level’s column: it is not an admin. Server configuration lowering a mod’s ceiling is B-PERM2 (#249).
  • Rule actors. The engine’s own rules hold every node and are never checked; only engine code can act as a rule.
  • Guard. The mod_self_guard workspace guard (in manifold-test-support) scans every crate’s sources and fails on a ModSelf arm that yields true, Ok(()) or the admin limit tier, or shares its arm with Rule. Its KNOWN_UNFIXED list names files whose fix is in flight (the physics boundary, #584); an entry is removed when its fix lands.
  • The client’s copy. Each connection receives its own level, nodes and limits in S2C::PermissionsUpdate (client state: OwnPermissions (crates/manifold-client-state/src/mod_channel.rs)), once its grants are installed and after every change. It is for display and UI gating only.
  • Mod UIs. The reserved manifold:ui-actor-permission bundle entry carries the actor’s level, then the nodes it holds and the limit values within the mod’s scope (UiActorPermissionWire (crates/manifold-mod-types/src/ui_actor.rs)). A guest that decodes only the level still reads it.

permissions.ron

An optional file beside ops.ron in the server data directory. ops.ron keeps meaning Admin. Both are keyed on the account a join proves, never a display name, and share one table and one version-1 migration (operators (docs/architecture/player-identity.md), #557).

// permissions.ron — keyed on proven accounts; labels are for reading only
(
    version: 2,
    players: [
        (account: Offline("3b6a27bc…"), label: "Carol", grant: ["enki.use"]),
        (account: Platform("6f1d0e2c…"), label: "Dave", grant: ["enki.use"], deny: ["build.edit"]),
    ],
)

A missing file grants nothing; a malformed one grants nothing, logs a warning and is never overwritten. /perm show <user> lists the online players with that name. /perm grant <user> <node> (Admin) grants the proven account of the one online player named <user>; /perm revoke <user> <node> revokes it from online players with that name and from entries labelled with it. Both rewrite the file atomically and update connected players at once. A version-1 file (players keyed by platform username) loads as unbound names, which bind only on a platform-signed join. Tiers, default overrides and per-player limit values are not applied yet (#249); a file that uses them loads its players and warns.

Platform namespaces

The namespaces platform programs own are reserved mod ids (reserved.rs (crates/manifold-modloader/src/reserved.rs)), listed with their owners in the platform-namespaces table (docs/architecture/extension-contracts.md).

Mod message channel

A mod declares named channels between its halves (ChannelDecl (crates/manifold-mod-types/src/channel.rs)): a direction, a size cap, a token bucket and an optional requires node. Every message rides one reliable transport channel, CH_MOD (7), as C2S::Mod or S2C::Mod, so a large mod payload never delays engine events.

  • Handles. Both sides build the same ModChannelRegistry (crates/manifold-host-core/src/mod_channel.rs) from the loaded mods’ declarations: mods sorted by id, then each mod’s channels in declaration order. Handles are derived, never exchanged; the mod-set check makes both sides load the same modules. A guest numbers its channels by declaration position.
  • Server delivery. The inbound phase stages each message (mod_channel (crates/manifold-server-state/src/mod_channel.rs) in server state); before the tick’s guest systems, deliver_server_inbound drops and counts messages on an unknown handle, against the channel’s direction, over its size cap, from a sender without its requires node, or over the sender’s token bucket. The rest reach the mod’s inbox in arrival order with the sender’s player, level, and nodes and limits within the mod’s scope, captured at delivery.
  • Limits. A declaration is clamped by the server’s ChannelLimits; an inline message never exceeds 1 MiB. Buckets refill per server tick in integer milli-tokens, identically on both hosts.
  • Replies (server_send_to, server_broadcast) queue S2C::Mod on the connection at once. The client checks its sends too (client_send), so a client learns it is rate limited instead of being dropped.

Only reliable inline messages are served. Transfers come later; an unreliable-latest channel is served reliably, capped at the datagram size.

Blob storage

ModBlobStore (crates/manifold-server-state/src/mod_blobs.rs) keeps per-mod blobs in the world save, in the world scope (per mod) and the world-player scope (per mod and durable player id). Both hosts store them in one redb table, mod_blobs_v1 (table helpers (crates/manifold-saves-types/src/mod_blobs.rs)), in the same database as the chunks: the native save store and the browser’s OPFS-backed RedbOpfsSaveStore.

  • Keyed by the host. Every operation names the mod id the host authenticated; a guest never states it.
  • Deferred results. Each call returns a request id; results drain through take_completions on both executors.
  • Saved with the world. A write is staged and reaches the table in the world’s next save transaction, so blobs never disagree on disk with the world they describe. Reads see staged changes first; a failed save stages its rows again.
  • Quotas. 1 GiB per mod for world and 256 MiB per mod per player for world-player (no world-player quota in browser singleplayer); a write over quota fails and changes nothing.
  • Paths are 1 to 8 /-separated segments, at most 256 bytes, with no empty, . or .. segment.

Guest interfaces

Each interface’s host functions run inside the mod’s own systems, where the orchestrator lends the instance the world (Mod contract, the world loan); outside one they fail with outside-system, and on the side an interface does not serve with wrong-side. The logic lives once in manifold-wasm-host-core::capability (crates/manifold-wasm-host-core/src/capability/) over per-side ports that platform_ports (crates/manifold-host-core/src/platform_ports/mod.rs) installs; the wasmtime host and the jco shims only convert values.

InterfaceFunctionsSidesSDK
manifold:net/mod-channel (consent listed)send (client), send-to, broadcast (server), take-inboundbothchannel (crates/manifold-mod-substrate/src/channel.rs): ModApp::add_channel::<T> returns a typed ModChannel<T> for a #[derive(ModMessage)] type, with send, send_to, broadcast and receive
manifold:storage/blob-store (consent operator)read, write, delete, list, take-completions, quotaserverblob_store (crates/manifold-mod-substrate/src/blob_store.rs)
manifold:perms/permissions (consent listed)level, has, limit, actor-has (server), own-level, own-has, own-limit (client), declaredbothpermissions (crates/manifold-mod-substrate/src/permissions.rs)
  • Channels. A channel’s number is its declaration position. ModApp::add_channel::<T> records T’s ModMessage::NAME as the declaration’s message, which names the type whose postcard encoding the channel’s opaque payloads are (PAYLOADS.toml mod-message). take-inbound drains every channel of the mod at once, so the SDK keeps messages per channel until each is read. The server half sees each sender’s player, its permission-level (the u8 ladder: Player 0, Admin 200) and the nodes and limits within the mod’s scope. A client send’s token bucket refills against the client’s TickCursor.
  • Blobs. Operations keep the deferred shape and complete at the call (Enki B issue 32): the store’s results move into the instance’s own queue at once, so the next take-completions returns them in call order. A call that reaches no store (outside a system, on the client, a key whose player part does not match its scope, a server without a store) still returns an id, numbered from bit 63 up so it never meets the store’s ids, and its failure arrives at the next drain.
  • Permissions. The server answers for any connected peer and, through actor-has, for mod-self (the nodes the mod declares and lists in uses); a player-ref whose durable id is not the connection’s is unknown-peer. The client answers for its own player from the last S2C::PermissionsUpdate (Player and nothing held before the first). declared answers from the mod’s checked declarations on either side.

Regression coverage

  • Declaration rules: manifold-modloader (platform_decls, the manifest sections); the loader refusing a platform-namespace node: manifold-wasm-host export_split; cargo mod build’s manifest check.

  • Catalogue, resolution, namespace rule, the mod-self refusal and limits, and mod-self transactions and animation ops: unit tests in manifold-server-state (permissions, connection_permission, transaction, anim_contract) and the mod_self_guard scan; permissions.ron and /perm (including a mod’s nodes and limits) in manifold-server.

  • Channel registry and token buckets: manifold-host-core mod_channel tests; blob store: manifold-server-state mod_blobs; the redb table: manifold-saves-types mod_blobs (the helpers both hosts use).

  • On a real server over the local transport: mod_platform_e2e.rs (crates/manifold-server/tests/mod_platform_e2e.rs) (ordering, every drop reason, sender context, replies, permission updates, blobs across a restart; and the enki-stub fixture mod’s mod.toml permissions and channels registered on a server and a client with the same handles, a message flowing from its client half to its server half and back).

  • Guest interfaces: unit tests in manifold-wasm-host-core’s capability modules; the real ports in manifold-host-core’s suite (platform_channel, platform_storage_perms); the platform-smoke test mod through wasmtime on a server world in manifold-server’s platform_smoke_e2e, and through wasmtime and jco against the recording ports (capability::platform_record) in web_parity.rs (crates/manifold-wasm-host/tests/web_parity.rs) (browser CI job).