Fix strfry README and drop deployment specifics
CI / Test (pull_request) Successful in 43s
Release Drafter / Update release notes draft (pull_request) Successful in 3s

The new README described the directory as mostly Node ESM and called the
pre-existing Deno policies "legacy", even though ldap-policy.ts is a shared
module reused by the new member bridge and strfry-policy.ts is the members
relay's current write policy. It also baked in internal deployment details
(Chef, strfry-1, /etc/*.conf paths, the staging relay's ZeroTier IP).

Document every file with its correct runtime (Deno vs Node 24 LTS), drop the
"legacy" label, and genericize the deployment examples. Cross-link the README
from docs/dev/nostr.md, and replace the remaining internal host/IP references
in sync-policy.mjs and its test with neutral placeholders.
This commit is contained in:
raucao committed 2026-11-18 13:51:48 +04:00
1 parent 30ca91797e
commit 023f5b39bf
4 files changed
+68 -38

No files matched your search

+6
View File
@@ -7,6 +7,12 @@ akkounts, so that notes published to the relay have to be authored by (or in
some cases just related to) local users who have verified their Nostr public
key.
It holds both Deno policies (the members relay's write policy, the member
bridge, and the manual sync tool — described below) and plain Node ESM policies
for the public submission relay and the approved-content sync. See
`extras/strfry/README.md` for details on the policies and their environment
variables.
### Requirements
[Deno](https://deno.com/) needs to be installed on the machine that you run
+60 -36
View File
@@ -1,15 +1,24 @@
# strfry policies
Write-policy plugins for [strfry][strfry] relays. Most are plain Node ESM
(`.mjs`, Node 22 LTS); the member-bridge policy (`ldap-only-policy.ts`) is a
Deno script. They are fetched by Chef from this directory into `/opt/strfry` on
the relay hosts.
Policy plugins for the Kosmos [strfry][strfry] relays. There are two runtimes in
this directory:
The legacy Deno policies (`strfry-policy.ts`, `ldap-policy.ts`,
`strfry-sync.ts`) are still deployed for `nostr.kosmos.org` and power that
relay's own write policy plus its historical member sync. `ldap-only-policy.ts`
(below) reuses their `ldap-policy.ts` module. See `docs/dev/nostr.md` for the
legacy ones.
- **Deno** — the members relay's write policy and member bridge, plus the manual
member-note sync. Dependencies are pinned in `deno.json`/`deno.lock`. See
`docs/dev/nostr.md` for the Deno setup.
- `strfry-policy.ts` — the relay's own write policy.
- `ldap-only-policy.ts` — the member bridge's `pluginDown`.
- `ldap-policy.ts` — shared LDAP membership module used by both of the above.
- `strfry-sync.ts` — manual member-note sync tool.
- **Node** (plain ESM `.mjs`, Node 24 LTS, no dependencies) — the submission
relay and the approved-content sync.
- `submission-policy.mjs`
- `sync-policy.mjs`
In development the whole directory is mounted at `/opt/strfry` (see the
`strfry` service in `docker-compose.yml`, and `docker/strfry/strfry.conf` for
the write-policy wiring); in production the ops tooling deploys it to the relay
hosts.
## How strfry invokes a policy
@@ -35,9 +44,8 @@ go to **stderr** and end up in the strfry log.
## `submission-policy.mjs`
Write policy for the **public submission relay** (`submit.nostr.kosmos.org`).
Open to all authors — there is **no LDAP/membership check**. It applies only the
"usual gates":
Write policy for the **public submission relay**. Open to all authors — there is
**no LDAP/membership check**. It applies only the "usual gates":
1. `type` must be `new`.
2. Event must be well-formed (`pubkey`, integer `kind`, `tags` array).
@@ -69,7 +77,7 @@ on file mtime change or config change).
| `SUBMISSION_DEDUPE_WINDOW_MS` | `60000` | Dedupe window. |
| `SUBMISSION_DEDUPE_MIN_LENGTH` | `50` | Minimum content length that is deduped. |
### Chef / strfry configuration
### strfry configuration
```ini
relay {
@@ -81,8 +89,8 @@ relay {
## `sync-policy.mjs`
Write policy for the **approved-content sync** config on strfry-1
(`/etc/strfry-sync.conf`, same LMDB database as the production relay). It is
Write policy for the **approved-content sync** on the members relay. It runs
under a separate strfry config that shares the relay's database, and it is
**fail-closed** and does **source verification only**; all content gating
(kinds, sizes, rates, …) is handled by the other policies. An event is accepted
only when *all* of the following hold:
@@ -99,11 +107,9 @@ policy rejects every event.
| Variable | Default | Description |
| --- | --- | --- |
| `STAGING_RELAY_URL` | _(unset)_ | Expected `sourceInfo` for synced events, e.g. `ws://10.1.1.183:7779`. Unset/empty rejects everything. Whitespace around the configured value is trimmed; `sourceInfo` is compared as-is. |
| `STAGING_RELAY_URL` | _(unset)_ | Expected `sourceInfo` for synced events, e.g. `ws://staging-relay:7779`. Unset/empty rejects everything. Whitespace around the configured value is trimmed; `sourceInfo` is compared as-is. |
### Chef / strfry configuration
`/etc/strfry-sync.conf`:
### strfry configuration
```ini
relay {
@@ -113,44 +119,62 @@ relay {
}
```
The matching sync is driven by `strfry --config /etc/strfry-sync.conf sync
ws://<nuc-zt-ip>:7779 --dir down`, which sets `sourceType=Sync` and
The matching sync is driven by `strfry --config <sync-config> sync
ws://<staging-relay>:7779 --dir down`, which sets `sourceType=Sync` and
`sourceInfo` to the relay URL passed on the command line. `STAGING_RELAY_URL`
must be that exact URL.
## `strfry-policy.ts`
Deno write policy for the members relay itself. It combines the hellthread cap,
anti-duplication (via Deno KV with a 60s window), and the shared `LdapPolicy`
membership check, but lets NIP-46 (kind `24133`) ephemeral events through from
anyone. See `docs/dev/nostr.md` for the Deno requirements and configuration.
## `ldap-only-policy.ts`
Deno write policy for the production relay's **member bridge** — a `strfry
router` stream group (`dir = "down"`) that subscribes to the local submission
relay (`ws://localhost:7778`) and writes member-authored events into the
production database. It is this stream group's `pluginDown`, and it accepts an
event **only** when its author is an LDAP member (or a whitelisted pubkey).
Deno write policy for the members relay's **member bridge** — a `strfry router`
stream group (`dir = "down"`) that subscribes to the local submission relay and
writes member-authored events into the members relay's database. It is this
stream group's `pluginDown`, and it accepts an event **only** when its author is
an LDAP member (or a whitelisted pubkey).
It reuses `ldap-policy.ts` and the shared `/opt/strfry/.env` (the same read-only
LDAP service account as `strfry-policy.ts`), but deliberately does **no**
It reuses `ldap-policy.ts` and the shared `.env` (the same read-only LDAP
service account as `strfry-policy.ts`), but deliberately does **no**
hellthread/anti-duplication work and opens **no** Deno KV store — so it can run
alongside the relay's own policy process without shared state.
### Chef / strfry configuration
`/etc/strfry-member-bridge.conf`:
### strfry configuration
```ini
streams {
members {
dir = "down"
filter = { "kinds": [0, 3, 5, 360, 30360] }
urls = [ "ws://localhost:7778" ]
urls = [ "ws://<submission-relay>:7778" ]
pluginDown = "/opt/strfry/ldap-only-policy.ts"
}
}
```
driven by `strfry router /etc/strfry-member-bridge.conf`. `dir = "down"` keeps
it strictly one-way (the router never watches or forwards the local DB). The
driven by `strfry router <member-bridge-config>`. `dir = "down"` keeps it
strictly one-way (the router never watches or forwards the local DB). The
`filter` bounds the LDAP lookups to the submission kinds; membership is decided
per event by the policy, so no member list is maintained.
## `ldap-policy.ts`
Shared Deno module exporting `LdapConfig` and the `LdapPolicy` class: it looks
up the event author's `nostrKey` in LDAP (with a pubkey whitelist and special
handling for zap receipts) and rejects non-members. Imported by both
`strfry-policy.ts` and `ldap-only-policy.ts`.
## `strfry-sync.ts`
Deno script for one-off/manual syncs of all notes authored by local users (any
account that has verified its Nostr pubkey with akkounts) from a remote relay via
negentropy sync. See the "Manual tasks" section in `docs/dev/nostr.md`.
## Tests
Unit tests use the built-in `node:test` runner (no dependencies):
@@ -167,8 +191,8 @@ printf '%s\n' \
| ./submission-policy.mjs
printf '%s\n' \
'{"type":"new","sourceType":"Sync","sourceInfo":"ws://10.1.1.183:7779","event":{"id":"a","pubkey":"b","kind":360,"tags":[],"content":"hi"}}' \
| STAGING_RELAY_URL='ws://10.1.1.183:7779' ./sync-policy.mjs
'{"type":"new","sourceType":"Sync","sourceInfo":"ws://staging-relay:7779","event":{"id":"a","pubkey":"b","kind":360,"tags":[],"content":"hi"}}' \
| STAGING_RELAY_URL='ws://staging-relay:7779' ./sync-policy.mjs
```
[strfry]: https://github.com/hoytech/strfry
+1 -1
View File
@@ -1,5 +1,5 @@
#!/usr/bin/env node
// Fail-closed strfry write policy for the strfry-1 approved-content sync.
// Fail-closed strfry write policy for the members relay's approved-content sync.
//
// This policy only accepts events that arrived through `strfry sync` from the
// dedicated staging relay. Everything else is rejected, including events with
+1 -1
View File
@@ -4,7 +4,7 @@ import { Readable, Writable } from 'node:stream';
import { createState, decide, run } from '../sync-policy.mjs';
const STAGING = 'ws://10.1.1.183:7779';
const STAGING = 'ws://staging-relay:7779';
function syncMsg(overrides = {}) {
const { event: eventOverrides, ...rest } = overrides;