snowflake-jdbc: SNOW-618478: Unable to authenticate with a private key by using spring datasource properties
We are using the standard configuration to setup spring datasources. When we want to use a private key to authenticate, the key is interpreted as a string and not a private key.
net.snowflake.client.jdbc.SnowflakeSQLLoggedException: Invalid parameter value type: java.lang.String, expected type: java.security.PrivateKey.
spring.datasource.username=${snowflake.username}
spring.datasource.driverClassName=net.snowflake.client.jdbc.SnowflakeDriver
spring.datasource.url=jdbc:snowflake://${snowflake.account}.snowflakecomputing.com/?warehouse=${snowflake.warehouse}&db=${snowflake.database.name}&schema=${snowflake.schema}
spring.datasource.dataSourceProperties.privatekey=MII...YKF
The final case is to use Azure AppConfiguration/KeyVault to get properties.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 30 (5 by maintainers)
@sfc-gh-wfateem I just opened a PR to resolve this issue. As further justification of the need, I’d add my blocking concern:
I want to leverage this driver through Spark.read in a cluster. In order to use private_key_file, I’d have to make the file available to every executor in the cluster. If I instead use private_key_base64, I can read the bytes from disk once and allow Spark to pass the base64 encoded String to all the executors transparently.
Happy to make adjustments to the PR as necessary, I’d really like to get this mainlined asap and I’m certain all the Hikari users represented here would appreciate it as well.
We currently use HikariCP + Snowflake JDBC in our project and faced this issue while attempting to inject
privateKeyas a data source property. By looking at the source code there’s no reason for the driver to acceptprivateKeyas an object, a string should be ok, and the driver can implicitly transform it as ajava.security.PrivateKeyobject, thoughts?Code Snippet:
Setting a DataSource like that should work too, but there’s an easier approach. With the PR in place, you can just pass the new private_key_base64 property into the config using addDataSourceProperty
For reference and my own understanding:
privateKeyStringand wouldn’t need to self parse the strings to keys@NitinSharma1991 I’m reopening this issue because it looks like I erroneously perceived that changes were made in that PR, but I see now that it was closed and the Hikari team commented that they’re not going to make any changes. We’ll need to take a closer look.
On Hikari 4.0.3: was seeing
Invalid parameter value type: java.lang.String, expected type: java.security.PrivateKey.even though I gave itjava.security.PrivateKey.private_key_base64did not work for me:Missing password.What did work was: