Files
chef/doc/nostr-submission-relay.md
raucao 1b1e2fbb3d Runbook: document the deployed state and fix the NIP-11 check
The submission relay and both promotion paths are live in production, so the
runbook no longer claims that nothing has been deployed. Reframe the deployment
order and pre-go-live checks as completed, and fix the verification command:
strfry only returns the NIP-11 JSON with an Accept header, so the old
curl | jq pipeline could never work.
2026-11-18 14:31:00 +04:00

12 KiB

Nostr submission relay (Chef)

Chef-side pieces of the public submission relay + image-recognition moderation MVP (raucao/marco#97). The canonical plan/spec lives in the Marco repo, doc/nostr/submission-relay-mvp/.

This document is the Chef runbook: what the code deploys, how it was rolled out, and how to roll it back. The stack is deployed to production — the relay is live at wss://submit.nostr.kosmos.org and both promotion paths are enabled. The deployment order below is kept as a record of the rollout and for rebuilding the service elsewhere.

What the Chef code adds

Piece Where Recipe / role
Public submission relay (strfry #2, :7778) one node role[strfry_submission] → kosmos_strfry_submission::default
Firewall for :7778 same node kosmos_strfry_submission::firewall
wss://submit.nostr.kosmos.org vhost + cert openresty proxy nodes kosmos_strfry_submission::nginx (via role[openresty_proxy])
Approved-event sync (staging :7779 → production DB) production relay node kosmos_strfry::approved_sync (via role[strfry])
Member bridge (:7778 → production DB, LDAP-only) production relay node kosmos_strfry::member_bridge (via role[strfry])
Node 24 LTS for the Node write policies relay nodes role-scoped kosmos_nodejs.version override

Write policies from kosmos/akkounts extras/strfry/ are fetched at converge time:

  • submission-policy.mjs — open write gates for the submission relay (Node).
  • sync-policy.mjs — fail-closed policy for strfry sync (Node; see below).
  • ldap-only-policy.ts — LDAP membership gate for the member bridge (Deno; see below).

Design notes / invariants

  • The submission relay is not role[strfry]. The openresty proxy builds its production _strfry upstream from role:strfry; a submission node must never be added to it. The new role also avoids role[ldap_client], because the submission relay is open to all authors and does not do LDAP.
  • The sync is the only non-member write path into production. It runs strfry --config /etc/strfry-sync.conf sync <staging> --dir down, one-way, every 5 minutes. strfry sync --dir down runs the local write policy with sourceType="Sync" and sourceInfo=<remote relay URL> (src/apps/mesh/cmd_sync.cpp), so sync-policy.mjs can accept only that exact source and reject everything else. STAGING_RELAY_URL is passed to the unit and must byte-match the URL on the command line — both come from the single node["strfry"]["staging_relay_url"] attribute.
  • The sync uses the production database (node["strfry"]["config"]["db"]) with a 100-year age floor (rejectEventsOlderThanSeconds = 3153600000) so long-delayed approvals still land. Note that 0 does not disable this check in strfry: strfry computes earliest = now - rejectEventsOlderThanSeconds, so 0 makes earliest == now and rejects every event as "created_at too early" before the write policy runs. A large bound is the way to turn it off.
  • The sync config sets nofiles explicitly. strfry raises its RLIMIT_NOFILE to relay.nofiles at startup and exits if that exceeds the process hard limit. The compiled-in default (1000000) is above the systemd default here (524288), so strfry_sync.conf.erb sets nofiles = <production value or 524288>. Without it the sync fails to start with Unable to set NOFILES limit to 1000000.
  • The submission relay is reachable only from the openresty proxy nodes. The relay trusts nginx's X-Real-IP (realIpHeader = "x-real-ip"), so a direct connection could forge that header and defeat the policy's per-IP token bucket. kosmos_strfry_submission::firewall therefore allow-lists the ZT IPs of the role:openresty_proxy nodes instead of all of 10.1.1.0/24 (the per-author bucket is unaffected). Consequence: anything that talks to the relay directly over ZeroTier must be added explicitly — in particular, if the WS2 moderator is switched from wss://submit.nostr.kosmos.org to the ZT-direct ws://<relay>:7778, add the nuc's address to the allow-list (or route it through nginx). The member bridge uses loopback and is unaffected.
  • No --filter on the sync. The worker only publishes approved events to the staging relay; the policy is the gate.
  • The member bridge is a live strfry router, not a service. A stream group with dir = "down" subscribes to ws://localhost:7778 and writes member-authored events into the production LMDB; its pluginDown is ldap-only-policy.ts, so membership is decided per event by LDAP and no member list is maintained. The group's filter bounds the REQ (and therefore the LDAP lookups) to the submission kinds. dir = "down" makes it strictly one-way: the router never watches or forwards the local DB. pluginDown's path contains no spaces, so strfry watches its mtime and hot-reloads it without a restart. It writes to the same LMDB as the relay (the same multi-process access pattern as the approved sync).
  • Both promotion paths are enabled from role[strfry_submission]. The strfry.approved_sync.enabled and strfry.member_bridge.enabled switches are set as role overrides, not in the production environment, so they travel with this feature's roles. (The recipes themselves live in role[strfry]; the relay node runs both roles.)

Attributes

Attribute Default Notes
strfry.staging_relay_url ws://10.1.1.183:7779 nuc ZeroTier IP + staging port
strfry.approved_sync.enabled false no-op until enabled (true in role[strfry_submission])
strfry.member_bridge.enabled false no-op until enabled (true in role[strfry_submission])
strfry.member_bridge.subscribe_relay ws://localhost:7778 local submission relay
strfry.member_bridge.plugin_cmd /opt/strfry/ldap-only-policy.ts LDAP-only pluginDown
strfry.member_bridge.kinds [0, 3, 5, 360, 30360] router REQ kind filter
strfry_submission.domain submit.nostr.kosmos.org
strfry_submission.port 7778
strfry_submission.config.db_params.mapsize 4 GiB disk cap for the disposable DB

Regression checks

site-cookbooks/kosmos_strfry/test/strfry_sync_conf_test.rb renders strfry_sync.conf.erb with the attribute shapes approved_sync.rb passes and fails if the sync config's rejectEventsOlderThanSeconds is missing or <= 0 (the guard for the "0 rejects every event" trap above) or if nofiles is not set to the expected value (strfry exits at startup when its nofiles exceeds the systemd LimitNOFILE). It needs neither a Chef server nor a converge — only the chef gem and stdlib ERB:

ruby site-cookbooks/kosmos_strfry/test/strfry_sync_conf_test.rb

site-cookbooks/kosmos_strfry/test/member_bridge_conf_test.rb renders member_bridge.conf.erb with the attribute shapes member_bridge.rb passes and fails if the stream group is not one-way (dir != "down") or not gated by the LDAP-only policy (missing/wrong pluginDown, or a plugin path containing a space, which strfry would not hot-reload). Only stdlib ERB is needed:

ruby site-cookbooks/kosmos_strfry/test/member_bridge_conf_test.rb

Deployment order (as performed)

All of the steps below have been performed; this is the order that was used. Keep it for rebuilding the service on another host.

  1. HARD PRECONDITION — akkounts live branch. Before any converge, the live branch of kosmos/akkounts must contain extras/strfry/submission-policy.mjs, extras/strfry/sync-policy.mjs and extras/strfry/ldap-only-policy.ts. Chef fetches them from https://gitea.kosmos.org/kosmos/akkounts/raw/branch/live/extras/strfry/… at converge time; if any is missing, the remote_file resource fails and the converge aborts (with a partially configured host). Verify with: curl -fsSI https://gitea.kosmos.org/kosmos/akkounts/raw/branch/live/extras/strfry/submission-policy.mjs and the same for the other two files. These files are produced by WS1, not by this repo.
  2. DNS. submit.nostr.kosmos.org is a CNAME to lb.kosmos.org at Gandi (already configured). Chef does not manage DNS; the gandi_dns Let's Encrypt challenge cannot succeed without it. Verify it resolves before converging the proxy nodes.
  3. Relay node. Assign role[strfry_submission], converge. Creates the binary (or reuses it), DB, config, policy and strfry-submission.service. The firewall allow-lists the current role:openresty_proxy node IPs, so the proxy nodes should already be registered as Chef nodes.
  4. Proxy nodes. Converge role[openresty_proxy]; this adds the submit.nostr.kosmos.org site and requests the certificate.
  5. Enable the promotion paths. Only after the worker + staging relay (WS2) are live: role[strfry_submission] sets strfry.approved_sync.enabled and strfry.member_bridge.enabled to true (role overrides, not the environment). Converge role[strfry]. This deploys sync-policy.mjs, the sync config, strfry-sync.timer, ldap-only-policy.ts, the member-bridge config and strfry-member-bridge.service.
  6. Verify.
    • systemctl status strfry-submission / strfry-sync.timer / strfry-member-bridge.
    • curl -s -H 'Accept: application/nostr+json' https://submit.nostr.kosmos.org | jq -r .name → Kosmos submission relay. (Without the Accept header strfry serves its HTML info page, which jq cannot parse.)
    • journalctl -u strfry-sync shows accepted events after an approval.
    • journalctl -u strfry-member-bridge shows Connected to ws://localhost:7778 and rejects non-member events (pluginDown blocked event … Only members can publish notes on this relay).
    • The production relay's NIP-11 and _strfry upstream are unchanged.

Pre-go-live verification (completed)

  • LMDB concurrency (verified 2026-11-17 on the nuc's :7777 mirror). A strfry sync --dir down was run against the same LMDB that the live relay was serving from. Result: sync exited 0 and the relay answered 13/13 subscriptions (39 events) during the sync; the relay stayed active and the event count was unchanged. This is the same access pattern the approved-sync uses on strfry-1 (same DB, separate strfry sync process), so no additional lock is needed.
  • No rogue sync path. Confirmed before the timer was enabled: no external negentropy/websocket path can produce sourceType = "Sync" on the production relay; the sync policy is fail-closed on the exact staging URL.

Rollback

  • Sync: set strfry.approved_sync.enabled = false and converge, then systemctl disable --now strfry-sync.timer. (The recipe becomes a no-op, but it does not stop an already-running timer.)
  • Member bridge: set strfry.member_bridge.enabled = false and converge, then systemctl disable --now strfry-member-bridge.
  • Submission relay / proxy: remove kosmos_strfry_submission::nginx from role[openresty_proxy] and role[strfry_submission] from the node, converge, then systemctl disable --now strfry-submission. The DB at /var/lib/strfry-submission can be deleted independently; the production relay and its database are untouched.

Node.js caveat (checked before converging)

The Node write policies (submission-policy.mjs, sync-policy.mjs) are Node 24 ESM scripts, so role[strfry_submission] and role[strfry] add a role-scoped kosmos_nodejs.version override to 24.22.2. The global default (14.21.3) is deliberately not raised. (ldap-only-policy.ts is a Deno script and needs no Node.)

If either role is applied to a host that already runs other Node/JS services, verify they do not depend on Node 14 before converging:

  • On strfry-1: blossom uses Deno (its recipe sets DENO_DIR), not Node; substr is the prebuilt Rust binary from the package registry. Neither currently installs or uses Node, so adding Node 24 is additive. Re-check if substr ever falls back to deno task server or if a Node-based service is added.
  • Any other node that gains role[strfry_submission] should be checked the same way.

Out of scope

  • Deploying/converging, DNS changes, certificate issuance, ZeroTier changes.
  • The nuc staging relay and the moderator worker (WS2; not Kosmos infra). The member bridge is covered here (kosmos_strfry::member_bridge).
  • The write policies themselves (WS1, kosmos/akkounts).