Skip to content

Conversation

k9ert
Copy link

@k9ert k9ert commented Jul 29, 2025

Problem

The admin panel only have an all or nothing authorisation concept. We need a more sophisticated authorisation.

Solution

On the admin-API, we group all the endpoints to specific access-rights. We have:

  • VIEW_ACCOUNTS
  • VIEW_MERCHANTS
  • LOCK_ACCOUNT
  • APPROVE_MERCHANT
  • CHANGECONTACTS_ACCOUNT
  • CHANGELEVEL_ACCOUNT
  • DELETE_ACCOUNTS
  • VIEW_TRANSACTIONS
  • SEND_NOTIFICATIONS
  • SYSTEM_CONFIG

If a request wants to call any of the endpoints (which need auth), that token need to have the corresponding access-right in its token.scope.

How do we achieve that?

We'll configure a ROLE_USER_MAPPING env var for the admin-panel which maps user to roles. Basic roles are for now:

  • ADMIN : can do everything
  • SUPPORTLV2 : advanced support operations (includes all SUPPORTLV1 + contact changes)
  • SUPPORTLV1 : basic support operations (view accounts/merchants, lock accounts, level_changes, approve merchants)
  • MARKETING : can send notifications only
  • VIEWER: can only view accounts and transactions

One user can have many roles.

The admin-panel then maps those roles to a list of access-rights like this:

Role Hierarchy:

  • VIEWER: VIEW_ACCOUNTS, VIEW_TRANSACTIONS, VIEW_MERCHANTS
  • MARKETING: SEND_NOTIFICATIONS
  • SUPPORTLV1: VIEW_ACCOUNTS, VIEW_TRANSACTIONS, VIEW_MERCHANTS, LOCK_ACCOUNT, APPROVE_MERCHANT,CHANGELEVEL_ACCOUNT
  • SUPPORTLV2: All SUPPORTLV1 rights + CHANGECONTACTS_ACCOUNT,
  • ADMIN: All permissions including DELETE_ACCOUNTS, SYSTEM_CONFIG

Here is a table:

Access Right VIEWER MARKETING SUPPORTLV1 SUPPORTLV2 ADMIN
VIEW_ACCOUNTS
VIEW_TRANSACTIONS
VIEW_MERCHANTS
LOCK_ACCOUNT
APPROVE_MERCHANT
CHANGECONTACTS_ACCOUNT
CHANGELEVEL_ACCOUNT
SEND_NOTIFICATIONS
DELETE_ACCOUNTS
SYSTEM_CONFIG

Legend:

  • ✅ = Permission granted
  • ❌ = Permission denied

This list is then attached to the token.scope (as stringified JSON).

@k9ert k9ert marked this pull request as draft July 29, 2025 16:58
@k9ert k9ert changed the title feat: rbac for the admin-api feat: RBAC for the admin-api Jul 30, 2025
@github-actions github-actions bot added the ci label Jul 30, 2025
@k9ert k9ert requested a review from dolcalmi July 31, 2025 08:32
@k9ert k9ert marked this pull request as ready for review July 31, 2025 08:33
@k9ert k9ert marked this pull request as draft August 6, 2025 19:27
@k9ert k9ert force-pushed the kn/admin_api_rbac branch 2 times, most recently from 568a8ae to 79430bc Compare August 27, 2025 09:51
@k9ert k9ert marked this pull request as ready for review September 1, 2025 11:56
@k9ert k9ert requested a review from dolcalmi September 1, 2025 16:03
openoms
openoms previously approved these changes Sep 3, 2025
Copy link

@openoms openoms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good as discussed.

@k9ert k9ert force-pushed the kn/admin_api_rbac branch 2 times, most recently from 5ce4d40 to d8f13a6 Compare September 8, 2025 11:54
Comment on lines +110 to +115
dev_pnpm_task_test(
name="unit-test",
command="test",
deps = ["//:node_modules"],
)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not much clue about BUCK. It doesn't seem that the admin-panel had unit-tests so far. So i created some and i think we need to add it here to have them tested more or less OOB?!

@k9ert k9ert force-pushed the kn/admin_api_rbac branch 3 times, most recently from 3f99a16 to 569273a Compare September 10, 2025 11:35
@k9ert k9ert force-pushed the kn/admin_api_rbac branch from 422831b to 27c6f66 Compare October 1, 2025 15:00
@k9ert k9ert force-pushed the kn/admin_api_rbac branch from 27c6f66 to 5502141 Compare October 1, 2025 15:04
yarn install
export PORT=3004
yarn dev
pnpm install
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This project is pnpm based since some longer time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants