从Linux机器上的nodejs使用Active Directory连接到Sql Server

Mit*_*hir 8 sql-server node.js azure-active-directory node-mssql

我有一个在Linux机器上运行的nodejs服务。我需要连接到Sql Server(Mssql)。

我正在使用mssql程序包,但在与AD连接时看不到任何支持。

还有一个Azure Keyvault,我们可以通过调用以下命令与连接到计算机的MSI连接:

import * as msRestAzure from 'ms-rest-azure'
msRestAzure.loginWithVmMSI({ resource: this.azureKeyVaultResourceName })
Run Code Online (Sandbox Code Playgroud)

有没有办法使用我从loginWithVmMSI获得的凭据并连接到Sql Server?有没有一种方法可以直接用AD调用Sql Server?

是否有其他驱动程序对此提供支持?乏味还是nodemssql?

tuk*_*kan 5

如果可以使用Tedious(支持tedious@4.1.0中的 Azure AD)。

有一个顶级authentication选项,它允许指定要使用的身份验证方法:

new Connection({
  'config': {
    'server': '<server>',
    'authentication': {
      'type': 'azure-active-directory-password',
      'options': {
        'userName': '<userName>',
        'password': '<password>'
      }
    },
    'options': {
      'encrypt': true
    }
  }
})
Run Code Online (Sandbox Code Playgroud)

至于集成安全性部分(MSI身份验证支持),当前(19.5.2019)在github上有一个待处理的拉取请求。如果它获得批准/接受,您将获得支持-您也可以手动添加它。

配置看起来像这样

简单的连接配置:

var connectionADMSI = {
    server: [Server Name], 
    options: {
        database:[Database Name],
        encrypt: true
    },
    authentication: {
        type: "azure-active-directory-MSI",
        // Option client id, if provided, then the token will be only valid for that user
        options: {
        clientID: [Client ID For User Assigned Identity]
        }
    }
};
Run Code Online (Sandbox Code Playgroud)

如果您使用,则表示msnodesqlv8您不走运。这是Windows的唯一解决方案,Linux尚不支持。为了提供信息,我将介绍如何与其连接:

// Init connection string
var dbConfig = {    
    driver: 'msnodesqlv8',
    connectionString:'Driver={SQL Server Native Client 11.0};Server={localhost\\SQLNode};Database={nodedb};Trusted_Connection={yes};'
};
Run Code Online (Sandbox Code Playgroud)