docs: Azzamo free/premium example configs and deploy checklist
Phase 9 of PLAN.md. - noteguard-free.example.toml: everyone writes; blacklist, content and ratelimit use the Azzamo sources; premium exempt from rate limit and IP bans. - noteguard-premium.example.toml: whitelist gate on the premium source (fails closed when no list or cache), blacklists, 60/min runaway guard with no exemption and no bans. - DEPLOY.md: build, host prep (env, cache dir), smoke test, install, rollout order, rollback, operational notes. - README: Sources section (keys, loading model, accepted bodies) and an Azzamo deployments section. - Tests load both examples and the repo noteguard.toml with sources declared but not fetched, and check the gate fails closed. API URLs are placeholders (CHANGEME) until the endpoints are confirmed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
70a69aa114
commit
f63e2d9087
@@ -0,0 +1,122 @@
|
||||
# Deploying Azzamo Noteguard
|
||||
|
||||
One binary, two configs:
|
||||
|
||||
| Relay | Config |
|
||||
|---|---|
|
||||
| nostr.azzamo.net (free) | [noteguard-free.example.toml](noteguard-free.example.toml) |
|
||||
| relay, us, asia (premium) | [noteguard-premium.example.toml](noteguard-premium.example.toml) |
|
||||
|
||||
## 1. Build
|
||||
|
||||
Rust 1.88 or newer is required for the `remote` and `cloudflare` features.
|
||||
|
||||
```sh
|
||||
cargo build --release --features remote,cloudflare
|
||||
cargo test --features remote,cloudflare
|
||||
```
|
||||
|
||||
For a static binary, build for `x86_64-unknown-linux-musl` with the same
|
||||
features. rustls pulls in `ring`, which needs a musl C toolchain
|
||||
(`musl-tools` on Debian) on the build host.
|
||||
|
||||
## 2. Prepare each relay host
|
||||
|
||||
- [ ] Fill in the real API URLs in the config (replace every `CHANGEME`).
|
||||
- [ ] Copy the config to e.g. `/etc/noteguard/free.toml` or `/etc/noteguard/premium.toml`.
|
||||
- [ ] Create the cache directory, writable by the user strfry runs as:
|
||||
`install -d -o strfry -g strfry /var/lib/noteguard`
|
||||
(or `StateDirectory=noteguard` in the systemd unit).
|
||||
- [ ] Give strfry the environment. noteguard inherits strfry's environment, so
|
||||
set it on the strfry service, for example in a systemd drop-in:
|
||||
|
||||
```ini
|
||||
[Service]
|
||||
Environment=NOTEGUARD_CONFIG=/etc/noteguard/premium.toml
|
||||
Environment=RUST_LOG=info
|
||||
EnvironmentFile=/etc/noteguard/secrets.env
|
||||
```
|
||||
|
||||
with `/etc/noteguard/secrets.env` (mode 600) holding
|
||||
`AZZAMO_API_TOKEN=...` and, if Cloudflare edge bans are used,
|
||||
`CLOUDFLARE_API_TOKEN=...`. Then `systemctl daemon-reload`.
|
||||
|
||||
## 3. Smoke test on the host, before switching strfry over
|
||||
|
||||
```sh
|
||||
sudo -u strfry env NOTEGUARD_CONFIG=/etc/noteguard/premium.toml RUST_LOG=info \
|
||||
AZZAMO_API_TOKEN=... ./noteguard.new < test/inputs
|
||||
```
|
||||
|
||||
Check the log lines on stderr:
|
||||
|
||||
- `source premium: loaded N entries (M skipped)` for every source. A large `M`
|
||||
means the API shape does not match what noteguard expects.
|
||||
- No `token_env $AZZAMO_API_TOKEN is not set`.
|
||||
- No `fetch failed ... no usable cache`.
|
||||
|
||||
Then check the cache files exist in `/var/lib/noteguard/`.
|
||||
|
||||
Expected verdicts: on the premium config, a note from a non-member is
|
||||
rejected with the `whitelist.message`; on the free config it is accepted.
|
||||
|
||||
## 4. Install
|
||||
|
||||
```sh
|
||||
cp /path/strfry/noteguard /path/strfry/noteguard.prev
|
||||
cp /etc/noteguard/premium.toml /etc/noteguard/premium.toml.prev # if one existed
|
||||
install -m755 noteguard.new /path/strfry/noteguard.tmp
|
||||
mv /path/strfry/noteguard.tmp /path/strfry/noteguard
|
||||
```
|
||||
|
||||
Always replace the binary with `mv` (an atomic rename), never `cp` over the
|
||||
running file. strfry relaunches the write plugin when the plugin file changes;
|
||||
if in doubt, restart strfry. noteguard reads its config only at startup, so
|
||||
after a config-only change `touch` the binary or restart strfry.
|
||||
|
||||
Point strfry at it (`strfry.conf`):
|
||||
|
||||
```
|
||||
writePolicy {
|
||||
plugin = "/path/strfry/noteguard"
|
||||
}
|
||||
```
|
||||
|
||||
## 5. Rollout order
|
||||
|
||||
1. Free relay first. Watch the log for one reload interval (5 minutes): every
|
||||
source should reload cleanly, and premium members should not be rate limited.
|
||||
2. One premium relay (asia). Post as a member (accepted) and as a non-member
|
||||
(rejected). Watch for one reload interval.
|
||||
3. The remaining premium relays (us, then relay).
|
||||
|
||||
## 6. Rollback
|
||||
|
||||
On the affected relay:
|
||||
|
||||
```sh
|
||||
mv /path/strfry/noteguard.prev /path/strfry/noteguard
|
||||
mv /etc/noteguard/premium.toml.prev /etc/noteguard/premium.toml # if the config changed
|
||||
```
|
||||
|
||||
Then make sure strfry picked it up: restart strfry, or `touch` the binary if
|
||||
only the config changed. The cache files in `/var/lib/noteguard/` can stay;
|
||||
older binaries ignore them.
|
||||
|
||||
Every new config key is optional, so the previous config also runs on the new
|
||||
binary: rolling back the config alone turns the new behavior off.
|
||||
|
||||
## Operational notes
|
||||
|
||||
- If the API is down, each relay keeps its last good lists. Member expiries
|
||||
still apply to that stale copy, but new payments and revocations wait until
|
||||
the API is back.
|
||||
- A premium relay that starts with no list and no cache rejects every
|
||||
non-whitelisted writer with `whitelist.unavailable_message` until the first
|
||||
successful fetch. Keep `cache_path` set to avoid this.
|
||||
- API load is roughly (relays x strfry ingester threads x sources) requests
|
||||
every `reload_secs`.
|
||||
- Zap receipts (kind 9735) and NIP-17 gift wraps (kind 1059) addressed to
|
||||
members are signed by non-member keys, so premium relays reject them.
|
||||
- Events arriving through strfry router or sync pass through the same
|
||||
filters, so an expired member's notes stop syncing into premium relays.
|
||||
@@ -74,6 +74,21 @@ writePolicy {
|
||||
|
||||
And you're done! Enjoy.
|
||||
|
||||
### Azzamo deployments
|
||||
|
||||
Ready-to-edit configs for the Azzamo relays, both served by the same binary:
|
||||
|
||||
- [noteguard-free.example.toml](noteguard-free.example.toml): everyone can write, rate limited per IP, premium members exempt, Azzamo blacklists applied.
|
||||
- [noteguard-premium.example.toml](noteguard-premium.example.toml): only active premium members can write, Azzamo blacklists applied.
|
||||
|
||||
They fetch their lists over https, so build with the `remote` feature (Rust 1.88 or newer):
|
||||
|
||||
```sh
|
||||
$ cargo build --release --features remote,cloudflare
|
||||
```
|
||||
|
||||
[DEPLOY.md](DEPLOY.md) is the step-by-step checklist for rolling them out and rolling back.
|
||||
|
||||
## Filters
|
||||
|
||||
You can use any of the builtin filters, or create your own!
|
||||
@@ -99,6 +114,44 @@ existing configs behave exactly as before.
|
||||
`content` has no message: it shadow-rejects, and strfry tells the client the
|
||||
note was accepted, so no text is ever sent.
|
||||
|
||||
### Sources
|
||||
|
||||
A source is a named list fetched from an API or a file, kept fresh in the
|
||||
background, and used by filters by name. Declare each one once at the top
|
||||
level of the config:
|
||||
|
||||
```toml
|
||||
[sources.premium]
|
||||
url = "https://api.example.com/premium" # https://, http://, file:///path or a plain path
|
||||
format = "pubkeys" # "pubkeys" or "words"
|
||||
token_env = "AZZAMO_API_TOKEN" # optional: env var holding a bearer token
|
||||
reload_secs = 300 # optional: default 300, minimum 30
|
||||
timeout_secs = 10 # optional: per-request timeout, default 10
|
||||
max_bytes = 10485760 # optional: larger bodies are rejected, default 10 MiB
|
||||
cache_path = "/var/lib/noteguard/premium.json" # optional: last good copy for restarts
|
||||
```
|
||||
|
||||
Then refer to it from a filter: `blacklist.pubkeys_source`, `ratelimit.exempt_source`,
|
||||
`content.words_source`, `content.exempt_source` and `whitelist.pubkey_sources`.
|
||||
A name that is not declared, or a list of the wrong format, stops noteguard at
|
||||
startup with an error.
|
||||
|
||||
How loading works:
|
||||
|
||||
- Every source is loaded once at startup, before the first note. If that fails, the `cache_path` copy is used. If there is no cache either, the list counts as unavailable until a reload succeeds (only `whitelist` treats that specially, see `unavailable`).
|
||||
- A background thread reloads each source every `reload_secs`. A failed fetch, a non-2xx response, an oversized or unparseable body all keep the last good copy, and the failure is logged with the copy's age.
|
||||
- No network call ever happens while a note is being filtered.
|
||||
- strfry runs one noteguard process per ingester thread, and each fetches its own copy.
|
||||
|
||||
Accepted bodies (unknown fields are ignored; unusable entries are skipped and
|
||||
counted in the log):
|
||||
|
||||
- `format = "pubkeys"`: a JSON array, or `{"pubkeys": [...]}`, whose items are either a hex pubkey string or `{"pubkey": "<hex>", "expires_at": <unix seconds or null>}`. Keys are lowercased; npub and malformed keys are skipped. An entry stops counting once `expires_at` passes, even if the API is down and the list is stale. A key listed twice keeps the latest expiry.
|
||||
- `format = "words"`: a JSON array of strings, or `{"words": [...]}`.
|
||||
|
||||
HTTP sources need a build with `--features remote`; a config with an http(s)
|
||||
source in a build without it stops at startup with an error.
|
||||
|
||||
### Ratelimit
|
||||
|
||||
* name: `ratelimit`
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
# Azzamo FREE relay (nostr.azzamo.net)
|
||||
#
|
||||
# Everyone can write. Notes are rate limited per IP, premium members are
|
||||
# exempt from the rate limit and from IP bans, and everyone is checked
|
||||
# against the Azzamo pubkey and word blacklists.
|
||||
#
|
||||
# Build: cargo build --release --features remote,cloudflare
|
||||
# Run: NOTEGUARD_CONFIG=/etc/noteguard/free.toml (see DEPLOY.md)
|
||||
#
|
||||
# The source URLs below are placeholders until the Azzamo API endpoints and
|
||||
# response shapes are confirmed. Accepted shapes are documented in the README
|
||||
# (section "Sources").
|
||||
|
||||
pipeline = ["protected_events", "kinds", "blacklist", "content", "ratelimit"]
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Remote lists. Each is fetched at startup, then every reload_secs in the
|
||||
# background; a failed fetch keeps the last good copy, and cache_path lets a
|
||||
# restart during an API outage come back with the last good list.
|
||||
# The token is read from the AZZAMO_API_TOKEN environment variable.
|
||||
# ---------------------------------------------------------------------------
|
||||
[sources.premium]
|
||||
url = "https://api.azzamo.net/CHANGEME/premium"
|
||||
format = "pubkeys"
|
||||
token_env = "AZZAMO_API_TOKEN"
|
||||
reload_secs = 300
|
||||
timeout_secs = 10
|
||||
cache_path = "/var/lib/noteguard/premium.json"
|
||||
|
||||
[sources.blacklist_pubkeys]
|
||||
url = "https://api.azzamo.net/CHANGEME/blacklist/pubkeys"
|
||||
format = "pubkeys"
|
||||
token_env = "AZZAMO_API_TOKEN"
|
||||
reload_secs = 300
|
||||
timeout_secs = 10
|
||||
cache_path = "/var/lib/noteguard/blacklist_pubkeys.json"
|
||||
|
||||
[sources.blacklist_words]
|
||||
url = "https://api.azzamo.net/CHANGEME/blacklist/words"
|
||||
format = "words"
|
||||
token_env = "AZZAMO_API_TOKEN"
|
||||
reload_secs = 300
|
||||
timeout_secs = 10
|
||||
cache_path = "/var/lib/noteguard/blacklist_words.json"
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Filters, in pipeline order.
|
||||
# ---------------------------------------------------------------------------
|
||||
[filters.protected_events]
|
||||
# message = "blocked: event marked as protected"
|
||||
|
||||
[filters.kinds]
|
||||
kinds = [30065, 1064, 34550, 4550]
|
||||
# message = "blocked: note kind is not allowed here"
|
||||
|
||||
[filters.kinds.messages]
|
||||
30065 = "blocked: files on nostr is dumb"
|
||||
1064 = "blocked: files on nostr is dumb"
|
||||
34550 = "blocked: please use a dedicated relay for moderated communities"
|
||||
4550 = "blocked: please use a dedicated relay for moderated communities"
|
||||
|
||||
# Blacklisted pubkeys (static + Azzamo list) and IPs get a visible reject.
|
||||
[filters.blacklist]
|
||||
pubkeys_source = "blacklist_pubkeys"
|
||||
# pubkeys = []
|
||||
# ips = []
|
||||
# cidrs = []
|
||||
# message = "blocked: pubkey/ip is blacklisted"
|
||||
|
||||
# Blocked words (static + Azzamo list) are silently dropped. Repeat offenders
|
||||
# are IP-banned; premium members skip the ban but are still word-checked.
|
||||
[filters.content]
|
||||
filters = ["Damus Airdrop"]
|
||||
words_source = "blacklist_words"
|
||||
exempt_source = "premium"
|
||||
ban_after = 5
|
||||
ban_duration_secs = 3600
|
||||
|
||||
# Per-IP rate limit. Premium members are exempt.
|
||||
[filters.ratelimit]
|
||||
posts_per_minute = 8
|
||||
whitelist = ["127.0.0.1"]
|
||||
exempt_source = "premium"
|
||||
message = "rate-limited: you note too much"
|
||||
ban_after = 10
|
||||
ban_duration_secs = 3600
|
||||
ban_message = "banned: too many rate-limit violations, try again later"
|
||||
|
||||
# Optional: push IP bans to a Cloudflare WAF list (needs the cloudflare
|
||||
# feature and CLOUDFLARE_API_TOKEN). See the README.
|
||||
# [cloudflare]
|
||||
# account_id = "<cloudflare account id>"
|
||||
# list_id = "<ip list id>"
|
||||
@@ -0,0 +1,85 @@
|
||||
# Azzamo PREMIUM relays (relay, us, asia)
|
||||
#
|
||||
# Only active premium members can write. The member list comes from the
|
||||
# Azzamo API with an expiry per member, and members are still checked against
|
||||
# the Azzamo pubkey and word blacklists.
|
||||
#
|
||||
# Build: cargo build --release --features remote,cloudflare
|
||||
# Run: NOTEGUARD_CONFIG=/etc/noteguard/premium.toml (see DEPLOY.md)
|
||||
#
|
||||
# The source URLs below are placeholders until the Azzamo API endpoints and
|
||||
# response shapes are confirmed. Accepted shapes are documented in the README
|
||||
# (section "Sources").
|
||||
|
||||
# blacklist runs before the gate so a blacklisted member gets the blacklist
|
||||
# message; the gate runs before content so strangers never reach the word
|
||||
# check or count towards IP bans.
|
||||
pipeline = ["protected_events", "kinds", "blacklist", "whitelist", "content", "ratelimit"]
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Remote lists. See noteguard-free.example.toml for how loading works. The
|
||||
# cache matters most here: with no list and no cache the gate rejects
|
||||
# everyone (see `unavailable` below).
|
||||
# ---------------------------------------------------------------------------
|
||||
[sources.premium]
|
||||
url = "https://api.azzamo.net/CHANGEME/premium"
|
||||
format = "pubkeys"
|
||||
token_env = "AZZAMO_API_TOKEN"
|
||||
reload_secs = 300
|
||||
timeout_secs = 10
|
||||
cache_path = "/var/lib/noteguard/premium.json"
|
||||
|
||||
[sources.blacklist_pubkeys]
|
||||
url = "https://api.azzamo.net/CHANGEME/blacklist/pubkeys"
|
||||
format = "pubkeys"
|
||||
token_env = "AZZAMO_API_TOKEN"
|
||||
reload_secs = 300
|
||||
timeout_secs = 10
|
||||
cache_path = "/var/lib/noteguard/blacklist_pubkeys.json"
|
||||
|
||||
[sources.blacklist_words]
|
||||
url = "https://api.azzamo.net/CHANGEME/blacklist/words"
|
||||
format = "words"
|
||||
token_env = "AZZAMO_API_TOKEN"
|
||||
reload_secs = 300
|
||||
timeout_secs = 10
|
||||
cache_path = "/var/lib/noteguard/blacklist_words.json"
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Filters, in pipeline order.
|
||||
# ---------------------------------------------------------------------------
|
||||
[filters.protected_events]
|
||||
|
||||
[filters.kinds]
|
||||
kinds = [30065, 1064, 34550, 4550]
|
||||
|
||||
[filters.kinds.messages]
|
||||
30065 = "blocked: files on nostr is dumb"
|
||||
1064 = "blocked: files on nostr is dumb"
|
||||
34550 = "blocked: please use a dedicated relay for moderated communities"
|
||||
4550 = "blocked: please use a dedicated relay for moderated communities"
|
||||
|
||||
[filters.blacklist]
|
||||
pubkeys_source = "blacklist_pubkeys"
|
||||
|
||||
# The premium gate. Static pubkeys and IPs are allowed too (e.g. localhost for
|
||||
# admin imports). Zap receipts (kind 9735) and NIP-17 gift wraps (kind 1059)
|
||||
# are signed by non-member keys, so they are rejected here like any stranger.
|
||||
[filters.whitelist]
|
||||
pubkey_sources = ["premium"]
|
||||
ips = ["127.0.0.1"]
|
||||
message = "restricted: this relay is for Azzamo premium members"
|
||||
# "reject" (default) fails closed when the premium list has never loaded and
|
||||
# there is no cache; "accept" lets everyone write until it loads.
|
||||
unavailable = "reject"
|
||||
unavailable_message = "restricted: membership list unavailable, try again shortly"
|
||||
|
||||
[filters.content]
|
||||
filters = ["Damus Airdrop"]
|
||||
words_source = "blacklist_words"
|
||||
|
||||
# A guard against runaway clients rather than a quota: everyone here is a
|
||||
# member, so there is no premium exemption and no IP ban.
|
||||
[filters.ratelimit]
|
||||
posts_per_minute = 60
|
||||
whitelist = ["127.0.0.1"]
|
||||
+51
@@ -859,6 +859,57 @@ mod tests {
|
||||
assert!(config.sources.is_empty());
|
||||
}
|
||||
|
||||
/// Load a config file from the repo with every source pointed at a missing
|
||||
/// file, declared but never started: no network, no `remote` feature
|
||||
/// needed, and every list stays "never loaded".
|
||||
fn load_repo_config(path: &str) -> Noteguard {
|
||||
let contents = std::fs::read_to_string(format!("{}/{path}", env!("CARGO_MANIFEST_DIR")))
|
||||
.expect("read config");
|
||||
let mut config: Config = toml::from_str(&contents).expect("Failed to parse config");
|
||||
for source in config.sources.values_mut() {
|
||||
source.url = "/nonexistent/noteguard-example-source".to_string();
|
||||
}
|
||||
noteguard::sources::declare(&config.sources).expect("sources declare");
|
||||
|
||||
let mut noteguard = Noteguard::new();
|
||||
noteguard
|
||||
.load_config(&config)
|
||||
.expect("Failed to load config");
|
||||
noteguard
|
||||
}
|
||||
|
||||
fn plain_note(pubkey: &str) -> InputMessage {
|
||||
let mut msg = create_mock_input_message("example", "new", "1.2.3.4");
|
||||
msg.event.tags.clear();
|
||||
msg.event.pubkey = pubkey.to_string();
|
||||
msg
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn free_example_config_loads() {
|
||||
let mut noteguard = load_repo_config("noteguard-free.example.toml");
|
||||
assert_eq!(noteguard.loaded_filters.len(), 5);
|
||||
// Lists not loaded yet: the free relay still accepts a plain note.
|
||||
assert_eq!(noteguard.run(plain_note("anyone")).action, Action::Accept);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn premium_example_config_loads() {
|
||||
let mut noteguard = load_repo_config("noteguard-premium.example.toml");
|
||||
assert_eq!(noteguard.loaded_filters.len(), 6);
|
||||
// No premium list and no cache: the gate fails closed.
|
||||
assert_reject_msg(
|
||||
noteguard.run(plain_note("anyone")),
|
||||
"restricted: membership list unavailable, try again shortly",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn repo_noteguard_toml_still_loads() {
|
||||
let noteguard = load_repo_config("noteguard.toml");
|
||||
assert_eq!(noteguard.loaded_filters.len(), 5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_deserialize_input_message() {
|
||||
let input_json = r#"
|
||||
|
||||
Reference in New Issue
Block a user