-
Notifications
You must be signed in to change notification settings - Fork 4
feat: RBAC for the admin-api #158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
568a8ae
to
79430bc
Compare
There was a problem hiding this 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.
5ce4d40
to
d8f13a6
Compare
dev_pnpm_task_test( | ||
name="unit-test", | ||
command="test", | ||
deps = ["//:node_modules"], | ||
) | ||
|
There was a problem hiding this comment.
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?!
3f99a16
to
569273a
Compare
422831b
to
27c6f66
Compare
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
27c6f66
to
5502141
Compare
yarn install | ||
export PORT=3004 | ||
yarn dev | ||
pnpm install |
There was a problem hiding this comment.
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.
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 everythingSUPPORTLV2
: 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 onlyVIEWER
: can only view accounts and transactionsOne user can have many roles.
The admin-panel then maps those roles to a list of access-rights like this:
Role Hierarchy:
VIEW_ACCOUNTS
,VIEW_TRANSACTIONS
,VIEW_MERCHANTS
SEND_NOTIFICATIONS
VIEW_ACCOUNTS
,VIEW_TRANSACTIONS
,VIEW_MERCHANTS
,LOCK_ACCOUNT
,APPROVE_MERCHANT
,CHANGELEVEL_ACCOUNT
CHANGECONTACTS_ACCOUNT
,DELETE_ACCOUNTS
,SYSTEM_CONFIG
Here is a table:
VIEW_ACCOUNTS
VIEW_TRANSACTIONS
VIEW_MERCHANTS
LOCK_ACCOUNT
APPROVE_MERCHANT
CHANGECONTACTS_ACCOUNT
CHANGELEVEL_ACCOUNT
SEND_NOTIFICATIONS
DELETE_ACCOUNTS
SYSTEM_CONFIG
Legend:
This list is then attached to the
token.scope
(as stringified JSON).