Dataproc尝试通过JDBC连接到Postgres,缺少权限

问题描述 投票:1回答:1

提前致谢...

  1. 我想使用JDBC API连接/写入以编程方式使用Cloud SQL运行的Postgres SQL实例。我用过以下罐子: PostgreSQL的 Postgres的插座工厂 Postgres的插槽,出厂1.0.11-JAR与 - dependencies.jar

我正在运行Dataproc,它将尝试使用步骤#1进行连接,但是我得到以下异常:

2019-04-01 11:05:03.998 IST
Something unusual has occurred to cause the driver to fail. Please report this exception.
    at org.postgresql.Driver.connect(Driver.java:277)
    at java.sql.DriverManager.getConnection(DriverManager.java:664)
    at java.sql.DriverManager.getConnection(DriverManager.java:270)
    at rdsConnector$.getConnection(rdsConnector.scala:33) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.spark.deploy.yarn.ApplicationMaster$$anon$4.run(ApplicationMaster.scala:721)
Caused by: java.lang.RuntimeException: Unable to retrieve information about Cloud SQL instance [projectID:us-east1:dB]
    at com.google.cloud.sql.core.SslSocketFactory.obtainInstanceMetadata(SslSocketFactory.java:459)
    at com.google.cloud.sql.core.SslSocketFactory.fetchInstanceSslInfo(SslSocketFactory.java:333)
    at com.google.cloud.sql.core.SslSocketFactory.getInstanceSslInfo(SslSocketFactory.java:313)
    at com.google.cloud.sql.core.SslSocketFactory.createAndConfigureSocket(SslSocketFactory.java:194)
    at com.google.cloud.sql.core.SslSocketFactory.create(SslSocketFactory.java:160)
    at com.google.cloud.sql.postgres.SocketFactory.createSocket(SocketFactory.java:96)
    at org.postgresql.core.PGStream.<init>(PGStream.java:62)
    at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:91)
    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)
    ... 11 more
Caused by: com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden

2019-04-01 11:05:03.000 IST
User class threw exception: org.postgresql.util.PSQLException: Something unusual has occurred to cause the driver to fail. Please report this exception.

我将此理解为权限问题,但由于我使用Dataproc连接到Postgres,缺少哪些权限?如果我从本地笔记本电脑上运行,那么我必须将GOOGLE_APPLICATION_CREDENTIALS设置为json文件。但Dataproc的流程是什么?

postgresql jdbc google-cloud-platform google-cloud-sql google-cloud-dataproc
1个回答
1
投票

JDBC SocketFactory使用Application Default Credentials策略来访问帐户凭据。

对于Cloud Dataproc,您可以在[project-number][email protected]上为您提供默认服务帐户。您授予此帐户“Cloud SQL Client”IAM角色,JDBC SocketFactory将使用它进行身份验证,因此您将能够连接到您的应用程序。

© www.soinside.com 2019 - 2024. All rights reserved.