使用 Azure AD 创建 Azure SQL 数据库 login/user

Creating Azure SQL Database login/user using Azure AD

我的 Azure AD 中有两个用户 (name@company.com),他们已通过 Azure 门户获得了对 Azure 服务器的所有者权限。

首先,是否可以从 Azure AD 为这些登录凭据创建一个 links/pulls 的登录?我已经搜索过,但没有找到具体的答案,虽然我怀疑是没有。

其次,我已经为同一个数据库创建了 logins/users,但是,虽然对服务器的访问正常,但对数据库的访问被拒绝了。我已授予连接到登录名的权限,并已将 sp_addrolemember 作为数据库的每个数据读取器执行。在仔细检查我的工作时,我引用了几个示例,这些示例显示了我在 Azure logins/users 中使用的相同语法,但访问仍然被拒绝。

如有任何帮助,我们将不胜感激。

史蒂夫。

代码:

CREATE LOGIN [login_name]
   WITH PASSWORD = N'password'

CREATE USER [user_name]
   FROM LOGIN [login_name]
   WITH DEFAULT_SCHEMA = dbo

GO

GRANT CONNECT TO [user_name]

EXEC sp_addrolemember 'db_datareader', 'user_name'

First, is it possible to create a login that links/pulls from Azure AD for these login credentials? I've searched and haven't found a specific answer to this, though my suspicion is no.

没有。在 Azure SQL 数据库中,您只能使用在 Azure SQL 数据库中创建的用户和登录名 - SQL 登录名。

Second, I have created logins/users for the same database, however, while access to the server is fine, access to the database is denied. I have granted connect to the logins as well as executed sp_addrolemember as datareader to each for the database. In double checking my work, I had referenced several examples that show the same syntax I'm using for Azure logins/users, and yet access is still denied.

Logins 应该在主数据库 中创建 ,而 usersgrantssp_addrolemember 应该被执行在目标数据库的上下文中。如果您在 Master 数据库中执行 sp_addrolemember,您的用户将无法访问目标数据库。

此外,重要的是,当您尝试使用新登录名连接到数据库时(请注意,要登录到数据库,您使用的是 login 而不是 user),您必须明确 select 这个新用户可以访问的数据库!

我的大胆猜测是您在 master 数据库的上下文中执行了 create usergrantsp_addrolemember。因此,这些用户现在只能访问 master 数据库。当您处于 master 上下文中时,您不能向其他数据库授予显式授权。

您不能使用 AD 用户登录 SQL 服务器。必须在 master 数据库中创建登录名,您需要使用该登录名通过连接用户数据库来创建用户和权限授予。但是 SQL DB V12 支持包含的用户,您不再需要在 master 中创建登录。登录可以在用户数据库上下文中执行,如果您为 Azure 中的数据库设置地理复制(使用时间点还原功能进行还原),这将非常有用。根据我的经验,我会推荐 Azure 数据库中包含的用户。

可以使用 Azure AD 用户访问 Azure SQL 数据库: https://azure.microsoft.com/en-us/documentation/articles/sql-database-aad-authentication/