An Azure managed PostgreSQL database service for app development and deployment.
Hi **Adrian Brenne,
**You don’t actually need to install a pgaadauth extension yourself (it’s built into the Flexible Server image), you just need to:
Enable & assign your User-Assigned Managed Identity (UAMI) to the server
- In the Azure portal go to your PostgreSQL Flexible Server → Identity → User assigned → Add your UAMI Promote that same UAMI to be an Entra (AAD) administrator on the server - In the portal go to Azure Database for PostgreSQL → Active Directory admin → Add → select your UAMI
- Create the matching Postgres role inside your database
Option A – use the built-in pgaadauth helper (connect to the default “postgres” database as the AAD admin):Select *FROM pgaadauth_create_principal('YourUamiName', false, false);- Option B – manually create a role using the client-ID as the password:
-- turn off strict OID checks CREATE ROLE yourUamiRoleName WITH LOGIN PASSWORD 'CLIENT_ID' IN ROLE azure_ad_user;
Connect using your UAMI role + token
- From your VM or App Service, retrieve a token from the IMDS endpoint
curl 'http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https://ossrdbms-aad.database.windows.net&client_id=<CLIENT_ID>' \
-H Metadata:true
- Use that token as the password, and connect as
yourUamiRoleName@yourServerNamewith your favorite Postgres client or ADO.NET.
You must run the pgaadauth function (or CREATE ROLE approach) against the built-in postgres database, not a user database.
Ensure your network/NSG allows outbound calls to the AzureActiveDirectory service tag so IMDS can return tokens.
https://learn.microsoft.com/en-us/azure/postgresql/security/security-entra-concepts#database-extensions
https://learn.microsoft.com/en-us/azure/postgresql/security/security-connect-with-managed-identity
https://learn.microsoft.com/en-us/azure/postgresql/security/security-entra-configure