summaryrefslogtreecommitdiffstats
path: root/internal/auth
diff options
context:
space:
mode:
Diffstat (limited to 'internal/auth')
-rw-r--r--internal/auth/README.md4
-rw-r--r--internal/auth/auth_test.go4
-rw-r--r--internal/auth/interceptor.go15
3 files changed, 10 insertions, 13 deletions
diff --git a/internal/auth/README.md b/internal/auth/README.md
index de37010..98d1437 100644
--- a/internal/auth/README.md
+++ b/internal/auth/README.md
@@ -142,11 +142,11 @@ import (
142 142
143// Create auth options 143// Create auth options
144authOpts := &auth.InterceptorOptions{ 144authOpts := &auth.InterceptorOptions{
145 Read: auth.OperationAuthConfig{ 145 Read: auth.AuthOperationConfig{
146 Enabled: true, // Require auth for reads 146 Enabled: true, // Require auth for reads
147 AllowedNpubs: nil, // Accept any valid signature 147 AllowedNpubs: nil, // Accept any valid signature
148 }, 148 },
149 Write: auth.OperationAuthConfig{ 149 Write: auth.AuthOperationConfig{
150 Enabled: true, 150 Enabled: true,
151 AllowedNpubs: []string{"hex-pubkey-1", "hex-pubkey-2"}, // Whitelist 151 AllowedNpubs: []string{"hex-pubkey-1", "hex-pubkey-2"}, // Whitelist
152 }, 152 },
diff --git a/internal/auth/auth_test.go b/internal/auth/auth_test.go
index 7b0fa13..68c68f5 100644
--- a/internal/auth/auth_test.go
+++ b/internal/auth/auth_test.go
@@ -243,11 +243,11 @@ func TestValidateAuthFromContext(t *testing.T) {
243 ctx := metadata.NewIncomingContext(context.Background(), md) 243 ctx := metadata.NewIncomingContext(context.Background(), md)
244 244
245 opts := &InterceptorOptions{ 245 opts := &InterceptorOptions{
246 Read: OperationAuthConfig{ 246 Read: AuthOperationConfig{
247 Enabled: true, 247 Enabled: true,
248 AllowedNpubs: nil, 248 AllowedNpubs: nil,
249 }, 249 },
250 Write: OperationAuthConfig{ 250 Write: AuthOperationConfig{
251 Enabled: true, 251 Enabled: true,
252 AllowedNpubs: nil, 252 AllowedNpubs: nil,
253 }, 253 },
diff --git a/internal/auth/interceptor.go b/internal/auth/interceptor.go
index 42c2688..67450ce 100644
--- a/internal/auth/interceptor.go
+++ b/internal/auth/interceptor.go
@@ -18,28 +18,25 @@ const (
18) 18)
19 19
20type InterceptorOptions struct { 20type InterceptorOptions struct {
21 Read OperationAuthConfig 21 Read AuthOperationConfig
22 Write OperationAuthConfig 22 Write AuthOperationConfig
23 TimestampWindow int64 23 TimestampWindow int64
24 ValidatePayload bool 24 ValidatePayload bool
25 SkipMethods []string 25 SkipMethods []string
26} 26}
27 27
28// OperationAuthConfig configures auth for read or write operations. 28type AuthOperationConfig struct {
29// Three states: disabled (allow all), enabled with empty list (require auth),
30// enabled with npubs (whitelist only). Npubs normalized to hex at load time.
31type OperationAuthConfig struct {
32 Enabled bool 29 Enabled bool
33 AllowedNpubs []string 30 AllowedNpubs []string
34} 31}
35 32
36func DefaultInterceptorOptions() *InterceptorOptions { 33func DefaultInterceptorOptions() *InterceptorOptions {
37 return &InterceptorOptions{ 34 return &InterceptorOptions{
38 Read: OperationAuthConfig{ 35 Read: AuthOperationConfig{
39 Enabled: false, 36 Enabled: false,
40 AllowedNpubs: nil, 37 AllowedNpubs: nil,
41 }, 38 },
42 Write: OperationAuthConfig{ 39 Write: AuthOperationConfig{
43 Enabled: false, 40 Enabled: false,
44 AllowedNpubs: nil, 41 AllowedNpubs: nil,
45 }, 42 },
@@ -154,7 +151,7 @@ func validateAuthFromContext(ctx context.Context, method string, opts *Intercept
154 151
155 pubkey := ExtractPubkey(event) 152 pubkey := ExtractPubkey(event)
156 153
157 var opConfig OperationAuthConfig 154 var opConfig AuthOperationConfig
158 if isWriteMethod(method) { 155 if isWriteMethod(method) {
159 opConfig = opts.Write 156 opConfig = opts.Write
160 } else { 157 } else {