Skip to content

Commit

Permalink
feat(mssql-cdc): add ssl support for sqlserver-cdc (#18912)
Browse files Browse the repository at this point in the history
  • Loading branch information
KeXiangWang authored Oct 16, 2024
1 parent 360fe8a commit 7920e3d
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class DbzConnectorConfig {

/* Sql Server configs */
public static final String SQL_SERVER_SCHEMA_NAME = "schema.name";
public static final String SQL_SERVER_ENCRYPT = "database.encrypt";

/* RisingWave configs */
private static final String DBZ_CONFIG_FILE = "debezium.properties";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,12 @@ public SqlServerValidator(
var dbName = userProps.get(DbzConnectorConfig.DB_NAME);
var user = userProps.get(DbzConnectorConfig.USER);
var password = userProps.get(DbzConnectorConfig.PASSWORD);
var encrypt =
Boolean.parseBoolean(
userProps.getOrDefault(DbzConnectorConfig.SQL_SERVER_ENCRYPT, "false"));

var jdbcUrl = ValidatorUtils.getJdbcUrl(SourceTypeE.SQL_SERVER, dbHost, dbPort, dbName);
jdbcUrl = jdbcUrl + ";encrypt=" + encrypt + ";trustServerCertificate=true";
this.jdbcConnection = DriverManager.getConnection(jdbcUrl, user, password);

this.dbName = dbName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ public static String getJdbcUrl(
return String.format("jdbc:postgresql://%s:%s/%s", host, port, database);
case SQL_SERVER:
return String.format(
"jdbc:sqlserver://%s:%s;databaseName=%s;encrypt=false",
host, port, database);
"jdbc:sqlserver://%s:%s;databaseName=%s", host, port, database);
default:
throw ValidatorUtils.invalidArgument("Unknown source type: " + sourceType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ name=${hostname}:${port}:${database.name}.${schema.name}.${table.name:-RW_CDC_Sh
# In sharing cdc mode, transaction metadata will be enabled in frontend.
# For sql server, it's always false actually.
provide.transaction.metadata=${transactional:-false}
database.encrypt=false
database.encrypt=${database.encrypt:-false}
database.trustServerCertificate=true
5 changes: 5 additions & 0 deletions src/connector/src/source/cdc/external/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ pub struct ExternalTableConfig {
#[serde(rename = "ssl.root.cert")]
#[serde(alias = "debezium.database.sslrootcert")]
pub ssl_root_cert: Option<String>,

/// `encrypt` specifies whether connect to SQL Server using SSL.
/// Only "true" means using SSL. All other values are treated as "false".
#[serde(rename = "database.encrypt", default = "Default::default")]
pub encrypt: String,
}

impl ExternalTableConfig {
Expand Down
1 change: 1 addition & 0 deletions src/connector/src/source/cdc/external/mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,7 @@ mod tests {
table: "part".to_string(),
ssl_mode: Default::default(),
ssl_root_cert: None,
encrypt: "false".to_string(),
};

let table = MySqlExternalTable::connect(config).await.unwrap();
Expand Down
1 change: 1 addition & 0 deletions src/connector/src/source/cdc/external/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ mod tests {
table: "mytest".to_string(),
ssl_mode: Default::default(),
ssl_root_cert: None,
encrypt: "false".to_string(),
};

let table = PostgresExternalTable::connect(config).await.unwrap();
Expand Down
8 changes: 6 additions & 2 deletions src/connector/src/source/cdc/external/sql_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,10 @@ impl SqlServerExternalTable {
&config.username,
&config.password,
));
// TODO(kexiang): add ssl support
// TODO(kexiang): use trust_cert_ca, trust_cert is not secure
if config.encrypt == "true" {
client_config.encryption(tiberius::EncryptionLevel::Required);
}
client_config.trust_cert();

let mut client = SqlServerClient::new_with_config(client_config).await?;
Expand Down Expand Up @@ -282,8 +284,10 @@ impl SqlServerExternalTableReader {
&config.username,
&config.password,
));
// TODO(kexiang): add ssl support
// TODO(kexiang): use trust_cert_ca, trust_cert is not secure
if config.encrypt == "true" {
client_config.encryption(tiberius::EncryptionLevel::Required);
}
client_config.trust_cert();

let client = SqlServerClient::new_with_config(client_config).await?;
Expand Down

0 comments on commit 7920e3d

Please sign in to comment.