yandex-cloud / ydb-java-sdk

Yandex Database Java SDK
Other
32 stars 9 forks source link

There is no convenient way to connect to YDB in Y.Cloud via JDBC using connection url in IDE #14

Open pnv1 opened 3 years ago

pnv1 commented 3 years ago

The cause of the problem: Y.Cloud uses iam authentication for all of its services, including YDB. There is a separate project "auth-iam" in YDB SDK repository for iam authentication. YDB core does not depend on it. Neither does JDBC. JDBC has only default token authentication. To use iam authentication in jdbc there is an opportunity to set custom authProvider in the code of a user application. Example: https://github.com/yandex-cloud/ydb-java-sdk/blob/master/jdbc/examples/basic_example/src/main/java/com/yandex/ydb/jdbc/example/Main.java#L46

But when you use JDBC in IDEs all you can set is a connection url with a list of key-value string properties.

Solution: Probably a new jdbc jar that has iam authentication options in connection url.

Workaround: You can get iam token (yc iam create-token) and use it as a token in JDBC's connection url: jdbc:ydb:<endpoint>?database=<database>&token=<iam-token>&secureConnection=true Note that iam-token expires in around 10 hours, so its a temporary solution.