Repository navigation
feat(api): enforce RBAC with admin-only rule management - #69
Merged
Merged
Conversation
Define subprotocol bearer auth, at-least-once delivery with stable envelope ids, no-replay semantics, and server close codes. Refs #5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xzt3HRqVzoHnEyEUbTT3h9
- realtime.Relay polls unpublished outbox rows oldest-first, publishes them to the hub, then marks published_at (at-least-once), backing off on consecutive failures. - realtime.Hub fans out without blocking; clients that fall behind are dropped with 1013. - GET /ws verifies the access token offered as the bearer.<token> subprotocol before upgrading, clears the server's connection deadlines, pings, and closes with 1008 when the token expires and 1001 on shutdown. - statusRecorder implements Unwrap so handlers behind AccessLog can hijack. - OUTBOX_POLL_INTERVAL config (default 500ms). Refs #5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xzt3HRqVzoHnEyEUbTT3h9
useRealtimeEvents keeps one socket open while signed in, dedupes on envelope id, invalidates the transactions/alerts query keys, refetches on every (re)connect, reconnects with capped jittered backoff, and logs out on 1008. The shell shows an accessible connection status. Refs #5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xzt3HRqVzoHnEyEUbTT3h9
Refs #5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xzt3HRqVzoHnEyEUbTT3h9
GET /rules for any authenticated role; PATCH /rules/{id} with a strict
{"enabled": boolean} body, 403 for non-admins.
Refs #68
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xzt3HRqVzoHnEyEUbTT3h9
- rules/httpapi: GET /rules and PATCH /rules/{id}, the latter behind
auth.RequireRole(auth.RoleAdmin) on the route itself.
- Strict body parsing: 1 KiB cap, unknown fields and trailing data
rejected, enabled required.
- Each change logs rule_id, enabled and the acting user_id (no email).
- sqlc ListRules / SetRuleEnabled; store maps unknown or malformed ids
to rules.ErrNotFound.
- CORS preflight allows PATCH.
Refs #68
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xzt3HRqVzoHnEyEUbTT3h9
Refs #68 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xzt3HRqVzoHnEyEUbTT3h9
This was referenced Oct 8, 2026
…gement Resolve conflicts with the outbox relay and WebSocket hub (#65): - cmd/api/main.go: keep both the realtime and rule HTTP imports; drop the now-unused rules import since appServices holds *rulestore.Store. - docs: keep the realtime DoS mitigations and the /ws section from #65 and the RBAC rows from this branch; neither streaming nor RBAC is listed as out of scope any more. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013Yguxp4QdXefV36UWrij2T
vianbas
pushed a commit
that referenced
this pull request
Nov 19, 2026
Resolve the threat-model conflict with RBAC (#69): keep the per-user WebSocket cap in the denial-of-service row and the server-side role check in the elevation-of-privilege row. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013Yguxp4QdXefV36UWrij2T
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
auth.RequireRoleexisted but was not mounted on any route, because there was no admin-only operation to protect. This PR adds the first admin surface, rule management, and enforces the role server-side:GET /rulesis open to any authenticated role.PATCH /rules/{id}sets{"enabled": boolean}and is admin only. Operators get403 FORBIDDEN.Closes #68
Architecture summary
contracts/openapi.yaml0.1.0 → 0.2.0): adds therulestag,GET /rulesandPATCH /rules/{id}, theRule,RuleListandRuleUpdateschemas (additionalProperties: false) and theRuleIdparameter. It reuses the existingUnauthorized,ForbiddenandNotFoundresponses.internal/rules/httpapi(new):RegisterRoutesmountsr.With(auth.RequireRole(auth.RoleAdmin)).Patch("/rules/{id}", …).RequireRolereturns 403.RequireAuth.MaxBytesReader.DisallowUnknownFieldsis on,enabledis required (*bool, sonullis rejected), and anything after the JSON object is rejected.400 INVALID_BODY.ListRulesandSetRuleEnabled … RETURNING. Unknown or malformed ids map torules.ErrNotFound, which the handler returns as 404.rules.RulegainsCreatedAt.alerts.Servicealready reloads the enabled rules on every ingest, so a toggle applies to the next transaction. Existing alerts are untouched.PATCH; before this change the browser would have blocked the call.container-design.md,system-context.md,CLAUDE.mdand.claude/rules/security.mdno longer say thatRequireRoleis unmounted.Security considerations
adminbut is signed with another key gets 401, and there is a test for this.rule_id,enabledand the actinguser_id, an opaque synthetic UUID. Emails and tokens are never logged, and a test asserts it.Testing evidence
httpserver.NewRouterwith the realauth.RequireAuthand real JWTs:user_idand no email or token.ListEnabled.ErrNotFound.GET /rulesas operator returned 200 with 3 rules.PATCHreturned 403 as operator, 401 without a token, and 200 as admin.Access-Control-Allow-Methods: GET, POST, PATCH.gbp-currencydisabled, seeding 60 transactions (13 in GBP) raised 0 newgbp-currencyalerts (6 → 6). Re-enabling returned 200.Known limitations
cmd/api/main.go,middleware.goand the docs. Whichever merges second needs a small conflict resolution, which I will handle.Follow-up issues
Checklist
main; this PR targetsmain.make verifypasses locally.git diff --checkis clean.