My Node-RED apps using D2 often need to be accessed by multiple users, and I've often found the need for a way to easily control access to pages via the UI. I've created a work in progress PR that adds User Allowed Page filtering by utilizing user credentials provided by auth plugins. Would highly appreciate any feedback, suggestions or pointers from the more experienced people here.
Description
As said, this is more a proof-of-concept PR for user page filtering using auth plugins. With my tests this seems to have been quite robust, looking for additional feedback.
Still needs to be decided which direction to take here, whether this functionality should be integrated into D2 directly, added as a plugin or as a 3rd party node.
Working Principle
-
D2 will function exactly as usual unless
global.store.enablePageFilter
with contextfile
is set totrue
. -
For now, UI for Admin Management of users, groups and pages is just a Node-RED flow using D2 widgets.
-
Users and groups are saved to Node-RED
file
context storage so no database is needed. User allowed pages are then determined on a group basis and saved to and retrieved fromglobal.store[{user}].allowedPages
inmemory only
context. -
On
ui-base
emitConfig()
all pages, groups and widgets are filtered based on the page they reside in or if they are UI scoped. Therefore, only the allowed pages, groups, and widgets are emitted in the config to the connected dashboards. This could also have added benefit of improved load speeds. -
Includes an optional zero-trust filtering approach where all users are denied access to all pages by default, or alternatively, enabling filtering for a specific user only if they have been added to user list (default?).
-
D2 pages are automatically populated as form options to
ui-form
for adding Groups in Admin Management UI, same with groups when adding User -
Uses
msg._client.user.email
as user ID, will need to arrive at some sort of standardization across auth plugins concerning this -
Any users logged in using an auth provider will show up as detected user in UI, which you can then assign groups to.
Usage
-
Use this branch of D2: https://github.com/cgjgh/node-red-dashboard/tree/User-Page-Filtering
-
Attached below is a Node-RED flow with the necessary D2 UI for Admin Management of users, groups and pages.
-
Integrated into the PR is a test mode which you can toggle in UI and impersonate a specific user, therefore no auth plugins are required for testing.
-
New groups and users can be added with the included
ui-form
. -
Table rows can be selected to load a form to edit user or group
-
Since D2
ui-table
does not yet support dynamic props, included in the flow below areinject
nodes with functions to generate JSON for each table with all columns for pages or groups predefined. This you can then copy from debug window and import and replace the existing tables in flow, or alternatively edit the table node.
Example UI for Admin Management
Controls
- Enable Page Filtering - turn filtering on or off
- Enable Zero Trust - turn
on
to deny access to all pages by default,off
to enable filtering only for users existing in user list (prevents locking out users while in development) - Enable Test Mode - impersonate a specific user to check page access, current user is defined by the dropdown or textbox - Test mode settings are globally applied to anyone using D2, needs to be turned off during normal use
- Dropdown allows selecting users existing in user list
- Textbox allows setting user not existing in user list
Tables
- First table shows users and what groups they are part of
- Second table shows users and what pages they are allowed access to
- Third table shows users detected using dashboard, and whether they exist in user list
- Fourth table shows groups and what pages are part of the group
Example Flow
D2 User Access Control Flow.json (77.3 KB)
or :
copy from PR on Github in Example Flow section. (full flow doesn't fit in this post)