diff options
| author | bndw <ben@bdw.to> | 2026-02-15 10:31:06 -0800 |
|---|---|---|
| committer | bndw <ben@bdw.to> | 2026-02-15 10:31:06 -0800 |
| commit | f658ef072394ff9fd28244ad475859c210e8ec16 (patch) | |
| tree | cc08f5f3e09a1a75dd307a1439f53c5e6a27d0ac /internal/handler/websocket/handler.go | |
| parent | 57bc300fe26812aad568c8119f04d92e94c9ab14 (diff) | |
feat: track authorized (authenticated + successful) requests
Add 'authorized' status for requests that complete successfully after
authentication. This complements the existing 'unauthenticated' (pre-auth)
status tracking.
Now the dashboard shows:
- Authorized: Authenticated requests that succeeded
- Unauthorized: Authenticated requests rejected (not in allowlist)
- Pre-Auth: Requests sent before authentication
This gives full visibility into the auth flow:
1. Challenges: How many clients authenticated
2. Authorized: How many authenticated requests succeeded
3. Unauthorized: How many were rejected despite valid auth
4. Pre-Auth: How many tried before authenticating
Updated metrics:
- requests_total{status="authorized"} - authenticated successes
- requests_total{status="ok"} - unauthenticated successes (when no auth)
Diffstat (limited to 'internal/handler/websocket/handler.go')
| -rw-r--r-- | internal/handler/websocket/handler.go | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/internal/handler/websocket/handler.go b/internal/handler/websocket/handler.go index dfe7b9e..909e2ec 100644 --- a/internal/handler/websocket/handler.go +++ b/internal/handler/websocket/handler.go | |||
| @@ -348,7 +348,12 @@ func (h *Handler) handleEvent(ctx context.Context, conn *websocket.Conn, raw []j | |||
| 348 | 348 | ||
| 349 | h.subs.MatchAndFan(pbEvent) | 349 | h.subs.MatchAndFan(pbEvent) |
| 350 | 350 | ||
| 351 | status = "ok" | 351 | // Track whether request was authenticated for metrics |
| 352 | if state.authenticatedPubkey != "" { | ||
| 353 | status = "authorized" | ||
| 354 | } else { | ||
| 355 | status = "ok" | ||
| 356 | } | ||
| 352 | h.sendOK(ctx, conn, event.ID, true, "") | 357 | h.sendOK(ctx, conn, event.ID, true, "") |
| 353 | return nil | 358 | return nil |
| 354 | } | 359 | } |
| @@ -448,7 +453,12 @@ func (h *Handler) handleReq(ctx context.Context, conn *websocket.Conn, raw []jso | |||
| 448 | 453 | ||
| 449 | go h.streamEvents(ctx, conn, sub) | 454 | go h.streamEvents(ctx, conn, sub) |
| 450 | 455 | ||
| 451 | status = "ok" | 456 | // Track whether request was authenticated for metrics |
| 457 | if state.authenticatedPubkey != "" { | ||
| 458 | status = "authorized" | ||
| 459 | } else { | ||
| 460 | status = "ok" | ||
| 461 | } | ||
| 452 | return nil | 462 | return nil |
| 453 | } | 463 | } |
| 454 | 464 | ||
