rbac-core
The RBAC core from hapi-rbac
This is inspired by the XACML policies.
Versions
1.0.0
Release Notes2.0.0
Release Notes3.0.0
Release Notes
How to use it
First, install
npm install --save rbac-core
Import it to your project
const Rbac = ;const DataRetrievalRouter = RbacDataRetrievalRouter;
Create your data sources in the data retrieval router
const dataRetrieverRouter = ; /** * register(prefixes, dataretriever): registers a data retriever. * * prefixes - a string or array of strings with prefixes which this data retriever will be associated * dataretriever - a function with the following signature * source - The requested prefix * key - the key being requested * context - An object with contextual information **/dataRetrieverRouter; // You can handle multiple prefixes with a single data retrieverdataRetrieverRouter;
Evaluate your policies against a certain context
const context = user: username: 'francisco' group: 'articles:admin' 'articles:developer' validated: true exampleField1: "test-value" connection: remoteip: '192.168.0.123' remoteport: 90 localip: '192.168.0.2' localport: 80 exampleField2: "test-value" ; dataRetrieverRouter; const policy = target: // if username matches 'francisco' OR (exampleField1 matches exampleField2 AND user group matches 'articles:*') 'credentials:username': 'francisco' // OR 'credentials:exampleField1': field: 'connection:exampleField2' // AND 'credentials:group': /^articles\:.*$/ //(using native javascript RegExp) apply: 'deny-overrides' // permit, unless one denies rules: target: 'credentials:group': 'articles:admin' 'credentials:validated': false // if group is 'articles:admin' AND is not validated effect: 'deny' // then deny (deny access to users that are not validated) target: 'connection:remoteip': '192.168.0.2' '192.168.0.3' // if remoteip is one of '192.168.0.2' or '192.168.0.3' effect: 'deny' // then deny (deny blacklisted ips) effect: 'permit' // else permit ; Rbac;
If you want to extend your existent data retriever router, you can do it.
// You can just extendconst dataRetrieverRouter1 = dataRetrieverRouter; // You can also directly add context to the extension, for isolationconst dataRetrieverRouter2 = dataRetrieverRouter;
Both dataRetrieverRouter1
and dataRetrieverRouter2
will have all the registered data retrievers from dataRetrieverRouter
.
Changes to dataRetrieverRouter
will influence dataRetrieverRouter1
and dataRetrieverRouter2
.
Changes to any of dataRetrieverRouter1
or dataRetrieverRouter2
will not cause influence on any data retriever routers, but themselves.
Contexts are preserved per data retriever router.
You can also get data from data retriever router
dataRetrieverRouter;
And you can override the context on get, by passing it in the second argument
dataRetrieverRouter;
Learn more about Rule Based Access Control
To have a better idea of how this works, you can check my Bachelor's project presentation about XACML here (english), or here (portuguese).
Even though this plugin doesn't implement the XACML specification, it was based on its policies.