question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Unable to connect to postgresql with azure ad

See original GitHub issue

Unable to connect to the Azure PostgreSQL Single server database with Managed Identity in a Spring Boot simple setup.

Exception

2022-10-31 22:28:07.939  INFO [,,] 25480 --- [  restartedMain] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
2022-10-31 22:28:08.541  INFO [,,] 25480 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
Disconnected from the target VM, address: '127.0.0.1:53157', transport: 'socket'
2022-10-31 22:28:09.832 ERROR [,,] 25480 --- [  restartedMain] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Exception during pool initialization.

org.postgresql.util.PSQLException: The server requested password-based authentication, but no password was provided by plugin null
	at org.postgresql.core.v3.AuthenticationPluginManager.lambda$withEncodedPassword$0(AuthenticationPluginManager.java:110) ~[postgresql-42.3.6.jar:42.3.6]
	at org.postgresql.core.v3.AuthenticationPluginManager.withPassword(AuthenticationPluginManager.java:81) ~[postgresql-42.3.6.jar:42.3.6]
	at org.postgresql.core.v3.AuthenticationPluginManager.withEncodedPassword(AuthenticationPluginManager.java:107) ~[postgresql-42.3.6.jar:42.3.6]
	at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:691) ~[postgresql-42.3.6.jar:42.3.6]
	at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:180) ~[postgresql-42.3.6.jar:42.3.6]
	at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:235) ~[postgresql-42.3.6.jar:42.3.6]
	at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49) ~[postgresql-42.3.6.jar:42.3.6]
	at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:223) ~[postgresql-42.3.6.jar:42.3.6]
	at org.postgresql.Driver.makeConnection(Driver.java:402) ~[postgresql-42.3.6.jar:42.3.6]
	at org.postgresql.Driver.connect(Driver.java:261) ~[postgresql-42.3.6.jar:42.3.6]
	at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138) ~[HikariCP-4.0.3.jar:na]
	at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:364) ~[HikariCP-4.0.3.jar:na]
	at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206) ~[HikariCP-4.0.3.jar:na]
	at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:476) ~[HikariCP-4.0.3.jar:na]

To Reproduce Simple Spring Boot app with using the library

        <dependency>
            <groupId>com.azure.spring</groupId>
            <artifactId>spring-cloud-azure-starter-jdbc-postgresql</artifactId>
            <version>4.5.0-beta.1</version>
        </dependency>

Followed the guide as defined here https://learn.microsoft.com/en-us/azure/developer/java/spring-framework/configure-spring-data-jpa-with-azure-postgresql?toc=%2Fazure%2Fpostgresql%2Ftoc.json&bc=%2Fazure%2Fbread%2Ftoc.json&tabs=passwordless

also set the following properties

  datasource:
    url: jdbc:postgresql://<myDB>.postgres.database.azure.com:5432/postgres?sslmode=require
    username: <myRole>@<myDB>
    azure:
      passwordless-enabled: true

Code Snippet After the properties, the application fails at the start while trying to create connection pool.

Expected behavior The connection pool should have been setup without any errors.

Setup (please complete the following information):

  • OS: Windows
  • IDE: IntelliJ
  • Library/Libraries: 4.5.0-beta.1
  • Java version: 17
  • App Server/Environment: Tomcat
  • Frameworks: Spring Boot

Additional context The example in the link considers System Managed Identity, but User Managed Identity is not explained on how to use or setup. I have defined the default identity using the following properties but not sure if this is the right way.

spring:
  cloud:
    azure:
      credential:
        managed-identity-enabled: true
        client-id: *clientID
        client-secret: *clientSecret
      profile:
        tenant-id: *tenantID
        cloud-type: azure

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
vtapadiacommented, Nov 18, 2022

Hi,

Thanks and I will check this out and see if I can find the issue. In the meantime, we also deployed a azre spring cloud instance to see if this works there, but running into java version issue. For that I will have to raise another issue at the portal side… 😦

0reactions
stliucommented, Dec 8, 2022

@vtapadia Hi any updates on this issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot connections - Azure Database for PostgreSQL
If the application persistently fails to connect to Azure Database for PostgreSQL, it usually indicates an issue with one of the following:.
Read more >
Failed to connect to PostgreSQL with Azure AD User via Azure ...
When I use admin user I can connect to the server but when I change to use Azure AD-based authentication, it always got...
Read more >
Cannot connect to postgres database in azure #274 - GitHub
We have written the needed data into your clipboard because it was too large to send. Please paste. Issue Type: Bug.
Read more >
[Solved]-Connect PostgreSQL with Azure Active Directory
So the issue was that I must either provide roles to a security group or a user. If the security group gets the...
Read more >
Connecting to Azure PostgreSQL using Azure Active Directory ...
In this video, we look at how to connect to Azure Database for PostgreSQL from an Azure Virtual Machine using that VM's Managed...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found