Skip to content

Commit ecaa7d9

Browse files
authored
Merge pull request #278783 from nachoalonsoportillo/patch-6
Update how-to-manage-azure-ad-users.md
2 parents 92300ea + a6f59d5 commit ecaa7d9

File tree

1 file changed

+81
-43
lines changed

1 file changed

+81
-43
lines changed

articles/postgresql/flexible-server/how-to-manage-azure-ad-users.md

Lines changed: 81 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: This article describes how you can manage Microsoft Entra ID enable
44
author: achudnovskij
55
ms.author: anchudno
66
ms.reviewer: maghan
7-
ms.date: 04/27/2024
7+
ms.date: 06/20/2024
88
ms.service: postgresql
99
ms.subservice: flexible-server
1010
ms.topic: how-to
@@ -24,8 +24,6 @@ This article describes how you can create a Microsoft Entra ID enabled database
2424
2525
If you like to learn about how to create and manage Azure subscription users and their privileges, you can visit the [Azure role-based access control (Azure RBAC) article](../../role-based-access-control/built-in-roles.md) or review [how to customize roles](../../role-based-access-control/custom-roles.md).
2626

27-
<a name='create-or-delete-azure-ad-administrators-using-azure-portal-or-azure-resource-manager-arm-api'></a>
28-
2927
## Create or delete Microsoft Entra administrators using Azure portal or Azure Resource Manager (ARM) API
3028

3129
1. Open the **Authentication** page for your Azure Database for PostgreSQL flexible server instance in the Azure portal.
@@ -39,8 +37,6 @@ If you like to learn about how to create and manage Azure subscription users and
3937
> [!NOTE]
4038
> Support for Microsoft Entra Administrators management via Azure SDK, az cli and Azure PowerShell is coming soon.
4139
42-
<a name='manage-azure-ad-roles-using-sql'></a>
43-
4440
## Manage Microsoft Entra roles using SQL
4541

4642
Once the first Microsoft Entra administrator is created from the Azure portal or API, you can use the administrator role to manage Microsoft Entra roles in your Azure Database for PostgreSQL flexible server instance.
@@ -56,38 +52,54 @@ Each PostgreSQL database role can be mapped to one of the following Microsoft En
5652
1. **Service Principal**. Including [Applications and Managed identities](../../active-directory/develop/app-objects-and-service-principals.md)
5753
1. **Group** When a PostgreSQL role is linked to a Microsoft Entra group, any user or service principal member of this group can connect to the Azure Database for PostgreSQL flexible server instance with the group role.
5854

59-
<a name='list-azure-ad-roles-using-sql'></a>
60-
6155
### List Microsoft Entra roles using SQL
6256

6357
```sql
64-
select * from pgaadauth_list_principals(true);
58+
pg_catalog.pgaadauth_list_principals(isAdminValue boolean)
6559
```
6660

67-
**Parameters:**
68-
- *true* -will return Admin users.
69-
- *false* -will return all Microsoft Entra user both Microsoft Entra admins and Non Microsoft Entra admins.
61+
#### Arguments
7062

71-
<a name='create-a-role-using-azure-ad-principal-name'></a>
63+
##### `isAdminValue`
7264

73-
## Create a role using Microsoft Entra principal name
65+
`boolean` when `true` returns Admin users. When `false`returns all Microsoft Entra users, including Microsoft Entra admins and non-admins.
7466

75-
```sql
76-
select * from pgaadauth_create_principal('<roleName>', <isAdmin>, <isMfa>);
67+
#### Return type
7768

78-
--For example:
69+
`TABLE(rolname name, principalType text, objectId text, tenantId text, isMfa integer, isAdmin integer)` a table with the following schema:
70+
- `rolname` the name of the role in PostgreSQL.
71+
- `principalType` the type of principal in Microsoft Entra ID. It can be `user`, `group`, or `service`.
72+
- `objectId` the identifier of the object in Microsoft Entra ID for this principal.
73+
- `tenantId` the identifier of the tenant hosting this principal in Microsoft Entra ID.
74+
- `isMfa` returns a value of `1` if the user/role has MFA enforced.
75+
- `isAdmin` returns a value of `1` if the user/role is an administrator in PostgreSQL.
7976

80-
select * from pgaadauth_create_principal('[email protected]', false, false);
77+
## Create a user/role using Microsoft Entra principal name
78+
79+
```sql
80+
pg_catalog.pgaadauth_create_principal(roleName text, isAdmin boolean, isMfa boolean)
8181
```
8282

83-
**Parameters:**
84-
- *roleName* - Name of the role to be created. This **must match a name of Microsoft Entra principal**:
83+
#### Arguments
84+
85+
##### `roleName`
86+
87+
`text` name of the role to be created. This **must match the name of the Microsoft Entra principal**.
8588
- For **users** use User Principal Name from Profile. For guest users, include the full name in their home domain with #EXT# tag.
8689
- For **groups** and **service principals** use display name. The name must be unique in the tenant.
87-
- *isAdmin* - Set to **true** if when creating an admin user and **false** for a regular user. Admin user created this way has the same privileges as one created via portal or API.
88-
- *isMfa* - Flag if Multi Factor Authentication must be enforced for this role.
8990

90-
<a name='create-a-role-using-azure-ad-object-identifier'></a>
91+
##### `isAdmin`
92+
`boolean` when `true` it creates a PostgreSQL admin user (member of `azure_pg_admin` role and with CREATEROLE and CREATEDB permissions). When `false` it creates a regular PostgreSQL user.
93+
94+
##### `isMfa`
95+
`boolean` when `true` it enforces multifactor authentication for this PostgreSQL user.
96+
97+
> [!IMPORTANT]
98+
> The `isMfa` flag tests the `mfa` claim in the Microsoft Entra ID token, but it doesn't impact the token acquisition flow. For example, if the tenant of the principal is not configured for multifactor authentication, it will prevent the use of the feature. And if the tenant requires multifactor authentication for all tokens, it will make this flag useless.
99+
100+
#### Return type
101+
102+
`text` single value that consists of a string "Created role for ***roleName***", where ***roleName*** is the argument passed for the **roleName** parameter.
91103

92104
## Drop a role using Microsoft Entra principal name
93105

@@ -100,38 +112,64 @@ DROP ROLE rolename;
100112
## Create a role using Microsoft Entra object identifier
101113

102114
```sql
103-
select * from pgaadauth_create_principal_with_oid('<roleName>', '<objectId>', '<objectType>', <isAdmin>, <isMfa>);
104-
105-
For example: select * from pgaadauth_create_principal_with_oid('accounting_application', '00000000-0000-0000-0000-000000000000', 'service', false, false);
115+
pg_catalog.pgaadauth_create_principal(roleName text, objectId text, objectType text, isAdmin boolean, isMfa boolean)
106116
```
107117

108-
**Parameters:**
109-
- *roleName* - Name of the role to be created.
110-
- *objectId* - Unique object identifier of the Microsoft Entra object:
111-
- For **Users**, **Groups** and **Managed Identities** the ObjectId can be found by searching for the object name in Microsoft Entra ID page in Azure portal. [See this guide as example](/partner-center/find-ids-and-domain-names)
112-
- For **Applications**, Objectid of the corresponding **Service Principal** must be used. In Azure portal the required ObjectId can be found on **Enterprise Applications** page.
113-
- *objectType* - Type of the Microsoft Entra object to link to this role: service, user, group.
114-
- *isAdmin* - Set to **true** if when creating an admin user and **false** for a regular user. Admin user created this way has the same privileges as one created via portal or API.
115-
- *isMfa* - Flag if Multi Factor Authentication must be enforced for this role.
118+
#### Arguments
119+
120+
##### `roleName`
121+
122+
`text` name of the role to be created.
116123

117-
<a name='enable-azure-ad-authentication-for-an-existing-postgresql-role-using-sql'></a>
124+
##### `objectId`
125+
126+
`text` unique object identifier of the Microsoft Entra object.
127+
- For **users**, **groups**, and **managed identities**, the objectId can be found by searching for the object name in [Microsoft Entra ID](https://ms.portal.azure.com/#blade/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade) page in Azure portal. [See this guide as example](/partner-center/find-ids-and-domain-names)
128+
- For **groups** and **service principals** use display name. The name must be unique in the tenant.
129+
- For **applications**, the objectId of the corresponding **Service Principal** must be used. In Azure portal the required objectId can be found on [Enterprise Applications](https://ms.portal.azure.com/#view/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/~/EnterpriseApps) page in Azure portal.
130+
131+
##### `objectType`
132+
`text` the type of Microsoft Entra object to link to this role. It can be `user`, `group`, or `service`.
133+
134+
##### `isAdmin`
135+
`boolean` when `true` it creates a PostgreSQL admin user (member of `azure_pg_admin` role and with CREATEROLE and CREATEDB permissions). When `false` it creates a regular PostgreSQL user.
136+
137+
##### `isMfa`
138+
`boolean` when `true` it enforces multifactor authentication for this PostgreSQL user.
139+
140+
> [!IMPORTANT]
141+
> The `isMfa` flag tests the `mfa` claim in the Microsoft Entra ID token, but it doesn't impact the token acquisition flow. For example, if the tenant of the principal is not configured for multifactor authentication, it will prevent the use of the feature. And if the tenant requires multifactor authentication for all tokens, it will make this flag useless.
142+
143+
#### Return type
144+
145+
`text` single value that consists of a string "Created role for ***roleName***", where ***roleName*** is the argument passed for the **roleName** parameter.
118146

119147
## Enable Microsoft Entra authentication for an existing PostgreSQL role using SQL
120148

121-
Azure Database for PostgreSQL flexible server uses security labels associated with database roles to store Microsoft Entra ID mapping.
149+
Azure Database for PostgreSQL flexible server uses security labels associated with database roles to store their corresponding Microsoft Entra ID mapping.
122150

123-
You can use the following SQL to assign security label:
151+
You can use the following SQL to assign the required security label to map it to a Microsoft Entra object:
124152

125153
```sql
126-
SECURITY LABEL for "pgaadauth" on role "<roleName>" is 'aadauth,oid=<objectId>,type=<user|group|service>,admin';
154+
SECURITY LABEL for "pgaadauth" on role "<roleName>" is 'aadauth,oid=<objectId>,type=<objectType>,admin';
127155
```
156+
#### Arguments
157+
158+
##### `roleName`
159+
160+
`text` name of an existing PostgreSQL role to which Microsoft Entra authentication needs to be enabled.
161+
162+
##### `objectId`
163+
164+
`text` unique object identifier of the Microsoft Entra object.
165+
166+
##### `objectType`
167+
168+
`text` it can be set to `user`, `group`, or `service` (for applications or managed identities connecting under their own service credentials).
169+
170+
##### `admin`
128171

129-
**Parameters:**
130-
- *roleName* - Name of an existing PostgreSQL role to which Microsoft Entra authentication needs to be enabled.
131-
- *objectId* - Unique object identifier of the Microsoft Entra object.
132-
- *user* - End user principals.
133-
- *service* - Applications or Managed Identities connecting under their own service credentials.
134-
- *group* - Name of Microsoft Entra group.
172+
`text` it can be present or absent. Users/roles for which this part is present in their security label, can manage other Microsoft Entra ID roles.
135173

136174
## Next steps
137175

0 commit comments

Comments
 (0)