Skip to content

Commit

Permalink
Add ssl option to RemoteDatabaseConfig (#1690)
Browse files Browse the repository at this point in the history
* Add ssl option to RemoteDatabaseConfig
* Add sslcert, sslkey and sslrootcert parameter for LibPQFactory
  • Loading branch information
gumigumi4f authored Jul 29, 2022
1 parent 5bb2b5b commit 453a36a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ static DatabaseConfig convertFrom(Config config, String keyPrefix)
.loginTimeout(config.get(keyPrefix + "." + "loginTimeout", int.class, 30))
.socketTimeout(config.get(keyPrefix + "." + "socketTimeout", int.class, 1800))
.ssl(config.get(keyPrefix + "." + "ssl", boolean.class, false))
.sslfactory(config.get(keyPrefix + "." + "sslfactory", String.class, "org.postgresql.ssl.NonValidatingFactory"))
.sslmode(config.getOptional(keyPrefix + "." + "sslmode", String.class))
.sslcert(config.getOptional(keyPrefix + "." + "sslcert", String.class))
.sslkey(config.getOptional(keyPrefix + "." + "sslkey", String.class))
.sslrootcert(config.getOptional(keyPrefix + "." + "sslrootcert", String.class))
.build()));
break;
default:
Expand Down Expand Up @@ -173,6 +178,11 @@ static Config toConfig(DatabaseConfig databaseConfig, ConfigFactory cf, String k
config.set(keyPrefix + "." + "loginTimeout", remoteDatabaseConfig.getLoginTimeout());
config.set(keyPrefix + "." + "socketTimeout", remoteDatabaseConfig.getSocketTimeout());
config.set(keyPrefix + "." + "ssl", remoteDatabaseConfig.getSsl());
config.set(keyPrefix + "." + "sslfactory", remoteDatabaseConfig.getSslfactory());
config.setOptional(keyPrefix + "." + "sslmode", remoteDatabaseConfig.getSslmode());
config.setOptional(keyPrefix + "." + "sslcert", remoteDatabaseConfig.getSslcert());
config.setOptional(keyPrefix + "." + "sslkey", remoteDatabaseConfig.getSslkey());
config.setOptional(keyPrefix + "." + "sslrootcert", remoteDatabaseConfig.getSslrootcert());
break;
default:
throw new AssertionError("Unknown database.type: " + databaseConfig.getType());
Expand Down Expand Up @@ -273,7 +283,19 @@ static Properties buildJdbcProperties(DatabaseConfig config)
props.setProperty("password", rc.get().getPassword());
if (rc.get().getSsl()) {
props.setProperty("ssl", "true");
props.setProperty("sslfactory", "org.postgresql.ssl.NonValidatingFactory"); // disable server certificate validation
props.setProperty("sslfactory", rc.get().getSslfactory());
if (rc.get().getSslmode().isPresent()) {
props.setProperty("sslmode", rc.get().getSslmode().get());
}
if (rc.get().getSslcert().isPresent()) {
props.setProperty("sslcert", rc.get().getSslcert().get());
}
if (rc.get().getSslkey().isPresent()) {
props.setProperty("sslkey", rc.get().getSslkey().get());
}
if (rc.get().getSslrootcert().isPresent()) {
props.setProperty("sslrootcert", rc.get().getSslrootcert().get());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ public interface RemoteDatabaseConfig

boolean getSsl();

String getSslfactory();

Optional<String> getSslmode();

Optional<String> getSslcert();

Optional<String> getSslkey();

Optional<String> getSslrootcert();

String getDatabase();

static ImmutableRemoteDatabaseConfig.Builder builder()
Expand Down
5 changes: 5 additions & 0 deletions digdag-docs/src/command_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,11 @@ In the config file, following parameters are available
* database.loginTimeout (seconds in integer, default: 30)
* database.socketTimeout (seconds in integer, default: 1800)
* database.ssl (boolean, default: false)
* database.sslfactory (string, default: "org.postgresql.ssl.NonValidatingFactory", "org.postgresql.ssl.LibPQFactory" is also available)
* database.sslmode (string, "disable", "allow", "prefer", "require", "verify-ca" or "verify-full". enable if sslfactory is set to "org.postgresql.ssl.LibPQFactory")
* database.sslcert (path to ssl cert file in string. enable if sslfactory is set to "org.postgresql.ssl.LibPQFactory")
* database.sslkey (path to ssl key file in string. enable if sslfactory is set to "org.postgresql.ssl.LibPQFactory")
* database.sslrootcert (path to ssl root cert file. enable if sslfactory is set to "org.postgresql.ssl.LibPQFactory")
* database.connectionTimeout (seconds in integer, default: 30)
* database.idleTimeout (seconds in integer, default: 600)
* database.keepaliveTime (seconds in integer, default: 0)
Expand Down

0 comments on commit 453a36a

Please sign in to comment.