Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Applies to:
Azure SQL Managed Instance
In this article, you learn about:
- Configuration options for SQL Managed Instance that enable users to perform administrative tasks and access data stored in these databases.
- Access and authorization configuration after creating a new server.
- How to add logins and user accounts in the
masterdatabase and then grant these accounts administrative permissions. - How to add user accounts in user databases, either associated with logins or as contained user accounts.
- How to configure user accounts with permissions in user databases by using database roles and explicit permissions.
- For Azure SQL Database, see Authorize database access to SQL Database.
- For Azure Synapse Analytics, see Authorize database access to Azure Synapse Analytics.
Note
Microsoft Entra ID was previously known as Azure Active Directory (Azure AD).
Authentication and authorization
Authentication is the process of proving the user is who they claim to be. A user connects to a database using a user account.
When a user attempts to connect to a database, they provide a user account and authentication information. The user is authenticated using one of the following two authentication methods:
-
By using this authentication method, the user submits a user account name and associated password to establish a connection. The
masterdatabase stores this password for user accounts linked to a login. The database containing the user accounts not linked to a login stores the password.Note
For password policy in Azure SQL Managed Instance, see Azure SQL Managed Instance frequently asked questions (FAQ).
Microsoft Entra authentication for Azure SQL
By using this authentication method, the user submits a user account name and requests that the service use the credential information stored in Microsoft Entra ID (formerly Azure Active Directory).
Logins and users: You can associate a user account in a database with a login that the master database stores, or you can make it a user name that an individual database stores.
- A login is an account in the
masterdatabase, to which you can link a user account in one or more databases. By using a login, you store the credential information for the user account with the login. - A user account is an individual account in any database that might be, but doesn't have to be, linked to a login. By using a user account that isn't linked to a login, you store the credential information with the user account.
Authorization to access data and perform various actions is managed by using database roles and explicit permissions. Authorization refers to the permissions assigned to a user, and it determines what that user is allowed to do. Your user account's database role memberships and object-level permissions control authorization. As a best practice, grant users the least privileges necessary.
Existing logins and user accounts after creating a new database
When you first deploy an Azure SQL resource, specify a login name and a password for a special type of administrative login, the Server admin. During deployment, the following configuration of logins and users in the master and user databases occurs:
Important
Do not include any personal, sensitive, or confidential information in the server admin login name field. Data entered in this field is not considered customer data.
- The deployment process creates a SQL authentication login with administrative privileges by using the login name you specified. A login is an individual account for signing in to Azure SQL Managed Instance.
- The deployment process grants this authentication login full administrative permissions on all databases as a server-level principal. The authentication login has all available permissions and can't be limited. In a SQL Managed Instance, the deployment process adds this authentication login to the sysadmin fixed server role.
- When this account signs into a database, it matches to the special user account
dbo(user account), which exists in each user database. The dbo user has all database permissions in the database and is member of thedb_ownerfixed database role. Additional fixed database roles are discussed later in this article.
To identify the Server admin account:
- Go to Azure SQL hub at aka.ms/azuresqlhub.
- In the resource menu, go to your SQL managed instance.
- Under Settings, select the Properties page.
- View the values for Server admin login or Microsoft Entra admin.
Important
You can't change the name of the Server admin account after you create it. To reset the password, go to the Azure portal, select your SQL managed instance, and select Reset password. You can also use PowerShell or the Azure CLI.
Create additional logins and users having administrative permissions
At this point, your SQL managed instance is only configured for a single SQL authentication login and user account. To create additional logins with full or partial administrative permissions, use the following options:
Create a Microsoft Entra administrator account with full administrative permissions
Enable Microsoft Entra authentication and add a Microsoft Entra admin. You can configure one Microsoft Entra account as an administrator of the Azure SQL deployment with full administrative permissions. This account can be either an individual or security group account. You must configure a Microsoft Entra admin if you want to use Microsoft Entra accounts to connect to Azure SQL Managed Instance. For detailed information on enabling Microsoft Entra authentication for all Azure SQL deployment types, see the following articles:
In SQL Managed Instance, create SQL authentication logins with full administrative permissions
- Create an additional SQL authentication login in the
masterdatabase.- Add the login to the sysadmin fixed server role by using the ALTER SERVER ROLE statement. This login has full administrative permissions.
- Alternatively, create a Microsoft Entra authentication login by using the CREATE LOGIN syntax.
Note
The
dbmanagerandloginmanagerroles don't pertain to Azure SQL Managed Instance deployments.- Create an additional SQL authentication login in the
Create accounts for nonadministrator users
Create accounts for nonadministrative users by using one of the following methods:
Create a login
Create a SQL authentication login in the
masterdatabase. Then create a user account in each database that the user needs access to and associate the user account with the login. Use this approach when the user needs to access multiple databases and you want to keep the passwords synchronized. However, this approach has complexities when used with geo-replication as the login must be created on both the primary server and the secondary servers.Create a user account
Create a user account in the database that a user needs access to.
With SQL Managed Instance supporting Microsoft Entra server principals, you can create user accounts to authenticate to the SQL Managed Instance without requiring database users to be created as a contained database user.
By using this approach, the user authentication information is stored in each database and automatically replicated to geo-replicated databases. However, if the same account exists in multiple databases and you're using SQL authentication, you must keep the passwords synchronized manually. Additionally, if a user has an account in different databases with different passwords, remembering those passwords can become a problem.
Important
To create contained users mapped to Microsoft Entra identities in SQL Managed Instance, use a SQL authentication login with sysadmin permissions to also create a Microsoft Entra authentication login or user.
For examples that show how to create logins and users, see:
Using fixed and custom database roles
After creating a user account in a database, either based on a login or as a contained user, you can authorize that user to perform various actions and to access data in a particular database. Use the following methods to authorize access:
Fixed database roles
Add the user account to a fixed database role. There are nine fixed database roles, each with a defined set of permissions. The most common fixed database roles are: db_owner, db_ddladmin, db_datawriter, db_datareader, db_denydatawriter, and db_denydatareader. Use db_owner to grant full permission to only a few users. The other fixed database roles are useful for getting a simple database in development quickly, but aren't recommended for most production databases. For example, the db_datareader fixed database role grants read access to every table in the database, which is more than is strictly necessary.
- To add a user to a fixed database role, use the ALTER ROLE statement. For examples, see ALTER ROLE examples.
Custom database role
Create a custom database role by using the CREATE ROLE statement. A custom role enables you to create your own user-defined database roles and carefully grant each role the least permissions necessary for the business need. Then add users to the custom role. When a user is a member of multiple roles, they aggregate the permissions of them all.
Grant permissions directly
Grant the user account permissions directly. There are over 100 permissions that you can individually grant or deny. Many of these permissions are nested. For example, the
UPDATEpermission on a schema includes theUPDATEpermission on each table within that schema. As in most permission systems, the denial of a permission overrides a grant. Because of the nested nature and the number of permissions, it can take careful study to design an appropriate permission system to properly protect your database. Start with the list of permissions at Permissions (Database Engine) and review the poster size graphic of the permissions.
Using groups
Efficient access management assigns permissions to Microsoft Entra security groups and fixed or custom roles instead of to individual users.
When using Microsoft Entra authentication, put Microsoft Entra users into a Microsoft Entra security group. Create a contained database user for the group. Add one or more database users as a member to custom or built-in database roles with the specific permissions appropriate to that group of users.
When using SQL authentication, create contained database users in the database. Place one or more database users into a custom database role with specific permissions appropriate to that group of users.
Note
You can also use groups for noncontained database users.
Familiarize yourself with the following features that can be used to limit or elevate permissions:
- Impersonation and module-signing can be used to securely elevate permissions temporarily.
- Row-Level Security can be used to limit which rows a user can access.
- Dynamic data masking can be used to limit exposure of sensitive data.
- Stored procedures can be used to limit the actions that can be taken on the database.