Authentication failure in Azure postgresql database

Gokul R Dev 326 Reputation points
2024-08-22T09:13:22.8333333+00:00

Hello everyone,

I am following these turotials to authenticate with Azure postgresql db with system assigned managed identity. I haven't deployed to code to azure app service, when i try to check the connection locally, I'm getting the error 'Password authentication failed for user <user-name>'. The problem is the username which is diplayed is the local admin of the vm from which i am trying to authenticate. I had successfuly logged in using azure cli, azure account extension to run this locally and i am using simple nodejs app and was able to get the token successfully, my vm is in same vnet as the db resides. However I haven't connected my vm to entra id which is not mentioned as a requirement in docs.

tutorial 1, tutorial2

Azure Database for PostgreSQL
{count} votes

1 answer

Sort by: Most helpful
  1. Gokul R Dev 326 Reputation points
    2024-08-29T09:56:23.63+00:00

    Hi @Oury Ba-MSFT ,

    I just found the reason for the issue. DefaultAzureCredential class from azure identity library get the token credential by sequentially trying several different credential types. I believe the order is env file> azure cli> managed identity which I saw somewhere in the documentation and I was using an env file like suggested in the tutorial where i had given the database user value a postegrsql user initially and entra admin of database later.However, both of the values threw the error I mentioned above which is picking the local admin of my VM instead of the user I mentioned in env file. Then I tried to hard code the entra admin of database in code file (username@domain.com) and I was able to successfully connect to databse locally.

    1. How can we make sure the use of value mentioned in env file which is failing at this moment instead of hard coding?
    2. The service connector which is connection the app service with databse create a user. Is this user I need to mention as databse user when i deploy the code to app service?
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.