我有一个使用node-config( https://www.npmjs.com/package/ppackage/config )加载应用程序配置。我要做的是将秘密从Azure KeyVault加载到启动过程中的配置,并在需要之前确保它们可用(例如连接到数据库等)。
我毫无疑问地连接到钥匙vault的价值,但是我在JS的非阻滞性质上苦苦挣扎。在配置值已完成加载(异步)到配置之前,应用程序启动过程正在继续。
- 一种策略可能是延迟申请启动,以等待KeyVault Secrets加载在启动时如何在Node的启动过程中等待主要?
- 另一个是不要将它们加载到配置中,而是修改代码,以便使用秘密在哪里通过Promises加载这些秘密来加载这些
,似乎成为一个常见的问题,因此我希望这里的某人可以提供示例或设计模式,以确保在启动过程中加载远程钥匙vault秘密的最佳方式。
事先感谢您的建议。
杆
I have a NodeJS application that uses Node-Config (https://www.npmjs.com/package/config) to load application configurations. What I'm trying to do is to load secrets from Azure Keyvault to the config during startup, and ensure these are available before required (e.g. connecting to databases etc).
I have no problem connecting to and retrieving values from the Keyvault, but I am struggling with the non-blocking nature of JS. The application startup process is continuing before the config values have completed loaded (asynchronously) to the config.
- One strategy could be to delay application launch to await the keyvault secrets loading How to await in the main during start up in node?
- Another would be to not load them in Config but instead modify code where-ever secrets are used to load these asynchronously via promises
It seems like this will be a common problem, so I am hoping someone here can provide examples or a design pattern of the best way of ensuring remote keyvault secrets are loaded during startup.
Thanks in advance for suggestions.
Rod
发布评论
评论(1)
我现在已经成功解决了这个问题。
要注意的一个关键点是设置process.env ['lesson_config_mutations'] = true;
默认情况下,配置是不变的(初始设置后不能更改它们)。由于异步将在以后解决这些问题,因此必须调整此设置至关重要。否则,您会看到异步配置从密钥库中获得正确的值,但是当您使用config签名时。这确实应添加到
我的解决方案:首先,让我们为azure keystore客户端创建一个模块-Azure-keyvault.mjs:
in Config(in Config(使用 @node-config)文件(使用 @node-config)文件:
之前解决异步会议
最后修改应用程序启动以在config.get被称为server.js
。评论或改进以上欢迎。
〜杆
I have now successfully resolved this question.
A key point to note is setting process.env['ALLOW_CONFIG_MUTATIONS']=true;
Configs are immutable by default (they can't be changed after initial setting). Since async is going to resolve these later, it's critical that you adjust this setting. Otherwise you will see asynchronous configs obtaining correct values from the keystore, but when you check with config.get they will not have been set. This really should be added to the documentation at https://github.com/node-config/node-config/wiki/Asynchronous-Configurations
My solution: first, let's create a module for the Azure keystore client - azure-keyvault.mjs :
In the config (using @node-config) files:
Finally modify application startup to resolve the async conferences BEFORE config.get is called
server.js
I hope this helps others wishing to use config/async with remote keystores such as Azure. Comments or improvements on above welcome.
~ Rod