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
+54-57Lines changed: 54 additions & 57 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 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.
89
96
90
-
![Screenshot that shows selections for setting an Azure AD admin during server provisioning.][3]
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.
91
99
92
100
To set the Azure AD administrator after server creation, follow these steps:
93
101
@@ -96,18 +104,14 @@ To set the Azure AD administrator after server creation, follow these steps:
96
104
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
105
1. Select **Save**.
98
106
99
-
![Screenshot that shows selections for setting an Azure AD admin after server creation.][2]
100
-
101
107
> [!IMPORTANT]
102
-
> When you're setting the administrator, a new user is added to Azure Database for PostgreSQL - Flexible Server with full administrator permissions.
108
+
> When setting the administrator, a new user is added to Azure Database for PostgreSQL - Flexible Server with full administrator permissions.
103
109
104
110
## Connect to Azure Database for PostgreSQL by using Azure AD
105
111
106
112
The following high-level diagram summarizes the workflow of using Azure AD authentication with Azure Database for PostgreSQL:
107
113
108
-
![Diagram of authentication flow between Azure Active Directory, the user's computer, and the server.][1]
109
-
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.
114
+
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
115
112
116
We've tested the following clients:
113
117
@@ -118,7 +122,7 @@ We've tested the following clients:
118
122
119
123
## Authenticate with Azure AD
120
124
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.
125
+
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
126
123
127
### Sign in to the user's Azure subscription
124
128
@@ -132,7 +136,7 @@ The command opens a browser window to the Azure AD authentication page. It requi
132
136
133
137
### Retrieve the Azure AD access token
134
138
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:
139
+
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
140
137
141
```azurecli-interactive
138
142
az account get-access-token --resource https://ossrdbms-aad.database.windows.net
@@ -166,9 +170,9 @@ The token is a Base64 string. It encodes all the information about the authentic
166
170
167
171
### Use a token as a password for signing in with client psql
168
172
169
-
When you're connecting, it's best to use the access token as the PostgreSQL user password.
173
+
When connecting, it's best to use the access token as the PostgreSQL user password.
170
174
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.
175
+
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
176
173
177
Here's a Windows example:
174
178
@@ -182,20 +186,19 @@ $env:PGPASSWORD='<copy/pasted TOKEN value from step 2>'
182
186
183
187
Here's a Linux/macOS example:
184
188
185
-
```shell
189
+
```bash
186
190
export PGPASSWORD=<copy/pasted TOKEN value from step 2>
187
191
```
188
192
189
193
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.
218
+
- If the name contains spaces, use a backslash (`\`) before each space to escape it.
219
+
- 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
220
218
221
You're now authenticated to your Azure Database for PostgreSQL server through Azure AD authentication.
219
222
220
223
## Authenticate with Azure AD as a group member
221
224
222
225
### Create Azure AD groups in Azure Database for PostgreSQL - Flexible Server
223
226
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:
227
+
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
228
226
-
```
229
+
```sql
227
230
select*from pgAzure ADauth_create_principal('Prod DB Readonly', false, false).
228
231
```
229
232
230
-
When group members sign in, they use their personal access tokens but specify the group name as the username.
233
+
When group members sign in, they use their access tokens but specify the group name as the username.
231
234
232
235
> [!NOTE]
233
236
> Azure Database for PostgreSQL - Flexible Server supports managed identities as group members.
@@ -236,19 +239,19 @@ When group members sign in, they use their personal access tokens but specify th
236
239
237
240
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
241
239
-
```
242
+
```azurecli-interactive
240
243
az login
241
244
```
242
245
243
246
### Retrieve the Azure AD access token
244
247
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:
248
+
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
249
247
250
```azurecli-interactive
248
251
az account get-access-token --resource https://ossrdbms-aad.database.windows.net
249
252
```
250
253
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:
254
+
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
255
253
256
```azurecli-interactive
254
257
az cloud show
@@ -274,23 +277,17 @@ After authentication is successful, Azure AD returns an access token:
274
277
275
278
### Use a token as a password for signing in with psql or PgAdmin
276
279
277
-
These considerations are important when you're connecting as a group member:
280
+
These considerations are essential when you're connecting as a group member:
278
281
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.
282
+
- The group name is the name of the Azure AD group that you're trying to connect.
283
+
- Be sure to use the exact way the Azure AD group name is spelled. Azure AD user and group names are case-sensitive.
281
284
- When you're connecting as a group, use only the group name and not the alias of a group member.
282
285
- 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.
286
+
- 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
287
285
288
You're now authenticated to your PostgreSQL server through Azure AD authentication.
286
289
287
290
## Next steps
288
291
289
292
- 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