-
Notifications
You must be signed in to change notification settings - Fork 328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
R2DBC: Allow external credentials to be provided to Cloud SQL #775
Conversation
Kudos, SonarCloud Quality Gate passed! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it makes sense to file an issue in socket factory to accept credentials in a less environment-dependent way. Or do you think they had technical constraints that led to the environment property being the only way to inject the key?
spring-cloud-gcp-starters/spring-cloud-gcp-starter-sql-r2dbc/pom.xml
Outdated
Show resolved
Hide resolved
...ure/src/main/java/com/google/cloud/spring/autoconfigure/sql/CredentialsPropertiesSetter.java
Show resolved
Hide resolved
System.setProperty(CredentialFactory.CREDENTIAL_FACTORY_PROPERTY, | ||
SqlCredentialFactory.class.getName()); | ||
} catch (IOException ioe) { | ||
logger.info("Error reading Cloud SQL credentials file.", ioe); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this failure should propagate back to the user. If the user provided custom credentials and they did not work, the application is not really expected to work. Unless falling back to default credentials is acceptable (it might be in some cases? but it's hard to assume).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modified this throw an IllegalArgumentException if a user provides an invalid credentials file.
@@ -86,7 +80,7 @@ public void postProcessEnvironment( | |||
.getPropertySources() | |||
.addFirst(new MapPropertySource("CLOUD_SQL_DATA_SOURCE_URL", primaryMap)); | |||
|
|||
setCredentials(sqlProperties, propertiesRetriever.getGcpProperties()); | |||
CredentialsPropertiesSetter.setCredentials(sqlProperties, propertiesRetriever.getGcpProperties(), LOGGER); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to pass the logger; define a static logger in the CredentialsPropertiesSetter
if it's needed. Per-class loggers are useful because end users can control logging verbosity per package/class if needed.
That is a good point. I think this idea was initially considered but was later dropped in favor of environment variables because the Postgres driver didn't allow arbitrary properties to be passed to the socket factory through the JDBC url. GoogleCloudPlatform/cloud-sql-jdbc-socket-factory#41. This discussion happened a while ago so the status may have changed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only minor things left!
...ure/src/main/java/com/google/cloud/spring/autoconfigure/sql/CredentialsPropertiesSetter.java
Show resolved
Hide resolved
...ure/src/main/java/com/google/cloud/spring/autoconfigure/sql/CredentialsPropertiesSetter.java
Show resolved
Hide resolved
...toconfigure/src/main/java/com/google/cloud/spring/autoconfigure/sql/PropertiesRetriever.java
Outdated
Show resolved
Hide resolved
spring-cloud-gcp-samples/spring-cloud-gcp-sql-mysql-r2dbc-sample/README.adoc
Outdated
Show resolved
Hide resolved
spring-cloud-gcp-samples/spring-cloud-gcp-sql-postgres-r2dbc-sample/README.adoc
Outdated
Show resolved
Hide resolved
spring-cloud-gcp-samples/spring-cloud-gcp-sql-postgres-sample/README.adoc
Outdated
Show resolved
Hide resolved
Kudos, SonarCloud Quality Gate passed! |
…CloudPlatform#775) R2DBC support for Cloud SQL: Set credentials system properties for credentials provided through spring.cloud.gcp.credentials and spring.cloud.gcp.sql.credentials. * Refactor credentials code into helper class that will be shared between the EnvironmentPostProcessors of JDBC and R2DBC.
For #205
Follow-up to #772
This PR sets the credentials system properties for credentials provided through
spring.cloud.gcp.credentials
andspring.cloud.gcp.sql.credentials
. It moves all the credentials related logic fromCloudSqlEnvironmentPostProcessor
into a helper class that can be shared between the EnvironmentPostProcessors for JDBC and R2DBC support.