I have a java application that was previously running with Postgres JDBC dependency version 42.2.5 and flyway version 5.2.1. These versions were coming from spring-boot-dependencies project. In this case, we were using 2.1.0.RELEASE version.
So, I had the task of upgrading those dependencies. And I did so. spring-boot-dependencies is now at 2.7.8. Flyway version is now at 7.15.0. I kept postgres in the old version for now, because of the error described below.
The thing is that after upgrading if I keep the property spring.flyway.enabled set to true, the application won't start. It keeps complaining about a valid certificate:
Caused by: org.flywaydb.core.internal.exception.FlywaySqlException: Unable to obtain connection from database: FATAL: connection requires a valid client certificate
------------------------------------------------------------------------------------------------
SQL State : 28000
Error Code : 0
Message : FATAL: connection requires a valid client certificate
at org.flywaydb.core.internal.jdbc.JdbcUtils.openConnection(JdbcUtils.java:67)
at org.flywaydb.core.internal.jdbc.JdbcConnectionFactory.<init>(JdbcConnectionFactory.java:70)
at org.flywaydb.core.Flyway.execute(Flyway.java:504)
at org.flywaydb.core.Flyway.migrate(Flyway.java:170)
at org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer.afterPropertiesSet(FlywayMigrationInitializer.java:66)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800)
... 38 common frames omitted
Caused by: org.postgresql.util.PSQLException: FATAL: connection requires a valid client certificate
at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:514)
at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:141)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:192)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:195)
at org.postgresql.Driver.makeConnection(Driver.java:454)
at org.postgresql.Driver.connect(Driver.java:256)
at org.springframework.jdbc.datasource.SimpleDriverDataSource.getConnectionFromDriver(SimpleDriverDataSource.java:144)
at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnectionFromDriver(AbstractDriverBasedDataSource.java:205)
at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection(AbstractDriverBasedDataSource.java:169)
at org.flywaydb.core.internal.jdbc.JdbcUtils.openConnection(JdbcUtils.java:52)
... 44 common frames omitted
If I disable flyway, the application starts and can connect to the database.
My properties file looks like this:
spring.datasource.url=jdbc:postgresql://host:5432/db?ssl=true&sslmode=require&sslfactory=org.postgresql.ssl.DefaultJavaSSLFactory
spring.datasource.username=user
spring.datasource.password=
server.ssl.key-store=classpath:certs/keystore-dev.p12
server.ssl.key-store-password=pass
server.ssl.key-store-type=PKCS12
server.ssl.key-alias=app-alias
server.ssl.protocol=TLS
# flyway db migration support
spring.flyway.enabled=true
The connection data is correct since the application starts and connects to the database.