Skip to content

fix(rbac): role assignment failing (Keycloak lookup) + drop redundant viewer - #12

Merged
dfradehubs merged 1 commit into
mainfrom
fix/rbac-role-update
Jul 24, 2026
Merged

dfradehubs merged 1 commit into
mainfrom
fix/rbac-role-update

Conversation

@dfradehubs

Copy link
Copy Markdown
Owner

Problem

Assigning any non-admin role in Admin → Users (e.g. making someone editor) failed in production with 500 — "could not verify the user's groups in Keycloak, operation blocked for security".

The anti-demotion guard called isAdminByGroup, which queries another user's groups via the Keycloak Admin API; that lookup errors in prod and the handler turns the error into a hard 500, blocking every role change. It only surfaced now because before RBAC the guard ran only when demoting to user; the RBAC change extended it to every non-admin role.

Fix

  • Drop the isAdminByGroup Keycloak lookup from UpdateRole. It's redundant: with ResolveRole, a config-granted admin (admin_groups) always outranks the stored DB role, so changing a group-admin's DB role has no real effect anyway. Keep isProtectedAdmin (bootstrap admins — no Keycloak needed) to block changing their role.
  • Remove the now-dead isAdminByGroup method, the UserGroupsProvider type, and the unused handler fields; simplify the constructor.
  • UI: remove viewer from the role selector — today it's identical to user (no admin-panel access), so showing both confuses. The viewer constant stays in the backend for a future read-only role.

Test plan

  • Dev: PUT /admin/users/{email}/role with editor → 200 (previously 500 in prod); demote to user → 200; role persisted.
  • go build, go vet, go test ./internal/{handlers,service,models,middleware} green; web npm run build compiles.
  • isProtectedAdmin still blocks changing a bootstrap admin's role (403).

Note: not reproducible in the auth-disabled dev stack originally (no Keycloak lookup path), which is why it slipped past — verified the fix by exercising the role update directly.

🤖 Generated with Claude Code

Assigning any non-admin role triggered a Keycloak group lookup
(isAdminByGroup) that fails when querying another user's groups, returning
500 "could not verify the user's groups in Keycloak". The check was also
redundant: with ResolveRole, config-granted admin (admin_groups) always wins
over the stored DB role, so demoting the DB role of a group-admin has no real
effect. Drop the Keycloak lookup entirely; keep isProtectedAdmin (bootstrap
admins, no Keycloak) to block changing their role.

Also remove `viewer` from the Admin → Users role selector: it behaves exactly
like `user` today (no admin-panel access), so offering both only confuses. The
role constant stays in the backend for a future read-only role.
@dfradehubs
dfradehubs merged commit ea21040 into main Jul 24, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant