[BUG] Unable to connect to postgresql with azure ad
See original GitHub issueUnable 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:
- Created a year ago
- Comments:10 (7 by maintainers)
Top GitHub Comments
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… 😦
@vtapadia Hi any updates on this issue?