cloudfoundry / java-buildpack

Cloud Foundry buildpack for running Java applications
Apache License 2.0
435 stars 2.58k forks source link

MariaDB JDBC detection logic is incorrect with apps using MySQL Connector/j >= 8.0.31 #1027

Closed abg closed 1 year ago

abg commented 1 year ago

My team maintains a MySQL broker for TAS. In our test pipelines, we deploy a couple different Spring based apps to test JDBC bindings. One of these apps is built exclusively with the Oracle MySQL Connector/j. In a recent dependency bump, we noticed that the app was using the MariaDB v2.7.9 connector rather than MySQL connector bundled in the app. This seems to occur after we bumped to MySQL Connector/j v8.0.31+.

We discovered that Oracle recently renamed the Maven coordinates from mysql-connector-java to mysql-connector-j, this in turn changed the file naming convention from mysql-connector-java-$VERSION.jar to mysql-connector-j-$VERSION.jar. This applies to MySQL Connector/j 8.0.31+, even when using the legacy mysql:mysql-connector-java reference. We think this naming change may have broken some assumptions in java-buildpacks MariaDB JDBC Framework

Reproduction steps:

Under the hood, on the MySQL database we can also see that the app is incorrectly using the MariaDB connector provided by the buildpack:

mysql> SELECT ATTR_NAME, ATTR_VALUE FROM performance_schema.session_connect_attrs;
+------------------+----------------------+
| ATTR_NAME        | ATTR_VALUE           |
+------------------+----------------------+
| _runtime_version | 17.0.8.              |
| _client_version  | 2.7.9                |
| _client_license  | GPL                  |
| _runtime_vendor  | BellSoft             |
| _client_name     | MariaDB Connector/J  |
...
dmikusa commented 1 year ago

Yes, that will need to be updated. The buildpack is presently looking for JARs matching mariadb-java-client*.jar or mysql-connector-java*.jar. https://github.com/cloudfoundry/java-buildpack/blob/9ffb37f9fb643a1edf48b8abdc79941ded046abf/lib/java_buildpack/framework/maria_db_jdbc.rb#L49

anthonydahanne commented 1 year ago

Hello! I could reproduce it with the latest spring-music (based on SB3). Another way to notice the misuse of the Maria DB connector, is via the actuator:

GET http://app.com/actuator/env
[...]
{
  "name": "cfenvjdbc",
  "properties": {
    "spring.datasource.url": {
      "value": "jdbc:mysql://mysql.service.internal:3306/service_instance_db?user=xxx&password=yyy&sslMode=VERIFY_IDENTITY&useSSL=true&requireSSL=true&enabledTLSProtocols=TLSv1.2&serverSslCert=/etc/ssl/certs/ca-certificates.crt"
    },
    "spring.datasource.username": {
      "value": "xxx"
    },
    "spring.datasource.password": {
      "value": "yyy"
    },
    "spring.datasource.driver-class-name": {
      "value": "org.mariadb.jdbc.Driver"
    }
  }
}
[...]

if indeed we use an older mysql-connector-java connector, we'll get the expected usage:

{
  "name": "cfenvjdbc",
  "properties": {
    "spring.datasource.url": {
      "value": "jdbc:mysql://mysql.service.internal:3306/service_instance_db?user=xxx&password=yyy&sslMode=VERIFY_IDENTITY&useSSL=true&requireSSL=true&enabledTLSProtocols=TLSv1.2&serverSslCert=/etc/ssl/certs/ca-certificates.crt"
    },
    "spring.datasource.username": {
      "value": "xxx"
    },
    "spring.datasource.password": {
      "value": "yyy"
    },
    "spring.datasource.driver-class-name": {
      "value": "com.mysql.cj.jdbc.Driver"
    }
  }
}
anthonydahanne commented 12 months ago

fix released in https://github.com/cloudfoundry/java-buildpack/releases/tag/v4.61.1