我已经到处搜索,但似乎找不到一种方法来保护我的 Node-RED 用户界面。匿名用户可以访问该 UI...
到目前为止,我已尝试设置
settings.json
文件和 httpNodeAuth
部分,但没有任何效果。
如何限制对 Node-RED UI 的访问?
我终于意识到 这是一个“缓存”问题。 node-red 似乎在缓存方面工作得非常积极。 谢谢大家的支持
settings.js
目录中的
.node-red
副本。当 Node-RED 启动时,将记录此文件及其位置18 May 11:41:51 - [info] Settings file : /home/hardillb/.node-red/settings.js
18 May 11:41:51 - [info] User directory : /home/hardillb/.node-red
18 May 11:41:51 - [info] Flows file : /home/hardillb/.node-red/testing.json
18 May 11:41:51 - [info] Server now running at http://127.0.0.1:1880/
18 May 11:41:51 - [info] Starting flows
接下来您要保护 Node-RED 编辑器 UI 还是仪表板 UI?
如果是编辑器 UI,那么您需要找到
adminAuth
部分:
adminAuth: {
type: "credentials",
users: [{
username: "admin",
password: "$2a$08$zZWtXTja0fB1pzD4sHCMyOCMYz2Z6dNbM6tl8sJogENOMcxWV9DN.",
permissions: "*"
}]
},
您可以使用以下命令生成密码哈希:
node-red-admin hash-pw
或
node -e "console.log(require('bcryptjs').hashSync(process.argv[1], 8));" [your-password-here]
如果您想保护仪表板 UI,那么需要更改
httpNodeAuth
选项。
httpNodeAuth: {user:"user",pass:"$2a$08$zZWtXTja0fB1pzD4sHCMyOCMYz2Z6dNbM6tl8sJogENOMcxWV9DN."},
如果您使用
httpStatic
启用了静态内容服务,则该内容将通过
httpStaticAuth
指令受到保护。httpStaticAuth: {user:"user",pass:"$2a$08$zZWtXTja0fB1pzD4sHCMyOCMYz2Z6dNbM6tl8sJogENOMcxWV9DN."}
两种情况下的密码哈希的生成方式与
adminAuth
部分相同。
可以在此处找到用于保护 Node-RED 的文档:http://nodered.org/docs/security它们都使得向端点添加身份验证变得相对容易,并且不依赖于 ExpressJS 设置的复杂性来实现这一点。