Can't login to postgresql database with service principal in Azure security group.

Teemu Kumpumäki 0 Reputation points
2024-07-22T13:07:57.58+00:00

Hi,

I'm having a problem with logging to postgresql with service principal. Service principal is the backend web app service principal.

Following steps are done to enable login:

Azure group with [OID_A] is created and contains one normal user and a service principal with [OID_B]

Then in Postgresql principal is created with:
select pg_catalog.pgaadauth_create_principal_with_oid('db_users', 'OID_A', 'group', false, false);

Now logging into database with a normal user that is in the group with oid OID_A and user name 'db_users' works fine. But when trying to log in from C# with generated token it fails with:

28000: Azure AD principal with [OID_B] is not a member of the provided Azure AD group.

Have tried all kind of voodoo for days, but nothing seems to get it working. I would appreciate if somebody has ideas how to fix it or how login could be debugged from the postgresql side, token, etc. Now in the postgresql logs is just this:

2024-07-22 12:00:43 UTC-669e49e9.815-LOG:  [AAD] Initializing AADAuth library
2024-07-22 12:00:43 UTC-669e49e9.815-LOG:  [AAD] AADAuth library initialization returns 0
2024-07-22 12:00:43 UTC-669e49e9.815-FATAL:  Azure AD principal with oid[6ac190e8-a17f-4be0-99ec-16727e32dca6] is not a member of the provided Azure AD group.
Azure Database for PostgreSQL
{count} votes