diff options
Diffstat (limited to 'internal/auth/README.md')
| -rw-r--r-- | internal/auth/README.md | 37 |
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 |
| 144 | authOpts := &auth.InterceptorOptions{ | 144 | authOpts := &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 | ||
