You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/postgresql/flexible-server/how-to-configure-sign-in-azure-ad-authentication.md
+60-55Lines changed: 60 additions & 55 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ description: Learn how to set up Azure Active Directory (Azure AD) for authentic
4
4
author: kabharati
5
5
ms.author: kabharati
6
6
ms.reviewer: maghan
7
-
ms.date: 11/04/2022
7
+
ms.date: 01/18/2023
8
8
ms.service: postgresql
9
9
ms.subservice: flexible-server
10
10
ms.topic: how-to
@@ -19,14 +19,14 @@ In this article, you'll configure Azure Active Directory (Azure AD) access for a
19
19
> [!NOTE]
20
20
> Azure Active Directory authentication for Azure Database for PostgreSQL - Flexible Server is currently in preview.
21
21
22
-
You can configure Azure AD authentication for Azure Database for PostgreSQL - Flexible Server either during server provisioning or later. Only Azure AD administrator users can create or enable users for Azure AD-based authentication. We recommend not using the Azure AD administrator for regular database operations, because that role has elevated user permissions (for example, CREATEDB).
22
+
You can configure Azure AD authentication for Azure Database for PostgreSQL - Flexible Server either during server provisioning or later. Only Azure AD administrator users can create or enable users for Azure AD-based authentication. We recommend not using the Azure AD administrator for regular database operations because that role has elevated user permissions (for example, CREATEDB).
23
23
24
-
You can have multiple Azure AD admin users with Azure Database for PostgreSQL - Flexible Server. Azure AD admin users can be a user, a group, or a service principal.
24
+
You can have multiple Azure AD admin users with Azure Database for PostgreSQL - Flexible Server. Azure AD admin users can be a user, a group, or service principal.
25
25
26
26
## Prerequisites
27
27
28
28
- An Azure account with an active subscription. If you don't already have one, [create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
29
-
- One of the following roles: Global Administrator, Privileged Role Administrator, Tenant Administrator.
29
+
- One of the following roles: **Global Administrator**, **Privileged Role Administrator**, **Tenant Creator**.
30
30
- Installation of the [Azure CLI](/cli/azure/install-azure-cli).
31
31
32
32
## Install the Azure AD PowerShell module
@@ -38,28 +38,38 @@ The following steps are mandatory to use Azure AD authentication with Azure Data
38
38
```powershell
39
39
Connect-AzureAD -TenantId <customer tenant id>
40
40
```
41
-
A successful output will look similar to the following.
[email protected] AzureCloud 456e5515-431d-4a70-874d-bdae2ba97c1d <your tenant name>.onmicrosoft.com User
47
-
```
42
+
A successful output looks similar to the following.
48
43
49
-
Ensure that your Azure tenant has the service principal for the Azure Database for PostgreSQL Flexible Server. This only needs to be done once per Azure tenant. First, check for the existence of the service principal in your tenant with this command. The specific ObjectId value is for the Azure Database for PostgreSQL Flexible Server service principal.
Ensure that your Azure tenant has the service principal for the Azure Database for PostgreSQL Flexible Server. This only needs to be done once per Azure tenant. First, check for the existence of the service principal in your tenant with this command. The ObjectId value is for the Azure Database for PostgreSQL Flexible Server service principal.
51
+
52
+
> [!NOTE]
53
+
> The following script is an example of a created Azure App Registration you can use for testing. If you want to apply your ids, you need to use your own App Registration object and application id.
If the service principal exists, you'll see the following output.
54
-
```
60
+
61
+
```output
55
62
ObjectId AppId DisplayName
56
63
-------- ----- -----------
57
64
0049e2e2-fcea-4bc4-af90-bdb29a9bbe98 5657e26c-cc92-45d9-bc47-9da6cfdb4ed9 Azure OSSRDBMS PostgreSQL Flexible Server
58
65
```
59
66
67
+
> [!IMPORTANT]
68
+
> If you are not a **Global Administrator**, **Privileged Role Administrator**, **Tenant Creator** you can't proceed past this step.
69
+
60
70
### Grant read access
61
71
62
-
Grant Azure Database for PostgreSQL - Flexible Server Service Principal read access to a customer tenant, to request Graph API tokens for Azure AD validation tasks:
72
+
Grant Azure Database for PostgreSQL - Flexible Server Service Principal read access to a customer tenant to request Graph API tokens for Azure AD validation tasks:
- You need an outbound network security group (NSG) rule to allow virtual network traffic to reach the `AzureActiveDirectory` service tag only.
78
-
- Optionally, if you're using a proxy, you can add a new firewall rule to allow HTTP/S traffic to reach the `AzureActiveDirectory` service tag only.
87
+
- You need an outbound network security group (NSG) rule to allow virtual network traffic to only reach the `AzureActiveDirectory` service tag.
88
+
- Optionally, if you're using a proxy, you can add a new firewall rule to allow HTTP/S traffic to reach only the `AzureActiveDirectory` service tag.
79
89
80
90
To set the Azure AD admin during server provisioning, follow these steps:
81
91
82
92
1. In the Azure portal, during server provisioning, select either **PostgreSQL and Azure Active Directory authentication** or **Azure Active Directory authentication only** as the authentication method.
83
93
1. On the **Set admin** tab, select a valid Azure AD user, group, service principal, or managed identity in the customer tenant to be the Azure AD administrator.
84
-
85
-
You can optionally add a local PostgreSQL admin account if you prefer using the **PostgreSQL and Azure Active Directory authentication** method.
86
94
87
-
> [!NOTE]
88
-
> You can add only one Azure admin user during server provisioning. You can add multiple Azure AD admin users after the server is created.
95
+
You can optionally add a local PostgreSQL admin account if you prefer using the **PostgreSQL and Azure Active Directory authentication** method.
96
+
97
+
> [!NOTE]
98
+
> You can add only one Azure admin user during server provisioning. You can add multiple Azure AD admin users after the Server is created.
99
+
100
+
101
+
:::image type="content" source="media/how-to-configure-sign-in-Azure-ad-authentication/set-Azure-ad-admin-server-creation.png" alt-text="Screenshot that shows selections for setting an Azure AD admin during server provisioning.]":::
89
102
90
-
![Screenshot that shows selections for setting an Azure AD admin during server provisioning.][3]
91
103
92
104
To set the Azure AD administrator after server creation, follow these steps:
93
105
@@ -96,18 +108,18 @@ To set the Azure AD administrator after server creation, follow these steps:
96
108
1. Select **Add Azure AD Admins**. Then select a valid Azure AD user, group, service principal, or managed identity in the customer tenant to be an Azure AD administrator.
97
109
1. Select **Save**.
98
110
99
-
![Screenshot that shows selections for setting an Azure AD admin after server creation.][2]
111
+
:::image type="content" source="media/how-to-configure-sign-in-Azure-ad-authentication/set-Azure-ad-admin.png" alt-text="Screenshot that shows selections for setting an Azure AD admin after server creation.":::
100
112
101
113
> [!IMPORTANT]
102
-
> When you're setting the administrator, a new user is added to Azure Database for PostgreSQL - Flexible Server with full administrator permissions.
114
+
> When setting the administrator, a new user is added to Azure Database for PostgreSQL - Flexible Server with full administrator permissions.
103
115
104
116
## Connect to Azure Database for PostgreSQL by using Azure AD
105
117
106
118
The following high-level diagram summarizes the workflow of using Azure AD authentication with Azure Database for PostgreSQL:
107
119
108
-
![Diagram of authentication flow between Azure Active Directory, the user's computer, and the server.][1]
120
+
:::image type="content" source="media/how-to-configure-sign-in-Azure-ad-authentication/authentication-flow.png" alt-text="Diagram of authentication flow between Azure Active Directory, the user's computer, and the server.":::
109
121
110
-
Azure AD integration works with standard PostgreSQL tools like psql, which aren't Azure AD aware and support only specifying the username and password when you're connecting to PostgreSQL. The Azure AD token is passed as the password, as shown in the preceding diagram.
122
+
Azure AD integration works with standard PostgreSQL tools like psql, which aren't Azure AD aware and support only specifying the username and password when you're connecting to PostgreSQL. As shown in the preceding diagram, the Azure AD token is passed as the password.
111
123
112
124
We've tested the following clients:
113
125
@@ -118,7 +130,7 @@ We've tested the following clients:
118
130
119
131
## Authenticate with Azure AD
120
132
121
-
Use the following procedures to authenticate with Azure AD as an Azure Database for PostgreSQL - Flexible Server user. You can follow along in Azure Cloud Shell, on an Azure virtual machine, or on your local machine.
133
+
Use the following procedures to authenticate with Azure AD as an Azure Database for PostgreSQL - Flexible Server user. You can follow along in Azure Cloud Shell, on an Azure virtual machine, or on your local machine.
122
134
123
135
### Sign in to the user's Azure subscription
124
136
@@ -132,7 +144,7 @@ The command opens a browser window to the Azure AD authentication page. It requi
132
144
133
145
### Retrieve the Azure AD access token
134
146
135
-
Use the Azure CLI to acquire an access token for the Azure AD authenticated user to access Azure Database for PostgreSQL. Here's an example for the public cloud:
147
+
Use the Azure CLI to acquire an access token for the Azure AD authenticated user to access Azure Database for PostgreSQL. Here's an example of the public cloud:
136
148
137
149
```azurecli-interactive
138
150
az account get-access-token --resource https://ossrdbms-aad.database.windows.net
@@ -166,9 +178,9 @@ The token is a Base64 string. It encodes all the information about the authentic
166
178
167
179
### Use a token as a password for signing in with client psql
168
180
169
-
When you're connecting, it's best to use the access token as the PostgreSQL user password.
181
+
When connecting, it's best to use the access token as the PostgreSQL user password.
170
182
171
-
While you're using the psql command-line client, the access token needs to be passed through the `PGPASSWORD` environment variable. The reason is that the access token exceeds the password length that psql can accept directly.
183
+
While using the psql command-line client, the access token needs to be passed through the `PGPASSWORD` environment variable. The reason is that the access token exceeds the password length that psql can accept directly.
172
184
173
185
Here's a Windows example:
174
186
@@ -182,20 +194,19 @@ $env:PGPASSWORD='<copy/pasted TOKEN value from step 2>'
182
194
183
195
Here's a Linux/macOS example:
184
196
185
-
```shell
197
+
```bash
186
198
export PGPASSWORD=<copy/pasted TOKEN value from step 2>
187
199
```
188
200
189
201
You can also combine step 2 and step 3 together using command substitution. The token retrieval can be encapsulated into a variable and passed directly as a value for `PGPASSWORD` environment variable:
* Be sure to use the exact way that the Azure user is spelled. Azure AD user and group names are case-sensitive.
215
-
* If the name contains spaces, use a backslash (`\`) before each space to escape it.
216
-
* The access token's validity is 5 minutes to 60 minutes. We recommend that you get the access token just before you initiate the sign-in to Azure Database for PostgreSQL.
- Be sure to use the exact way the Azure user is spelled. Azure AD user and group names are case-sensitive.
226
+
- If the name contains spaces, use a backslash (`\`) before each space to escape it.
227
+
- The access token's validity is 5 minutes to 60 minutes. You should get the access token before initiating the sign-in to Azure Database for PostgreSQL.
217
228
218
229
You're now authenticated to your Azure Database for PostgreSQL server through Azure AD authentication.
219
230
220
231
## Authenticate with Azure AD as a group member
221
232
222
233
### Create Azure AD groups in Azure Database for PostgreSQL - Flexible Server
223
234
224
-
To enable an Azure AD group for access to your database, use the same mechanism that you used for users, but instead specify the group name. For example:
235
+
To enable an Azure AD group to access your database, use the same mechanism you used for users, but specify the group name instead. For example:
225
236
226
-
```
237
+
```sql
227
238
select*from pgAzure ADauth_create_principal('Prod DB Readonly', false, false).
228
239
```
229
240
230
-
When group members sign in, they use their personal access tokens but specify the group name as the username.
241
+
When group members sign in, they use their access tokens but specify the group name as the username.
231
242
232
243
> [!NOTE]
233
244
> Azure Database for PostgreSQL - Flexible Server supports managed identities as group members.
@@ -236,19 +247,19 @@ When group members sign in, they use their personal access tokens but specify th
236
247
237
248
Authenticate with Azure AD by using the Azure CLI. This step isn't required in Azure Cloud Shell. The user needs to be a member of the Azure AD group.
238
249
239
-
```
250
+
```azurecli-interactive
240
251
az login
241
252
```
242
253
243
254
### Retrieve the Azure AD access token
244
255
245
-
Use the Azure CLI to acquire an access token for the Azure AD authenticated user to access Azure Database for PostgreSQL. Here's an example for the public cloud:
256
+
Use the Azure CLI to acquire an access token for the Azure AD authenticated user to access Azure Database for PostgreSQL. Here's an example of the public cloud:
246
257
247
258
```azurecli-interactive
248
259
az account get-access-token --resource https://ossrdbms-aad.database.windows.net
249
260
```
250
261
251
-
You must specify the preceding resource value exactly as shown. For other clouds, you can look up the resource value by using the following command:
262
+
You must specify the initial resource value exactly as shown. For other clouds, you can look up the resource value by using the following command:
252
263
253
264
```azurecli-interactive
254
265
az cloud show
@@ -274,23 +285,17 @@ After authentication is successful, Azure AD returns an access token:
274
285
275
286
### Use a token as a password for signing in with psql or PgAdmin
276
287
277
-
These considerations are important when you're connecting as a group member:
288
+
These considerations are essential when you're connecting as a group member:
278
289
279
-
- The group name is the name of the Azure AD group that you're trying to connect as.
280
-
- Be sure to use the exact way that the Azure AD group name is spelled. Azure AD user and group names are case-sensitive.
290
+
- The group name is the name of the Azure AD group that you're trying to connect.
291
+
- Be sure to use the exact way the Azure AD group name is spelled. Azure AD user and group names are case-sensitive.
281
292
- When you're connecting as a group, use only the group name and not the alias of a group member.
282
293
- If the name contains spaces, use a backslash (`\`) before each space to escape it.
283
-
- The access token's validity is 5 minutes to 60 minutes. We recommend that you get the access token just before you initiate the sign-in to Azure Database for PostgreSQL.
294
+
- The access token's validity is 5 minutes to 60 minutes. We recommend you get the access token before initiating the sign-in to Azure Database for PostgreSQL.
284
295
285
296
You're now authenticated to your PostgreSQL server through Azure AD authentication.
286
297
287
298
## Next steps
288
299
289
300
- Review the overall concepts for [Azure AD authentication with Azure Database for PostgreSQL - Flexible Server](concepts-azure-ad-authentication.md).
290
-
- Learn how to [Manage Azure Active Directory users - Azure Database for PostgreSQL - Flexible Server](how-to-manage-azure-ad-users.md).
0 commit comments