Skip to content

Commit ef54c0b

Browse files
Merge pull request #224322 from markingmyname/pgaad
[PostgreSQL] Update AAD article
2 parents dec150e + 9c5eab1 commit ef54c0b

File tree

4 files changed

+60
-55
lines changed

4 files changed

+60
-55
lines changed

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

Lines changed: 60 additions & 55 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 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.
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,22 @@ 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.
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.]":::
89102

90-
![Screenshot that shows selections for setting an Azure AD admin during server provisioning.][3]
91103

92104
To set the Azure AD administrator after server creation, follow these steps:
93105

@@ -96,18 +108,18 @@ To set the Azure AD administrator after server creation, follow these steps:
96108
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.
97109
1. Select **Save**.
98110

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.":::
100112

101113
> [!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.
103115
104116
## Connect to Azure Database for PostgreSQL by using Azure AD
105117

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

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.":::
109121

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

112124
We've tested the following clients:
113125

@@ -118,7 +130,7 @@ We've tested the following clients:
118130

119131
## Authenticate with Azure AD
120132

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

123135
### Sign in to the user's Azure subscription
124136

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

133145
### Retrieve the Azure AD access token
134146

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

137149
```azurecli-interactive
138150
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
166178

167179
### Use a token as a password for signing in with client psql
168180

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

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

173185
Here's a Windows example:
174186

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

183195
Here's a Linux/macOS example:
184196

185-
```shell
197+
```bash
186198
export PGPASSWORD=<copy/pasted TOKEN value from step 2>
187199
```
188200

189201
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:
190202

191-
```shell
203+
```bash
192204
export PGPASSWORD=$(az account get-access-token --resource-type oss-rdbms --query "[accessToken]" -o tsv)
193205
```
194206

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

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

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

211222
Here are some essential considerations when you're connecting:
212223

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.
224+
- `[email protected]` is the name of the Azure AD user.
225+
- 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.
217228

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

220231
## Authenticate with Azure AD as a group member
221232

222233
### Create Azure AD groups in Azure Database for PostgreSQL - Flexible Server
223234

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

226-
```
237+
```sql
227238
select * from pgAzure ADauth_create_principal('Prod DB Readonly', false, false).
228239
```
229240

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

232243
> [!NOTE]
233244
> 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
236247

237248
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.
238249

239-
```
250+
```azurecli-interactive
240251
az login
241252
```
242253

243254
### Retrieve the Azure AD access token
244255

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

247258
```azurecli-interactive
248259
az account get-access-token --resource https://ossrdbms-aad.database.windows.net
249260
```
250261

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

253264
```azurecli-interactive
254265
az cloud show
@@ -274,23 +285,17 @@ After authentication is successful, Azure AD returns an access token:
274285

275286
### Use a token as a password for signing in with psql or PgAdmin
276287

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

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

285296
You're now authenticated to your PostgreSQL server through Azure AD authentication.
286297

287298
## Next steps
288299

289300
- 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
301+
- Learn how to [Manage Azure Active Directory users - Azure Database for PostgreSQL - Flexible Server](how-to-manage-azure-ad-users.md).
56.1 KB
Loading
Loading
Loading

0 commit comments

Comments
 (0)