Skip to content

feat: RBAC for the admin-api#158

Merged
dolcalmi merged 9 commits into
mainfrom
kn/admin_api_rbac
May 15, 2026
Merged

feat: RBAC for the admin-api#158
dolcalmi merged 9 commits into
mainfrom
kn/admin_api_rbac

Conversation

@k9ert
Copy link
Copy Markdown

@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
Comment thread quickstart/dev/Tiltfile
Comment thread dev/core-bundle/serve-env.json Outdated
Comment thread core/api/src/services/auth/role-checker.ts Outdated
Comment thread core/api/src/services/auth/role-checker.ts Outdated
Comment thread core/api/src/servers/graphql-admin-api-server.ts Outdated
Comment thread core/api/package.json Outdated
Comment thread core/api/package.json Outdated
Comment thread core/api/BUCK Outdated
Comment thread core/api/BUCK Outdated
Comment thread bats/core/api/admin.bats Outdated
@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
Comment thread apps/admin-panel/app/api/auth/[...nextauth]/options.ts Outdated
Comment thread apps/admin-panel/app/api/auth/[...nextauth]/options.ts Outdated
Comment thread apps/admin-panel/app/api/auth/[...nextauth]/options.ts Outdated
Comment thread apps/admin-panel/app/env.ts Outdated
Comment thread apps/admin-panel/app/env.ts Outdated
Comment thread core/api/src/services/auth/role-checker.ts Outdated
openoms
openoms previously approved these changes Sep 3, 2025
Copy link
Copy Markdown

@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 thread apps/admin-panel/BUCK
@k9ert k9ert force-pushed the kn/admin_api_rbac branch 2 times, most recently from 27c6f66 to 5502141 Compare October 1, 2025 15:04
Comment thread apps/admin-panel/README.md
@k9ert k9ert force-pushed the kn/admin_api_rbac branch from 86b216e to a7a0995 Compare October 20, 2025 05:26
Comment thread core/api/src/servers/graphql-admin-api-server.ts Outdated
Comment thread pnpm-lock.yaml
// eslint-disable-next-line @typescript-eslint/no-explicit-any
): Record<keyof T, GraphQLFieldConfig<any, any, any>> {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const result: Record<string, GraphQLFieldConfig<any, any, any>> = {}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

did you test with unkown?

Copy link
Copy Markdown
Author

@k9ert k9ert Oct 29, 2025

Choose a reason for hiding this comment

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

Doesn't seem so as this was a seemless change!
Update: seems to have broken the build. A local pnpm tsc suceeds but the GithubAction does not.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

*/
export type AdminFieldDefinition = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
field: GraphQLFieldConfig<any, any, any>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

same here

Comment thread apps/admin-panel/app/access-rights.ts
@k9ert k9ert requested a review from dolcalmi October 29, 2025 18:53
@k9ert k9ert force-pushed the kn/admin_api_rbac branch 2 times, most recently from 5e46ea7 to ce660fd Compare December 2, 2025 08:11
@k9ert k9ert requested review from grimen and removed request for dolcalmi December 2, 2025 09:03
k9ert and others added 9 commits May 14, 2026 20:05
fix: linter happy

fix: linter happy

chore: prettier

fix: tests

fix: types

fix: linter

fix: env-vars for buck2

fix: env vars for workflow

fix: change way to use service-account credentials

fix: NODE_ENV test for integration tests

fix: GCS_APPLICATION_CREDENTIALS_PATH within env.ts

fix: prettier

chore: tidy up, part 1

chore: tidy up part 2

fix: remove env from BUCK

poc: Try to enrich the JWT token

remove gcloud dependencies

fix
@dolcalmi dolcalmi force-pushed the kn/admin_api_rbac branch from ce660fd to f97f8a8 Compare May 15, 2026 02:35
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