Skip to content

Commit a65d645

Browse files
committed
Microsoft Entra content change
1 parent 8985f39 commit a65d645

File tree

3 files changed

+82
-78
lines changed

3 files changed

+82
-78
lines changed

docs/toc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8406,7 +8406,7 @@ items:
84068406
items:
84078407
- name: sqlcmd overview
84088408
href: tools/sqlcmd/sqlcmd-utility.md
8409-
- name: Authenticate sqlcmd with Azure AD
8409+
- name: Authenticate sqlcmd with Microsoft Entra ID
84108410
href: tools/sqlcmd/sqlcmd-authentication.md
84118411
- name: Start the utility
84128412
href: tools/sqlcmd/sqlcmd-start-utility.md

docs/tools/sqlcmd/sqlcmd-authentication.md

Lines changed: 76 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,97 @@
11
---
2-
title: Azure Active Directory authentication in sqlcmd
3-
description: Authenticating with Azure Active Directory in the new standalone sqlcmd utility.
2+
title: Authenticate with Microsoft Entra ID in sqlcmd
3+
description: Authenticating with Microsoft Entra ID in the new standalone sqlcmd utility.
44
author: dlevy-msft
55
ms.author: dlevy
66
ms.reviewer: randolphwest
7-
ms.date: 08/15/2023
7+
ms.date: 12/13/2023
88
ms.service: sql
99
ms.subservice: tools-other
1010
ms.topic: conceptual
1111
monikerRange: ">=aps-pdw-2016 || =azuresqldb-current || =azure-sqldw-latest || >=sql-server-2016 || >=sql-server-linux-2017"
1212
---
13-
# Azure Active Directory authentication in sqlcmd
13+
# Authenticate with Microsoft Entra ID in sqlcmd
1414

1515
[!INCLUDE [sql-asdb-asdbmi-asa-pdw](../../includes/applies-to-version/sql-asdb-asdbmi-asa-pdw.md)]
1616

17-
**sqlcmd** supports a variety of Azure Active Directory (Azure AD) authentication models, depending on which version you have installed.
17+
**sqlcmd** supports a variety of Microsoft Entra authentication models, depending on which version you have installed.
18+
19+
[!INCLUDE [entra-id-hard-coded](../../includes/entra-id-hard-coded.md)]
1820

1921
For more information on the difference between **sqlcmd** versions, see [sqlcmd utility](sqlcmd-utility.md#find-out-which-version-you-have-installed).
2022

23+
## [sqlcmd (Go)](#tab/go)
24+
25+
**sqlcmd** (Go) supports more Microsoft Entra authentication models, based on the [azidentity package](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azidentity). The implementation relies on a Microsoft Entra connector in the [go-sqlcmd driver](https://github.com/microsoft/go-mssqldb).
26+
27+
### Command line arguments
28+
29+
To use Microsoft Entra authentication, you can use one of two command line switches.
30+
31+
`-G` is (mostly) compatible with its usage in **sqlcmd** (ODBC). If a username and password are provided, it authenticates using Microsoft Entra password authentication. If a user name is provided, it uses Microsoft Entra interactive authentication, which may display a web browser. If no username or password is provided, it uses a `DefaultAzureCredential`, which attempts to authenticate through various mechanisms.
32+
33+
`--authentication-method=` can be used to specify one of the following authentication types.
34+
35+
#### ActiveDirectoryDefault
36+
37+
- For an overview of the types of authentication this mode uses, see [Default Azure Credential](https://github.com/Azure/azure-sdk-for-go/tree/main/sdk/azidentity#defaultazurecredential).
38+
- Choose this method if your database automation scripts are intended to run in both local development environments and in a production deployment in Azure. In your development environment, you can use a client secret or an Azure CLI login. Without changing the script from the development environment, you can use a managed identity or client secret on your production deployment.
39+
- Setting environment variables `AZURE_TENANT_ID` and `AZURE_CLIENT_ID` are necessary for `DefaultAzureCredential` to begin checking the environment configuration and look for one of the following additional environment variables in order to authenticate:
40+
- Setting environment variable `AZURE_CLIENT_SECRET` configures the `DefaultAzureCredential` to choose `ClientSecretCredential`.
41+
- Setting environment variable `AZURE_CLIENT_CERTIFICATE_PATH` configures the `DefaultAzureCredential` to choose `ClientCertificateCredential` if `AZURE_CLIENT_SECRET` isn't set.
42+
- Setting environment variable AZURE_USERNAME configures the `DefaultAzureCredential` to choose `UsernamePasswordCredential` if `AZURE_CLIENT_SECRET` and `AZURE_CLIENT_CERTIFICATE_PATH` aren't set.
43+
44+
#### ActiveDirectoryIntegrated
45+
46+
This method is currently not implemented, and falls back to `ActiveDirectoryDefault`.
47+
48+
#### ActiveDirectoryPassword
49+
50+
- This method authenticates using a username and password. It doesn't work if MFA is required.
51+
52+
- You provide the user name and password using the usual command line switches or `SQLCMD` environment variables.
53+
54+
- Set `AZURE_TENANT_ID` environment variable to the tenant ID of the server if not using the default tenant of the user.
55+
56+
#### ActiveDirectoryInteractive
57+
58+
This method launches a web browser to authenticate the user.
59+
60+
#### ActiveDirectoryManagedIdentity
61+
62+
Use this method when running **sqlcmd** (Go) on an Azure VM that has either a system-assigned or user-assigned managed identity. If using a user-assigned managed identity, set the user name to the ID of the managed identity. If using a system-assigned identity, leave user name empty.
63+
64+
#### ActiveDirectoryServicePrincipal
65+
66+
This method authenticates the provided user name as a service principal ID and the password as the client secret for the service principal. Provide a user name in the form `<service principal id>@<tenant id>`. Set `SQLCMDPASSWORD` variable to the client secret. If using a certificate instead of a client secret, set `AZURE_CLIENT_CERTIFICATE_PATH` environment variable to the path of the certificate file.
67+
68+
### Environment variables for Microsoft Entra authentication
69+
70+
Some Microsoft Entra authentication settings don't have command line inputs, and some environment variables are consumed directly by the `azidentity` package used by **sqlcmd** (Go).
71+
72+
These environment variables can be set to configure some aspects of Microsoft Entra authentication and to bypass default behaviors. In addition to the variables listed previously, the following are specific to **sqlcmd** (Go), and apply to multiple methods.
73+
74+
#### SQLCMDCLIENTID
75+
76+
Set this environment variable to the identifier of an application registered in Microsoft Entra, which is authorized to authenticate to Azure SQL Database. Applies to `ActiveDirectoryInteractive` and `ActiveDirectoryPassword` methods.
77+
2178
## [sqlcmd (ODBC)](#tab/odbc)
2279

23-
The `-G` option is used by **sqlcmd** (ODBC) when connecting to Azure SQL Database or Azure Synapse Analytics, to specify that the user be authenticated using Azure AD authentication. This option sets the **sqlcmd** scripting variable `SQLCMDUSEAAD=true`.
80+
The `-G` option is used by **sqlcmd** (ODBC) when connecting to Azure SQL Database or Azure Synapse Analytics, to specify that the user be authenticated using Microsoft Entra authentication. This option sets the **sqlcmd** scripting variable `SQLCMDUSEAAD=true`.
2481

25-
- The `-G` option requires at least **sqlcmd** version [13.1](https://go.microsoft.com/fwlink/?LinkID=825643). Azure AD interactive authentication requires **sqlcmd** (ODBC) [version 15.0.1000.34](sqlcmd-utility.md#download-and-install-sqlcmd) and later versions, as well as [ODBC version 17.2 and later versions](../../connect/odbc/download-odbc-driver-for-sql-server.md).
82+
- The `-G` option requires at least **sqlcmd** version [13.1](https://go.microsoft.com/fwlink/?LinkID=825643). Microsoft Entra interactive authentication requires **sqlcmd** (ODBC) [version 15.0.1000.34](sqlcmd-utility.md#download-and-install-sqlcmd) and later versions, as well as [ODBC version 17.2 and later versions](../../connect/odbc/download-odbc-driver-for-sql-server.md).
2683

27-
- Azure AD integrated authentication requires [Microsoft ODBC Driver 17 for SQL Server](../../connect/odbc/download-odbc-driver-for-sql-server.md) version 17.6.1 and later versions, and a properly [configured Kerberos environment](../../connect/odbc/linux-mac/using-integrated-authentication.md).
84+
- Microsoft Entra integrated authentication requires [Microsoft ODBC Driver 17 for SQL Server](../../connect/odbc/download-odbc-driver-for-sql-server.md) version 17.6.1 and later versions, and a properly [configured Kerberos environment](../../connect/odbc/linux-mac/using-integrated-authentication.md).
2885

2986
- The `-G` option only applies to Azure SQL Database and Azure Synapse Analytics.
3087

31-
- Azure AD interactive authentication isn't currently supported on Linux or macOS.
88+
- Microsoft Entra interactive authentication isn't currently supported on Linux or macOS.
3289

3390
To determine your version, execute `sqlcmd "-?"`. For more information, see [Connecting to SQL Database or Azure Synapse Analytics By Using Azure Active Directory Authentication](/azure/azure-sql/database/authentication-aad-overview). The `-A` option isn't supported with the `-G` option.
3491

35-
### Azure Active Directory username and password
92+
### Microsoft Entra username and password
3693

37-
When you want to use an Azure AD user name and password, you can provide the `-G` option with the user name and password, by using the `-U` and `-P` options.
94+
When you want to use an Microsoft Entra user name and password, you can provide the `-G` option with the user name and password, by using the `-U` and `-P` options.
3895

3996
```console
4097
sqlcmd -S testsrv.database.windows.net -d Target_DB_or_DW -U bob@contoso.com -P MyAzureADPassword -G
@@ -46,9 +103,9 @@ The `-G` parameter generates the following connection string in the backend:
46103
SERVER = Target_DB_or_DW.testsrv.database.windows.net;UID=bob@contoso.com;PWD=MyAzureADPassword;AUTHENTICATION=ActiveDirectoryPassword;
47104
```
48105

49-
### Azure Active Directory integrated authentication
106+
### Microsoft Entra integrated authentication
50107

51-
For Azure AD integrated authentication, provide the `-G` option without a user name or password.
108+
For Microsoft Entra integrated authentication, provide the `-G` option without a user name or password.
52109

53110
```console
54111
sqlcmd -S Target_DB_or_DW.testsrv.database.windows.net -G
@@ -63,13 +120,13 @@ SERVER = Target_DB_or_DW.testsrv.database.windows.net;Authentication=ActiveDirec
63120
> [!NOTE]
64121
> The `-E` option (`Trusted_Connection`) cannot be used along with the `-G` option.
65122
66-
### Azure Active Directory interactive authentication
123+
### Microsoft Entra interactive authentication
67124

68-
The Azure AD interactive authentication for Azure SQL Database and Azure Synapse Analytics, allows you to use an interactive method supporting multi-factor authentication. For more information, see [Active Directory Interactive Authentication](../../ssdt/azure-active-directory.md#active-directory-interactive-authentication).
125+
The Microsoft Entra interactive authentication for Azure SQL Database and Azure Synapse Analytics, allows you to use an interactive method supporting multi-factor authentication. For more information, see [Active Directory Interactive Authentication](../../ssdt/azure-active-directory.md#active-directory-interactive-authentication).
69126

70127
To enable interactive authentication, provide the `-G` option with user name (`-U`) only, without a password.
71128

72-
The following example exports data using Azure AD interactive mode, indicating a username where the user represents an Azure AD account. This is the same example used in the previous section, **Azure Active Directory username and password**.
129+
The following example exports data using Microsoft Entra interactive mode, indicating a username where the user represents a Microsoft Entra account. This is the same example used in the previous section, **Microsoft Entra username and password**.
73130

74131
Interactive mode requires manually entering a password, or for accounts with multi-factor authentication enabled, complete your configured MFA authentication method.
75132

@@ -83,75 +140,20 @@ The previous command generates the following connection string in the backend:
83140
SERVER = Target_DB_or_DW.testsrv.database.windows.net;UID=alice@aadtest.onmicrosoft.com;AUTHENTICATION=ActiveDirectoryInteractive
84141
```
85142

86-
In case an Azure AD user is a domain federated user using a Windows account, the user name required in the command-line contains its domain account (for example `joe@contoso.com`):
143+
In case a Microsoft Entra user is a domain federated user using a Windows account, the user name required in the command-line contains its domain account (for example `joe@contoso.com`):
87144

88145
```console
89146
sqlcmd -S testsrv.database.windows.net -d Target_DB_or_DW -G -U joe@contoso.com
90147
```
91148

92-
If guest users exist in a specific Azure AD tenant, and are part of a group that exists in Azure SQL Database that has database permissions to execute the **sqlcmd** command, their guest user alias is used (for example, `keith0@adventureworks.com`).
149+
If guest users exist in a specific Microsoft Entra tenant, and are part of a group that exists in Azure SQL Database that has database permissions to execute the **sqlcmd** command, their guest user alias is used (for example, `keith0@adventureworks.com`).
93150

94151
> [!IMPORTANT]
95152
> There is a known issue when using the `-G` and `-U` option with **sqlcmd** (ODBC), where putting the `-U` option before the `-G` option may cause authentication to fail. Always start with the `-G` option followed by the `-U` option.
96153
97-
## [sqlcmd (Go)](#tab/go)
98-
99-
**sqlcmd** (Go) supports more Azure AD authentication models, based on the [azidentity package](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azidentity). The implementation relies on an Azure AD connector in the [go-sqlcmd driver](https://github.com/microsoft/go-mssqldb).
100-
101-
### Command line arguments
102-
103-
To use Azure AD authentication, you can use one of two command line switches.
104-
105-
`-G` is (mostly) compatible with its usage in **sqlcmd** (ODBC). If a username and password are provided, it authenticates using Azure AD Password authentication. If a user name is provided, it uses Azure AD Interactive authentication, which may display a web browser. If no username or password is provided, it uses a `DefaultAzureCredential`, which attempts to authenticate through various mechanisms.
106-
107-
`--authentication-method=` can be used to specify one of the following authentication types.
108-
109-
#### ActiveDirectoryDefault
110-
111-
- For an overview of the types of authentication this mode uses, see [Default Azure Credential](https://github.com/Azure/azure-sdk-for-go/tree/main/sdk/azidentity#defaultazurecredential).
112-
- Choose this method if your database automation scripts are intended to run in both local development environments and in a production deployment in Azure. In your development environment, you can use a client secret or an Azure CLI login. Without changing the script from the development environment, you can use a managed identity or client secret on your production deployment.
113-
- Setting environment variables `AZURE_TENANT_ID` and `AZURE_CLIENT_ID` are necessary for `DefaultAzureCredential` to begin checking the environment configuration and look for one of the following additional environment variables in order to authenticate:
114-
- Setting environment variable `AZURE_CLIENT_SECRET` configures the `DefaultAzureCredential` to choose `ClientSecretCredential`.
115-
- Setting environment variable `AZURE_CLIENT_CERTIFICATE_PATH` configures the `DefaultAzureCredential` to choose `ClientCertificateCredential` if `AZURE_CLIENT_SECRET` isn't set.
116-
- Setting environment variable AZURE_USERNAME configures the `DefaultAzureCredential` to choose `UsernamePasswordCredential` if `AZURE_CLIENT_SECRET` and `AZURE_CLIENT_CERTIFICATE_PATH` aren't set.
117-
118-
#### ActiveDirectoryIntegrated
119-
120-
This method is currently not implemented, and falls back to `ActiveDirectoryDefault`.
121-
122-
#### ActiveDirectoryPassword
123-
124-
- This method authenticates using a username and password. It doesn't work if MFA is required.
125-
126-
- You provide the user name and password using the usual command line switches or `SQLCMD` environment variables.
127-
128-
- Set `AZURE_TENANT_ID` environment variable to the tenant ID of the server if not using the default tenant of the user.
129-
130-
#### ActiveDirectoryInteractive
131-
132-
This method launches a web browser to authenticate the user.
133-
134-
#### ActiveDirectoryManagedIdentity
135-
136-
Use this method when running **sqlcmd** (Go) on an Azure VM that has either a system-assigned or user-assigned managed identity. If using a user-assigned managed identity, set the user name to the ID of the managed identity. If using a system-assigned identity, leave user name empty.
137-
138-
#### ActiveDirectoryServicePrincipal
139-
140-
This method authenticates the provided user name as a service principal ID and the password as the client secret for the service principal. Provide a user name in the form `<service principal id>@<tenant id>`. Set `SQLCMDPASSWORD` variable to the client secret. If using a certificate instead of a client secret, set `AZURE_CLIENT_CERTIFICATE_PATH` environment variable to the path of the certificate file.
141-
142-
### Environment variables for Azure AD authentication
143-
144-
Some Azure AD authentication settings don't have command line inputs, and some environment variables are consumed directly by the `azidentity` package used by **sqlcmd** (Go).
145-
146-
These environment variables can be set to configure some aspects of Azure AD authentication and to bypass default behaviors. In addition to the variables listed previously, the following are specific to **sqlcmd** (Go), and apply to multiple methods.
147-
148-
#### SQLCMDCLIENTID
149-
150-
Set this environment variable to the identifier of an application registered in your Azure AD, which is authorized to authenticate to Azure SQL Database. Applies to `ActiveDirectoryInteractive` and `ActiveDirectoryPassword` methods.
151-
152154
---
153155

154-
## Next steps
156+
## Related content
155157

156158
- [sqlcmd utility](sqlcmd-utility.md)
157159
- [sqlcmd - Start the utility](sqlcmd-start-utility.md)

docs/tools/sqlcmd/sqlcmd-utility.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ The **sqlcmd** utility lets you enter Transact-SQL statements, system procedures
4343

4444
There are two versions of **sqlcmd**:
4545

46-
- The ODBC-based **sqlcmd**, available with [!INCLUDE [ssnoversion-md](../../includes/ssnoversion-md.md)] or the Microsoft Command Line Utilities, and part of the `mssql-tools` package on Linux.
47-
4846
- The `go-mssqldb`-based **sqlcmd**, sometimes styled as **go-sqlcmd**. This version is a standalone tool you can download independently of [!INCLUDE [ssnoversion-md](../../includes/ssnoversion-md.md)].
4947

48+
- The ODBC-based **sqlcmd**, available with [!INCLUDE [ssnoversion-md](../../includes/ssnoversion-md.md)] or the Microsoft Command Line Utilities, and part of the `mssql-tools` package on Linux.
49+
5050
To determine the version you have installed, run the following statement at the command line:
5151

5252
::: zone pivot="cs1-bash"
@@ -99,7 +99,9 @@ Copyright (C) 2022 Microsoft Corporation. All rights reserved.
9999

100100
You may have several versions of **sqlcmd** (ODBC) installed on your computer. Be sure you're using the correct version. You should have at least version 15.0.4298.1 installed.
101101

102-
Always Encrypted (`-g`) and Azure AD authentication (`-G`) require at least version 13.1.
102+
Always Encrypted (`-g`) and Microsoft Entra authentication (`-G`) require at least version 13.1.
103+
104+
[!INCLUDE [entra-id-hard-coded](../../includes/entra-id-hard-coded.md)]
103105

104106
---
105107

0 commit comments

Comments
 (0)