node-red-contrib-opcua icon indicating copy to clipboard operation
node-red-contrib-opcua copied to clipboard

How to Create User.json File or use "SetUsers"-Command

Open PascalW123 opened this issue 3 years ago • 16 comments

Hello,

im having issues with creating users for my OPCUA Server. I have created Json file like this: {"username":"User1","password":"Password123", "role":"Administrator"} as well as [{"username":"User1","password":"Password123", "role":"ConfigureAdmin"}]

and I linked this in my OPCUA Server under Users File. image But when I try to connect I get this error: image

I was not able to find an example of how to create and use users in your examples. Could you please help me out?

PascalW123 avatar Nov 15 '21 10:11 PascalW123

Start from the command line with the -v option. Then you can see how it loads users.json

Perhaps directory separator \ should be /

Look line: Trying to load default users from file: c:/temp/users.json

C:\Users\karaimi.node-red>node-red -v USERS2.json

15 Nov 13:25:43 - [info]

Welcome to Node-RED
===================

15 Nov 13:25:43 - [info] Node-RED version: v1.0.6
15 Nov 13:25:43 - [info] Node.js  version: v12.16.2
15 Nov 13:25:43 - [info] Windows_NT 10.0.19042 x64 LE
15 Nov 13:25:44 - [info] Loading palette nodes
15 Nov 13:25:46 - [info] Worldmap version 2.8.1
15 Nov 13:25:46 - [info] Dashboard version 2.27.0 started at /ui
15 Nov 13:25:46 - [info] Settings file  : C:\Users\karaimi\.node-red\settings.js
15 Nov 13:25:46 - [info] Context store  : 'default' [module=memory]
15 Nov 13:25:46 - [info] User directory : C:\Users\karaimi\.node-red
15 Nov 13:25:46 - [warn] Projects disabled : editorTheme.projects.enabled=false
15 Nov 13:25:46 - [info] Flows file     : C:\Users\karaimi\.node-red\USERS2.json
15 Nov 13:25:46 - [warn]

---------------------------------------------------------------------
Your flow credentials file is encrypted using a system-generated key.

If the system-generated key is lost for any reason, your credentials
file will not be recoverable, you will have to delete it and re-enter
your credentials.

You should set your own key using the 'credentialSecret' option in
your settings file. Node-RED will then re-encrypt your credentials
file using your chosen key the next time you deploy a change.
---------------------------------------------------------------------

15 Nov 13:25:46 - [info] Starting flows
Trying to load default users from file: c:/temp/users.json (current folder: C:\Users\karaimi\.node-red\node_modules\node-red-contrib-opcua\opcua)
15 Nov 13:25:46 - [info] [OpcUa-Server:4d4531ac.c402a] Trying to load default users from file: c:/temp/users.json (current folder: C:\Users\karaimi\.node-red\node_modules\node-red-contrib-opcua\opcua)
Loaded users: [{"username":"visitor","password":"qwerty","role":"Guest"},{"username":"JohnSmith","password":"1234","role":"Operator"},{"username":"Administrator","password":"HardPassword!","role":"ConfigureAdmin"}]
15 Nov 13:25:46 - [info] [OpcUa-Server:4d4531ac.c402a] Loaded users: [{"username":"visitor","password":"qwerty","role":"Guest"},{"username":"JohnSmith","password":"1234","role":"Operator"},{"username":"Administrator","password":"HardPassword!","role":"ConfigureAdmin"}]
: node set:C:\Users\karaimi\.node-red\node_modules\node-red-contrib-opcua\opcua\public\vendor\opc-foundation\xml\Opc.Ua.NodeSet2.xml,C:\Users\karaimi\.node-red\node_modules\node-red-contrib-opcua\opcua\public\vendor\opc-foundation\xml\Opc.Ua.AutoID.NodeSet2.xml,C:\Users\karaimi\.node-red\node_modules\node-red-contrib-opcua\opcua\public\vendor\opc-foundation\xml\Opc.ISA95.NodeSet2.xml
15 Nov 13:25:46 - [warn] [OpcUa-Server:4d4531ac.c402a] OpcUaServerNode: node set:C:\Users\karaimi\.node-red\node_modules\node-red-contrib-opcua\opcua\public\vendor\opc-foundation\xml\Opc.Ua.NodeSet2.xml,C:\Users\karaimi\.node-red\node_modules\node-red-contrib-opcua\opcua\public\vendor\opc-foundation\xml\Opc.Ua.AutoID.NodeSet2.xml,C:\Users\karaimi\.node-red\node_modules\node-red-contrib-opcua\opcua\public\vendor\opc-foundation\xml\Opc.ISA95.NodeSet2.xml
: create Server from XML ...
15 Nov 13:25:46 - [warn] [OpcUa-Server:4d4531ac.c402a] OpcUaServerNode: create Server from XML ...
15 Nov 13:25:46 - [info] Started flows
15 Nov 13:25:46 - [info] Server now running at http://127.0.0.1:1880/

image

mikakaraila avatar Nov 15 '21 11:11 mikakaraila

Then with UaExpert:

image

mikakaraila avatar Nov 15 '21 11:11 mikakaraila

Hello,

thank you for your quick reply. However I have now run into new issue. While trying to fix this I updated the OPCUA Nodes Palette and now my .XML File will not work anymore. CSBME.zip It worked fine before but now it never builds the namespace like it should. On my other PC with old Version it works with same file and looks like this: image But on new one it it never shows the "CTX" Object and Variables under it.
I tried all kinds of different variations of how to load the .XML file:

C:/User/... C:/Benutzer/... C:\User... C:\Benutzer Only CSBME.XML, with the file being inside the Node-Red-Contrib and ...Contrib/opcua folders.

When using User as the folder Node-Red gave me an error "Directoy not found" everytime. With german "Benutzer" as user it doesn't throw an error but still wont create the Server like it should.

PascalW123 avatar Nov 15 '21 12:11 PascalW123

Check this, it is not anymore one file, it is folder:

image

It was very short time loading one file and I updated it to load all files from the folder.

mikakaraila avatar Nov 15 '21 12:11 mikakaraila

Thank you!!! This fixed the Nodeset. But users is not working yet sadly. I see only this when I enter OPCUsers.json and I can't open Node-Red after image

Whats interesting is this. When I just enter OPCUsers.json and put it in the correct folder Node-Red still tells me that it cant be found: image

PascalW123 avatar Nov 15 '21 12:11 PascalW123

Again \ -> /

mikakaraila avatar Nov 15 '21 12:11 mikakaraila

Strange. Because it works on the Custom nodeset with \. On the OPCUsers.json it doesnt work with /. See here: image

But now it doesn't throw me an error with: "C:/Users/marvin/.node-red/node_modules/node-red-contrib-opcua/opcua/OPCUsers.json"

But when i try to use this in UAExpert I cant connect: image

PascalW123 avatar Nov 15 '21 12:11 PascalW123

It loads the Users but still not working in UaExpert image

When I connect as Anonymous it works and says "Reason: True" cmd When I try user and PW it just says "Reason False" in cmd image

PascalW123 avatar Nov 15 '21 13:11 PascalW123

UserIdentity [{"type":0}] is anonymous?

If I change user then I see this on UaExpert:

image

mikakaraila avatar Nov 15 '21 13:11 mikakaraila

Do you have client node None/None options for Read/Write Multiple?

mikakaraila avatar Nov 15 '21 13:11 mikakaraila

This way:

image

mikakaraila avatar Nov 15 '21 14:11 mikakaraila

Sign means it will use user & password given below "Use credentials"

As verbose is on it will show on console this information: 15 Nov 16:04:27 - [info] [OpcUa-Client:9be75df2.167] Create session ... Create session with userIdentity: [{"userName":"1","password":"2","type":1},"visitor","qwerty"] 15 Nov 16:04:27 - [info] [OpcUa-Client:9be75df2.167] Create session with userIdentity: [{"userName":"1","password":"2","type":1},"visitor","qwerty"]

mikakaraila avatar Nov 15 '21 14:11 mikakaraila

Yes I do. type:0 is for anonymous I think yes. After I enabled all settings here (now I disabled Anonymous to test) it works. Even tho I choose none/none in UaExpert. image

I was able to connect with UaExpert using User and PW. Node, like write multiple can also connect using the User and PW. But only when setting SecurityPolicy and SecurityMode to "None". If I set them to Basic 256 and Sign I get this error: image

PascalW123 avatar Nov 15 '21 14:11 PascalW123

Read comments above...

mikakaraila avatar Nov 15 '21 14:11 mikakaraila

Error when using Basic256 + Sign image Works when using None + None: image

PascalW123 avatar Nov 15 '21 14:11 PascalW123

Depends on what you have active on server node allowed settings.

And if you have multiple client nodes remember to change parameters in each of them.

mikakaraila avatar Nov 15 '21 14:11 mikakaraila

Not active anymore.

mikakaraila avatar Feb 28 '23 17:02 mikakaraila