Can we pass username, password and permissions as an enviornment variable at run time of docker node-red instance?

in settings.js I added adminAuth like this:
adminAuth: {
type: "credentials",
users: [
username: process.env.USER_NAME,
password: process.env.PASSWORD,
permissions: process.env.PERMISSIONS || "*"

FROM nodered/node-red:latest

COPY settings.js /data/

USER root

RUN mkdir /data/nodes

COPY ./custom-node /data/nodes

RUN chown -R node-red:node-red /data/nodes

USER node-red

RUN cd /data/nodes && npm install

USER node-red

RUN npm install --no-fund --no-update-notifier --save node-red-contrib-storage-mongodb

Docker build
docker build -t custom-node-red .

Docker Run
docker run -d -p 1881:1880 -e MONGO_URL="MONGODB_PASSWORD" -e USER_NAME=prachi -e PASSWORD=password123 -e PERMISSIONS=* -e APP_NAME=r1 --name r1 custom-node-red

When I'm login the user name and password it is saying: Login Failed with
{"error":"invalid_grant","error_description":"Invalid resource owner credentials"}

Can anyone please help to know why it is not accepting the username and password at the time of login??

Hi @prachi

when sharing code samples on the forum, please make the effort to format them so they show as code samples rather than plain text. You can do that using the </> button in the toolbar, or simply wrap your code in backticks - ```

For your actual question, the value of password needs to be a properly hashed password, not the plain text as described here: Securing Node-RED : Node-RED

Can you please check even I passed the hashed value it still failed to login :
docker run -d -p 1880:1880 -e MONGO_URL="MONGODB_PASSWORD" -e USERNAME=chris -e PASSWORD="$2a$08$khD.TTAfyiJef5wJFaaa3OaSMC9iJ9Uz5Vbu5mldKzEbZSa6ClDtC" -e APP_NAME=r1 --name r1 custom-node-red

403 FORBIDDEN with: {"error":"invalid_grant","error_description":"Invalid resource owner credentials"}

I'm not an expert at these things, but shouldn't you escape the dollar sign?

docker run -d -p 1880:1880 -e MONGO_URL="MONGODB_PASSWORD" -e USERNAME=chris -e PASSWORD="\$2a\$08\$khD.TTAfyiJef5wJFaaa3OaSMC9iJ9Uz5Vbu5mldKzEbZSa6ClDtC" -e APP_NAME=r1 --name r1 custom-node-red

or put the hash in single quotes:
-e PASSWORD='$2a$08$khD.TTAfyiJef5wJFaaa3OaSMC9iJ9Uz5Vbu5mldKzEbZSa6ClDtC'

1 Like

Thank you so much, It work with single quotes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.