使用 Azure Active Directory authenticationUse Azure Active Directory authentication

適用於: Azure SQL Database Azure SQL 受控執行個體 Azure Synapse Analytics

Azure Active Directory (Azure AD) authentication 是在 Azure SQL Database 中使用身分識別連接到 受控執行個體Azure Sql AZURE SYNAPSE ANALYTICSSynapse SQL 的機制。Azure Active Directory (Azure AD) authentication is a mechanism for connecting to Azure SQL Database, Azure SQL Managed Instance, and Synapse SQL in Azure Synapse Analytics by using identities in Azure AD.

注意

本文適用于 Azure SQL Database、SQL 受控執行個體和 Azure Synapse Analytics。This article applies to Azure SQL Database, SQL Managed Instance, and Azure Synapse Analytics.

您可以使用 Azure AD 驗證,在單一中央位置集中管理資料庫使用者和其他 Microsoft 服務的身分識別。With Azure AD authentication, you can centrally manage the identities of database users and other Microsoft services in one central location. 中央識別碼管理提供單一位置以管理資料庫使用者並簡化權限管理。Central ID management provides a single place to manage database users and simplifies permission management. 包括以下優點:Benefits include the following:

  • 它提供 SQL Server 驗證的替代方案。It provides an alternative to SQL Server authentication.

  • 它有助於停止跨伺服器的使用者身分識別激增。It helps stop the proliferation of user identities across servers.

  • 允許在單一位置變換密碼。It allows password rotation in a single place.

  • 客戶可以使用外部 (Azure AD) 群組來管理資料庫權限。Customers can manage database permissions using external (Azure AD) groups.

  • 它可以藉由啟用整合式 Windows 驗證和 Azure Active Directory 支援的其他形式驗證來避免儲存密碼。It can eliminate storing passwords by enabling integrated Windows authentication and other forms of authentication supported by Azure Active Directory.

  • Azure AD 驗證會使用自主資料庫使用者,在資料庫層級驗證身分。Azure AD authentication uses contained database users to authenticate identities at the database level.

  • Azure AD 針對連接至 SQL Database 和 SQL 受控執行個體的應用程式支援以權杖為基礎的驗證。Azure AD supports token-based authentication for applications connecting to SQL Database and SQL Managed Instance.

  • Azure AD authentication 支援:Azure AD authentication supports:

  • Azure AD 支援來自 SQL Server Management Studio 的連線,其中使用包含 Multi-Factor Authentication 的 Active Directory 通用驗證。Azure AD supports connections from SQL Server Management Studio that use Active Directory Universal Authentication, which includes Multi-Factor Authentication. Multi-Factor Authentication 包含強大的驗證,包括一系列簡單的驗證選項,包括電話、文字訊息、具有 pin 的智慧卡或行動代理程式更新。Multi-Factor Authentication includes strong authentication with a range of easy verification options — phone call, text message, smart cards with pin, or mobile app notification. 如需詳細資訊,請參閱 使用 Azure SQL Database、SQL 受控執行個體和 Azure Synapse Azure AD Multi-Factor Authentication 的 SSMS 支援For more information, see SSMS support for Azure AD Multi-Factor Authentication with Azure SQL Database, SQL Managed Instance, and Azure Synapse

  • Azure AD 支援從 SQL Server Data Tools (SSDT) 使用 Active Directory 互動式驗證的類似連線。Azure AD supports similar connections from SQL Server Data Tools (SSDT) that use Active Directory Interactive Authentication. 如需詳細資訊,請參閱 SQL Server Data Tools (SSDT 中的 Azure Active Directory 支援) For more information, see Azure Active Directory support in SQL Server Data Tools (SSDT)

注意

不支援使用 Azure Active Directory 帳戶來連線至在 Azure 虛擬機器 (VM) 上執行的 SQL Server 執行個體。Connecting to a SQL Server instance that's running on an Azure virtual machine (VM) is not supported using an Azure Active Directory account. 請改用 Active Directory 網域帳戶。Use a domain Active Directory account instead.

設定步驟包括以下設定和使用 Azure Active Directory 驗證的程序。The configuration steps include the following procedures to configure and use Azure Active Directory authentication.

  1. 建立和填入 Azure AD。Create and populate Azure AD.
  2. 選用:和目前與您的 Azure 訂用帳戶相關聯的 Active Directory 產生關聯並加以變更Optional: Associate or change the active directory that is currently associated with your Azure Subscription.
  3. 建立 Azure Active Directory 系統管理員。Create an Azure Active Directory administrator.
  4. 設定用戶端電腦。Configure your client computers.
  5. 在對應至 Azure AD 身分識別的資料庫中建立自主資料庫使用者。Create contained database users in your database mapped to Azure AD identities.
  6. 使用 Azure AD 身分識別連接到您的資料庫。Connect to your database by using Azure AD identities.

注意

若要瞭解如何建立和填入 Azure AD,然後使用 Azure Synapse Analytics 中的 Azure SQL Database、SQL 受控執行個體和 Synapse SQL 來設定 Azure AD,請參閱 使用 Azure AD 設定 Azure SQL DatabaseTo learn how to create and populate Azure AD, and then configure Azure AD with Azure SQL Database, SQL Managed Instance, and Synapse SQL in Azure Synapse Analytics, see Configure Azure AD with Azure SQL Database.

信認架構Trust architecture

  • 只有 Azure AD、SQL Database、SQL 受控執行個體和 Azure Synapse 的雲端部分會被視為支援 Azure AD 原生使用者密碼。Only the cloud portion of Azure AD, SQL Database, SQL Managed Instance, and Azure Synapse is considered to support Azure AD native user passwords.
  • 若要支援 Windows 單一登入認證 (或 Windows 認證) 的使用者/密碼,請使用針對傳遞和密碼雜湊驗證設定無縫單一登入的同盟或受控網域 Azure Active Directory 認證。To support Windows single sign-on credentials (or user/password for Windows credential), use Azure Active Directory credentials from a federated or managed domain that is configured for seamless single sign-on for pass-through and password hash authentication. 如需詳細資訊,請參閱 Azure Active Directory 無縫單一登入For more information, see Azure Active Directory Seamless Single Sign-On.
  • 若要支援同盟驗證 (或 Windows 認證的使用者/密碼),需要與 ADFS 區塊進行通訊。To support Federated authentication (or user/password for Windows credentials), the communication with ADFS block is required.

如需 Azure AD 混合式身分識別、設定和同步處理的詳細資訊,請參閱下列文章:For more information on Azure AD hybrid identities, the setup, and synchronization, see the following articles:

如需搭配 ADFS 基礎結構的同盟驗證範例 (或 Windows 認證) 的使用者/密碼,請參閱下圖。For a sample federated authentication with ADFS infrastructure (or user/password for Windows credentials), see the diagram below. 箭頭表示通訊路徑。The arrows indicate communication pathways.

aad 驗證圖表

下圖表示允許用戶端藉由提交權杖連線到資料庫的同盟、信任和主控關聯性。The following diagram indicates the federation, trust, and hosting relationships that allow a client to connect to a database by submitting a token. 此權杖是由 Azure AD 所驗證,並受到資料庫信任。The token is authenticated by an Azure AD, and is trusted by the database. 客戶 1 可以代表具有原生使用者的 Azure AD 或具有同盟使用者的 Azure Active Directory。Customer 1 can represent an Azure Active Directory with native users or an Azure AD with federated users. 客戶2代表可能的解決方案,包括匯入的使用者,在此範例中,來自具有 ADFS 與 Azure Active Directory 同步處理的同盟 Azure Active Directory。Customer 2 represents a possible solution including imported users, in this example coming from a federated Azure Active Directory with ADFS being synchronized with Azure Active Directory. 請務必了解使用 Azure AD 驗證存取資料庫的必要條件是裝載訂用帳戶要與 Azure AD 相關聯。It's important to understand that access to a database using Azure AD authentication requires that the hosting subscription is associated to the Azure AD. 您必須使用相同的訂用帳戶來建立 Azure SQL Database、SQL 受控執行個體或 Azure Synapse 資源。The same subscription must be used to create the Azure SQL Database, SQL Managed Instance, or Azure Synapse resources.

訂用帳戶關聯性

系統管理員結構Administrator structure

使用 Azure AD 驗證時,有兩個系統管理員帳戶:原始 Azure SQL Database 系統管理員和 Azure AD 系統管理員。When using Azure AD authentication, there are two Administrator accounts: the original Azure SQL Database administrator and the Azure AD administrator. 相同的概念適用于 Azure Synapse。The same concepts apply to Azure Synapse. 只有以 Azure AD 帳戶為基礎的系統管理員可以在使用者資料庫中建立第一個 Azure AD 自主資料庫使用者。Only the administrator based on an Azure AD account can create the first Azure AD contained database user in a user database. Azure AD 系統管理員登入可以是 Azure AD 使用者或 Azure AD 群組。The Azure AD administrator login can be an Azure AD user or an Azure AD group. 當系統管理員是群組帳戶時,任何群組成員都可以使用它,以啟用伺服器的多個 Azure AD 系統管理員。When the administrator is a group account, it can be used by any group member, enabling multiple Azure AD administrators for the server. 使用群組帳戶做為系統管理員,可讓您在 Azure AD 集中新增和移除群組成員,而不需要變更 SQL Database 或 Azure Synapse 中的使用者或許可權,以增強管理能力。Using group account as an administrator enhances manageability by allowing you to centrally add and remove group members in Azure AD without changing the users or permissions in SQL Database or Azure Synapse. 一律只能設定一個 Azure AD 系統管理員 (使用者或群組)。Only one Azure AD administrator (a user or group) can be configured at any time.

系統管理員結構

權限Permissions

若要建立新的使用者,您必須具有資料庫中的 ALTER ANY USER 權限。To create new users, you must have the ALTER ANY USER permission in the database. 任何資料庫使用者皆可授與 ALTER ANY USER 權限。The ALTER ANY USER permission can be granted to any database user. ALTER ANY USER 權限的擁有者還包括伺服器系統管理員帳戶、具備資料庫之 CONTROL ON DATABASEALTER ON DATABASE 權限的資料庫使用者,以及 db_owner 資料庫角色的成員。The ALTER ANY USER permission is also held by the server administrator accounts, and database users with the CONTROL ON DATABASE or ALTER ON DATABASE permission for that database, and by members of the db_owner database role.

若要在 Azure SQL Database、SQL 受控執行個體或 Azure Synapse 中建立自主資料庫使用者,您必須使用 Azure AD 身分識別來連接到資料庫或實例。To create a contained database user in Azure SQL Database, SQL Managed Instance, or Azure Synapse, you must connect to the database or instance using an Azure AD identity. 若要建立第一個自主資料庫使用者,您必須使用 Azure AD 系統管理員 (資料庫的擁有者) 連接到資料庫。To create the first contained database user, you must connect to the database by using an Azure AD administrator (who is the owner of the database). 您可以 使用 SQL Database 或 Azure Synapse 來設定及管理 Azure Active Directory 驗證來示範這一點。This is demonstrated in Configure and manage Azure Active Directory authentication with SQL Database or Azure Synapse. 只有在 Azure AD 系統管理員是針對 Azure SQL Database、SQL 受控執行個體或 Azure Synapse 所建立的情況下,才可以 Azure AD 驗證。Azure AD authentication is only possible if the Azure AD admin was created for Azure SQL Database, SQL Managed Instance, or Azure Synapse. 如果已從伺服器移除 Azure Active Directory 系統管理員,則先前在 SQL Server 內建立的現有 Azure Active Directory 使用者便無法再使用其 Azure Active Directory 認證連線到資料庫。If the Azure Active Directory admin was removed from the server, existing Azure Active Directory users created previously inside SQL Server can no longer connect to the database using their Azure Active Directory credentials.

Azure AD 功能和限制Azure AD features and limitations

  • 您可以針對 Azure SQL Database 布建下列 Azure AD 成員:The following members of Azure AD can be provisioned for Azure SQL Database:

  • Azure AD 屬於具有伺服器角色之群組的使用者,將 db_owner 無法針對 Azure SQL Database 和 Azure Synapse 使用 CREATE DATABASE 範圍認證 語法。Azure AD users that are part of a group that has db_owner server role cannot use the CREATE DATABASE SCOPED CREDENTIAL syntax against Azure SQL Database and Azure Synapse. 您會看到下列錯誤︰You will see the following error:

    SQL Error [2760] [S0001]: The specified schema name 'user@mydomain.com' either does not exist or you do not have permission to use it.

    直接將 db_owner 角色授與給個別 Azure AD 使用者,以減輕 CREATE DATABASE SCOPED CREDENTIAL 問題。Grant the db_owner role directly to the individual Azure AD user to mitigate the CREATE DATABASE SCOPED CREDENTIAL issue.

  • 下列系統函式在 Azure AD 主體下執行時會傳回 NULL:These system functions return NULL values when executed under Azure AD principals:

    • SUSER_ID()
    • SUSER_NAME(<admin ID>)
    • SUSER_SNAME(<admin SID>)
    • SUSER_ID(<admin name>)
    • SUSER_SID(<admin name>)

SQL 受控執行個體SQL Managed Instance

  • Azure AD 伺服器主體 (登入) 和支援 SQL 受控執行個體的使用者。Azure AD server principals (logins) and users are supported for SQL Managed Instance.
  • 將 Azure AD 伺服器主體 (登入) 對應至 Azure AD 群組的登入,因為 SQL 受控執行個體不支援資料庫擁有者。Setting Azure AD server principals (logins) mapped to an Azure AD group as database owner is not supported in SQL Managed Instance.
    • 其中一個延伸模組是當群組加入成為伺服器角色的一部分時 dbcreator ,此群組的使用者可以連接到 SQL 受控執行個體並建立新的資料庫,但無法存取資料庫。An extension of this is that when a group is added as part of the dbcreator server role, users from this group can connect to the SQL Managed Instance and create new databases, but will not be able to access the database. 這是因為新的資料庫擁有者是 SA,而不是 Azure AD 使用者。This is because the new database owner is SA, and not the Azure AD user. 如果將個別使用者新增至 dbcreator 伺服器角色,則不會顯示這個問題。This issue does not manifest if the individual user is added to the dbcreator server role.
  • (登入) 的 Azure AD 伺服器主體都支援 SQL Agent 管理和作業執行。SQL Agent management and jobs execution are supported for Azure AD server principals (logins).
  • Azure AD 伺服器主體 (登入) 可以執行資料庫備份和還原作業。Database backup and restore operations can be executed by Azure AD server principals (logins).
  • 支援稽核與 Azure AD 伺服器主體 (登入) 和驗證事件相關的所有陳述式。Auditing of all statements related to Azure AD server principals (logins) and authentication events is supported.
  • 屬於 sysadmin 伺服器角色成員的 Azure AD 伺服器主體 (登入) 支援專用管理員連線。Dedicated administrator connection for Azure AD server principals (logins) which are members of sysadmin server role is supported.
    • 透過 SQLCMD 公用程式和 SQL Server Management Studio 支援。Supported through SQLCMD Utility and SQL Server Management Studio.
  • 來自 Azure AD 伺服器主體 (登入) 的登入事件支援登入觸發程序。Logon triggers are supported for logon events coming from Azure AD server principals (logins).
  • Service Broker 和 DB 電子郵件可使用 Azure AD 伺服器主體 (登入) 來設定。Service Broker and DB mail can be setup using an Azure AD server principal (login).

使用 Azure AD 身分識別連接Connect by using Azure AD identities

Azure Active Directory 驗證支援下列方法,使用 Azure AD 身分識別連接至資料庫:Azure Active Directory authentication supports the following methods of connecting to a database using Azure AD identities:

  • Azure Active Directory 密碼Azure Active Directory Password
  • Azure Active Directory 整合式Azure Active Directory Integrated
  • 使用 Multi-Factor Authentication Azure Active Directory 通用Azure Active Directory Universal with Multi-Factor Authentication
  • 使用應用程式權杖驗證Using Application token authentication

Azure AD 伺服器主體 (登入) 支援下列驗證方法:The following authentication methods are supported for Azure AD server principals (logins):

  • Azure Active Directory 密碼Azure Active Directory Password
  • Azure Active Directory 整合式Azure Active Directory Integrated
  • 使用 Multi-Factor Authentication Azure Active Directory 通用Azure Active Directory Universal with Multi-Factor Authentication

其他考量Additional considerations

  • 若要增強管理性,建議您以系統管理員身分佈建專用的 Azure AD 群組。To enhance manageability, we recommend you provision a dedicated Azure AD group as an administrator.
  • 只有一個 Azure AD 系統管理員 (可以在 SQL Database 或 Azure Synapse 中設定伺服器的使用者或群組) 。Only one Azure AD administrator (a user or group) can be configured for a server in SQL Database or Azure Synapse at any time.
    • Azure AD 伺服器主體 (登入) 的 SQL 受控執行個體,可讓您建立多個 Azure AD 伺服器主體 (可新增至角色的登入) sysadminThe addition of Azure AD server principals (logins) for SQL Managed Instance allows the possibility of creating multiple Azure AD server principals (logins) that can be added to the sysadmin role.
  • 只有伺服器的 Azure AD 系統管理員可以一開始使用 Azure Active Directory 帳戶連接到伺服器或受控實例。Only an Azure AD administrator for the server can initially connect to the server or managed instance using an Azure Active Directory account. Active Directory 系統管理員可以設定後續的 Azure AD 資料庫使用者。The Active Directory administrator can configure subsequent Azure AD database users.
  • 建議將連接逾時設定為 30 秒。We recommend setting the connection timeout to 30 seconds.
  • SQL Server 2016 Management Studio 和 SQL Server Data Tools for Visual Studio 2015 (版本 14.0.60311.1 (2016 年 4 月) 或更新版本) 支援 Azure Active Directory 驗證。SQL Server 2016 Management Studio and SQL Server Data Tools for Visual Studio 2015 (version 14.0.60311.1April 2016 or later) support Azure Active Directory authentication. ( .NET Framework Data Provider for SqlServer 支援 Azure AD 驗證,最低版本 .NET Framework 4.6)。(Azure AD authentication is supported by the .NET Framework Data Provider for SqlServer; at least version .NET Framework 4.6). 因此,這些工具和資料層應用程式的最新版本 (DAC 和 BACPAC) 可以使用 Azure AD 驗證。Therefore the newest versions of these tools and data-tier applications (DAC and BACPAC) can use Azure AD authentication.
  • 從版本15.0.1 版開始, sqlcmd 公用程式bcp 公用程式 支援 Active Directory Multi-Factor Authentication 的互動式驗證。Beginning with version 15.0.1, sqlcmd utility and bcp utility support Active Directory Interactive authentication with Multi-Factor Authentication.
  • SQL Server Data Tools for Visual Studio 2015 至少需要 2016 年 4 月版本的 Data Tools (版本 14.0.60311.1)。SQL Server Data Tools for Visual Studio 2015 requires at least the April 2016 version of the Data Tools (version 14.0.60311.1). Azure AD 的使用者目前不會顯示在 SSDT 物件總管中。Currently, Azure AD users are not shown in SSDT Object Explorer. 解決方法是在 sys.database_principals 中檢視使用者。As a workaround, view the users in sys.database_principals.
  • Microsoft JDBC Driver 6.0 for SQL Server 支援 Azure AD 驗證。Microsoft JDBC Driver 6.0 for SQL Server supports Azure AD authentication. 此外,請參閱 設定連接屬性Also, see Setting the Connection Properties.
  • PolyBase 無法使用 Azure AD 驗證進行驗證。PolyBase cannot authenticate by using Azure AD authentication.
  • 使用 Azure 入口網站匯 入資料庫匯出資料庫 blade,可支援 Azure SQL Database 和 Azure Synapse 的 Azure AD 驗證。Azure AD authentication is supported for Azure SQL Database and Azure Synapse by using the Azure portal Import Database and Export Database blades. PowerShell 命令也支援使用 Azure AD 驗證的匯入和匯出。Import and export using Azure AD authentication is also supported from a PowerShell command.
  • 使用 CLI 可支援 SQL Database、SQL 受控執行個體和 Azure Synapse 的 Azure AD 驗證。Azure AD authentication is supported for SQL Database, SQL Managed Instance, and Azure Synapse with using the CLI. 如需詳細資訊,請參閱使用 SQL Database 或 Azure Synapse 和SQL Server-az SQL Server設定和管理 Azure AD authenticationFor more information, see Configure and manage Azure AD authentication with SQL Database or Azure Synapse and SQL Server - az sql server.

下一步Next steps