summaryrefslogtreecommitdiffstats
path: root/internal/auth/README.md
diff options
context:
space:
mode:
authorbndw <ben@bdw.to>2026-02-14 10:11:16 -0800
committerbndw <ben@bdw.to>2026-02-14 10:11:16 -0800
commit606e0a3329a3534a00889eee19c25e7d432f7d2d (patch)
tree526b1419eaa6b9b91126adbfa5990ec47f5d3a07 /internal/auth/README.md
parenta90009e6b887a8a7ca67f49566af2caffb807776 (diff)
refactor: restructure auth config for better UX
Changed from flat structure to hierarchical read/write config: Before: auth: enabled: bool required: bool allowed_npubs_read: [] allowed_npubs_write: [] After: auth: read: enabled: bool allowed_npubs: [] write: enabled: bool allowed_npubs: [] Three states per operation: - enabled=false: no auth, allow all - enabled=true, allowed_npubs=[]: auth required, any valid signature - enabled=true, allowed_npubs=[...]: auth required, whitelist only Much clearer semantics and easier to reason about.
Diffstat (limited to 'internal/auth/README.md')
-rw-r--r--internal/auth/README.md37
1 files changed, 23 insertions, 14 deletions
diff --git a/internal/auth/README.md b/internal/auth/README.md
index 366e110..de37010 100644
--- a/internal/auth/README.md
+++ b/internal/auth/README.md
@@ -142,8 +142,15 @@ import (
142 142
143// Create auth options 143// Create auth options
144authOpts := &auth.InterceptorOptions{ 144authOpts := &auth.InterceptorOptions{
145 Read: auth.OperationAuthConfig{
146 Enabled: true, // Require auth for reads
147 AllowedNpubs: nil, // Accept any valid signature
148 },
149 Write: auth.OperationAuthConfig{
150 Enabled: true,
151 AllowedNpubs: []string{"hex-pubkey-1", "hex-pubkey-2"}, // Whitelist
152 },
145 TimestampWindow: 60, // Accept events within 60 seconds 153 TimestampWindow: 60, // Accept events within 60 seconds
146 Required: true, // Reject unauthenticated requests
147} 154}
148 155
149// Create gRPC server with interceptors 156// Create gRPC server with interceptors
@@ -206,23 +213,25 @@ authOpts := &auth.InterceptorOptions{
206 213
207### InterceptorOptions 214### InterceptorOptions
208 215
216- **`Read`**: Authentication config for read operations (Subscribe, QueryEvents, CountEvents)
217 - **`Enabled`**: false = no auth (allow all), true = auth required
218 - **`AllowedNpubs`**: Optional whitelist (hex format, normalized from npub in config)
219 - If `Enabled=false`: no auth required
220 - If `Enabled=true && AllowedNpubs=[]`: auth required, any valid signature accepted
221 - If `Enabled=true && AllowedNpubs=[...]`: auth required, only whitelisted npubs accepted
222
223- **`Write`**: Authentication config for write operations (PublishEvent, PublishBatch)
224 - Same structure as `Read`
225
209- **`TimestampWindow`**: Maximum age of events in seconds (default: 60) 226- **`TimestampWindow`**: Maximum age of events in seconds (default: 60)
210- **`Required`**: Whether to reject unauthenticated requests (default: false)
211- **`ValidatePayload`**: Whether to verify payload hash when present (default: false) 227- **`ValidatePayload`**: Whether to verify payload hash when present (default: false)
212- **`AllowedNpubsRead`**: Optional whitelist of allowed pubkeys for read operations (nil = allow all) 228- **`SkipMethods`**: List of methods that bypass auth (e.g., health checks)
213 - Config accepts npub format only (human-readable bech32)
214 - Automatically normalized to hex format (computer-readable) at config load time
215 - Controls access to Query, Get, List, Subscribe, and other read methods
216- **`AllowedNpubsWrite`**: Optional whitelist of allowed pubkeys for write operations (nil = allow all)
217 - Config accepts npub format only (human-readable bech32)
218 - Automatically normalized to hex format (computer-readable) at config load time
219 - Controls access to Publish, Delete, Create, Update, and other write methods
220 229
221**Access Control Patterns:** 230**Access Control Patterns:**
222- **Public relay**: Set `AllowedNpubsWrite` (only some can publish), leave `AllowedNpubsRead` empty (everyone can read) 231- **Public relay**: `Read.Enabled=false`, `Write.Enabled=true` with whitelist
223- **Private relay**: Set both lists (restricted read and write access) 232- **Private relay**: Both `Enabled=true` with whitelists
224- **Open relay**: Leave both empty (everyone can read and write) 233- **Open relay**: Both `Enabled=false`
225- **Read-only relay**: Set `AllowedNpubsRead`, block all writes 234- **Authenticated reads, open writes**: `Read.Enabled=true`, `Write.Enabled=false`
226 235
227### NostrCredentials Options 236### NostrCredentials Options
228 237