Skip to content

Commit 5c0cda8

Browse files
committed
[PostgreSQL] Update AAD article
1 parent a58965c commit 5c0cda8

File tree

1 file changed

+54
-57
lines changed

1 file changed

+54
-57
lines changed

articles/postgresql/flexible-server/how-to-configure-sign-in-azure-ad-authentication.md

Lines changed: 54 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: Learn how to set up Azure Active Directory (Azure AD) for authentic
44
author: kabharati
55
ms.author: kabharati
66
ms.reviewer: maghan
7-
ms.date: 11/04/2022
7+
ms.date: 01/18/2023
88
ms.service: postgresql
99
ms.subservice: flexible-server
1010
ms.topic: how-to
@@ -19,14 +19,14 @@ In this article, you'll configure Azure Active Directory (Azure AD) access for a
1919
> [!NOTE]
2020
> Azure Active Directory authentication for Azure Database for PostgreSQL - Flexible Server is currently in preview.
2121
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).
2323

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.
2525

2626
## Prerequisites
2727

2828
- 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**.
3030
- Installation of the [Azure CLI](/cli/azure/install-azure-cli).
3131

3232
## Install the Azure AD PowerShell module
@@ -38,28 +38,38 @@ The following steps are mandatory to use Azure AD authentication with Azure Data
3838
```powershell
3939
Connect-AzureAD -TenantId <customer tenant id>
4040
```
41-
A successful output will look similar to the following.
4241

43-
```
44-
Account Environment TenantId TenantDomain AccountType
45-
------- ----------- -------- ------------ -----------
46-
[email protected] AzureCloud 456e5515-431d-4a70-874d-bdae2ba97c1d <your tenant name>.onmicrosoft.com User
47-
```
42+
A successful output looks similar to the following.
4843

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.
44+
```output
45+
Account Environment TenantId TenantDomain AccountType
46+
------- ----------- -------- ------------ -----------
47+
<your account> AzureCloud <your tenant Id> <your tenant name>.onmicrosoft.com User
5048
```
51-
Get-AzureADServicePrincipal -ObjectId 0049e2e2-fcea-4bc4-af90-bdb29a9bbe98
49+
50+
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.
54+
55+
```powershell
56+
Get-AzureADServicePrincipal -ObjectId 97deb67a-332c-456a-9ef4-3a95eb59c74b
5257
```
58+
5359
If the service principal exists, you'll see the following output.
54-
```
60+
61+
```output
5562
ObjectId AppId DisplayName
5663
-------- ----- -----------
5764
0049e2e2-fcea-4bc4-af90-bdb29a9bbe98 5657e26c-cc92-45d9-bc47-9da6cfdb4ed9 Azure OSSRDBMS PostgreSQL Flexible Server
5865
```
5966

67+
> [!IMPORTANT]
68+
> If you are not a **Global Administrator**, **Privileged Role Administrator**, **Tenant Creator** you can't proceed past this step.
69+
6070
### Grant read access
6171

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:
6373

6474
```powershell
6575
New-AzureADServicePrincipal -AppId 5657e26c-cc92-45d9-bc47-9da6cfdb4ed9
@@ -74,20 +84,18 @@ Azure AD is a multitenant application. It requires outbound connectivity to perf
7484
- **Public access (allowed IP addresses)**: No extra network rules are required.
7585
- **Private access (virtual network integration)**:
7686

77-
- 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.
7989

8090
To set the Azure AD admin during server provisioning, follow these steps:
8191

8292
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.
8393
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.
8694

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.
8996

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.
9199
92100
To set the Azure AD administrator after server creation, follow these steps:
93101

@@ -96,18 +104,14 @@ To set the Azure AD administrator after server creation, follow these steps:
96104
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.
97105
1. Select **Save**.
98106

99-
![Screenshot that shows selections for setting an Azure AD admin after server creation.][2]
100-
101107
> [!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.
103109
104110
## Connect to Azure Database for PostgreSQL by using Azure AD
105111

106112
The following high-level diagram summarizes the workflow of using Azure AD authentication with Azure Database for PostgreSQL:
107113

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.
111115

112116
We've tested the following clients:
113117

@@ -118,7 +122,7 @@ We've tested the following clients:
118122

119123
## Authenticate with Azure AD
120124

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.
122126

123127
### Sign in to the user's Azure subscription
124128

@@ -132,7 +136,7 @@ The command opens a browser window to the Azure AD authentication page. It requi
132136

133137
### Retrieve the Azure AD access token
134138

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:
136140

137141
```azurecli-interactive
138142
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
166170

167171
### Use a token as a password for signing in with client psql
168172

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.
170174

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.
172176

173177
Here's a Windows example:
174178

@@ -182,20 +186,19 @@ $env:PGPASSWORD='<copy/pasted TOKEN value from step 2>'
182186

183187
Here's a Linux/macOS example:
184188

185-
```shell
189+
```bash
186190
export PGPASSWORD=<copy/pasted TOKEN value from step 2>
187191
```
188192

189193
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:
190194

191-
```shell
195+
```bash
192196
export PGPASSWORD=$(az account get-access-token --resource-type oss-rdbms --query "[accessToken]" -o tsv)
193197
```
194198

199+
Now you can initiate a connection with Azure Database for PostgreSQL as you usually would:
195200

196-
Now you can initiate a connection with Azure Database for PostgreSQL as you normally would:
197-
198-
```shell
201+
```sql
199202
psql "host=mydb.postgres... [email protected] dbname=postgres sslmode=require"
200203
```
201204

@@ -210,24 +213,24 @@ To connect by using an Azure AD token with PgAdmin, follow these steps:
210213

211214
Here are some essential considerations when you're connecting:
212215

213-
* `[email protected]` is the name of the Azure AD user.
214-
* 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.
216+
- `[email protected]` is the name of the Azure AD user.
217+
- 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.
217220

218221
You're now authenticated to your Azure Database for PostgreSQL server through Azure AD authentication.
219222

220223
## Authenticate with Azure AD as a group member
221224

222225
### Create Azure AD groups in Azure Database for PostgreSQL - Flexible Server
223226

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:
225228

226-
```
229+
```sql
227230
select * from pgAzure ADauth_create_principal('Prod DB Readonly', false, false).
228231
```
229232

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.
231234

232235
> [!NOTE]
233236
> 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
236239

237240
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.
238241

239-
```
242+
```azurecli-interactive
240243
az login
241244
```
242245

243246
### Retrieve the Azure AD access token
244247

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:
246249

247250
```azurecli-interactive
248251
az account get-access-token --resource https://ossrdbms-aad.database.windows.net
249252
```
250253

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:
252255

253256
```azurecli-interactive
254257
az cloud show
@@ -274,23 +277,17 @@ After authentication is successful, Azure AD returns an access token:
274277

275278
### Use a token as a password for signing in with psql or PgAdmin
276279

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:
278281

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.
281284
- When you're connecting as a group, use only the group name and not the alias of a group member.
282285
- 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.
284287

285288
You're now authenticated to your PostgreSQL server through Azure AD authentication.
286289

287290
## Next steps
288291

289292
- 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).
291-
292-
<!--Image references-->
293-
294-
[1]: ./media/concepts-azure-ad-authentication/authentication-flow.png
295-
[2]: ./media/concepts-azure-ad-authentication/set-azure-ad-admin.png
296-
[3]: ./media/concepts-azure-ad-authentication/set-azure-ad-admin-server-creation.png
293+
- Learn how to [Manage Azure Active Directory users - Azure Database for PostgreSQL - Flexible Server](how-to-manage-azure-ad-users.md).

0 commit comments

Comments
 (0)