簡體   English   中英

如何在我的本地筆記本電腦中使用來自 Django 應用程序的托管服務標識連接到 Azure SQL 服務器

[英]How to connect to Azure SQL Server using Managed Service Identity from Django application in my local laptop

我有一個 Django 應用程序,它通過傳統的用戶名和密碼組合連接到 Azure SQL 服務器,它工作正常。

我為此使用的庫是 mssql-django。 這是它的鏈接。 https://github.com/microsoft/mssql-django

這是settings.py的摘錄

DATABASES = {
    "default": {
        "ENGINE": "mssql",
        "NAME": "db_name",
        "USER": "foo",
        "PASSWORD": "password",
        "HOST": "foo.database.windows.net",
        "PORT": "1433",
        "OPTIONS": {
            "driver": "ODBC Driver 17 for SQL Server", 
        },
    },
}

但是,我想使用托管身份連接到 Azure SQL 服務器。 我正在使用的庫在此鏈接中討論此問題: https://github.com/microsoft/mssql-django/wiki/Azure-AD-Authentication

在上述鏈接的底部,他們建議使用此設置:

DATABASES = {
    "default": {
        "ENGINE": "mssql",
        "NAME": "db_name",
        "HOST": "foo.windows.net",
        "PORT": "1433",
        "OPTIONS": {
            "driver": "ODBC Driver 17 for SQL Server",
            "extra_params": "Authentication=ActiveDirectoryMsi",
        },
    },
}

但是如何在我的本地筆記本電腦中設置托管身份,以便它可以通過 Azure 進行身份驗證? 我知道這適用於應用服務或 Azure VM,但是如何為本地筆記本電腦設置它?

托管服務標識只能用於托管在 Azure 上的資源

由於您的應用程序托管在本地筆記本電腦中,因此您無法使用托管服務身份

在您的情況下,您可以使用服務主體身份驗證而不是托管服務身份

If your application is hosted in Azure (either Azure App service or Azure VM), then you can create Managed Identity for your Azure Resource and provide the required permissions for the managed identity in the Azure SQL server

然后您就可以為您的應用程序使用托管服務標識

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM