azure-active-directory-service-principal-secret 节点续集迁移

问题描述 投票:0回答:1

我正在使用以下快速方法将数据库与服务主体连接起来 链接

但是在运行迁移时,它将从 db.config 文件建立连接 其中 db.config 文件包含

  "development": {
"username": process.env.DB_USER,
"password": process.env.DB_PASSWORD,
"database": process.env.DB_DATABASE,
"host": process.env.DB_HOST,
"dialect": "mssql",
"logging": false

},

那么如何为服务主体方法配置 db.config 文件

javascript node.js sequelize.js azure-service-principal dbconnection
1个回答
0
投票

如何为服务主体方法配置 db.config 文件

按照以下步骤为服务主体方法配置

db.config
文件:

  • 创建一个

    App registration
    ,如下所示 enter image description here

  • 提供应用程序的名称,然后单击

    Register
    enter image description here

  • 注册后请注意

    ClientId
    TenantId
    enter image description here

  • 生成

    Certificates & Secrets
    中存在的客户端密钥并记下
    secretId
    enter image description here

  • 向您创建的服务主体授予权限。要授予权限,请导航到 Azure 服务器中存在的

    Access control
    ,然后转到
    Add role assignment
    ,如下所示。 enter image description here

  • 选择访问数据库所需的角色。我选择了

    SQL DB Contributor
    角色。 enter image description here

  • 选择角色后,选择要分配角色的成员。 enter image description here

添加角色分配后,现在在

db.config

中相应地提供所需的配置详细信息
module.exports = {
    development: {
      username: 'admin1',
      password: '*****',
      database: 'db1',
      host: 'server6391.database.windows.net',
      dialect: 'mssql',
      logging: false, // Set to true for Sequelize query logging
  
      authentication: {
        type: 'azure-active-directory-msi-app-service',
        options: {
          resource: 'https://database.windows.net/',
          tenantId: '******',
          clientId: '******'
        }
      }
    }
  };  

通过运行节点应用程序,它将成功连接到数据库,如下面的输出所示。 enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.