在Node.js中隐藏OracleDatabase凭据

问题描述

我正在使用示例功能连接到外部Oracle数据库here

const oracledb = require('oracledb');

const connection = await oracledb.getConnection(
  {
    user          : "hr",password      : mypw,// mypw contains the hr schema password
    connectString : "mydbmachine.example.com/orclpdb1"
  }
);

因此,如您所见,我的凭据将“公开”给所有可以访问代码的人(也许是github存储库之类)。

有什么办法可以隐藏我的用户名密码或对其进行保密,还是我不必担心?

注意:我正在使用oracledb节点模块

解决方法

您可以使用.env,并通过process.env对其进行访问。

在此处检查:https://nodejs.org/dist/latest-v8.x/docs/api/process.html#process_process_env

,

存储以Secrets ManagerParameter Store加密的数据库机密,并让您的应用在运行时读取它们。请确保更新您的应用使用的IAM角色,以使其具有IAM权限来检索凭据。

注意:对于certain databases,Secrets Manager支持凭据的自动轮换。

,

选择包括:

  1. 在运行时提示输入密码

  2. 在环境变量中传递密码

  3. 使用kerberos,然后在node-oracledb中使用'external' authentication。所有这些都是在node-oracledb下面的代码层中配置和启用的,请参见Oracle Database Security Guide

  4. 使用Oracle Wallet,然后在node-oracledb中使用“外部”身份验证。