Skip to content

Commit 0a9d8c1

Browse files
authored
fix(csharp/src/Drivers/Apache): Set tls enabled to true all HTTP-based drivers, by default (apache#2667)
This change fixes a problem when connecting to a Databricks data source using the `adbc.hive.host` and `adbc.hive.path` instead of `uri`. Databricks connections always require an encrypted connection, so the default of `false` for option `adbc.http_options.tls.enabled` does not correctly apply to a Databricks connection. This change makes the default `True` for Databricks and all HTTP-based drivers. Callers can provide a `uri` with `http:` scheme or set the `adbc.http_options.tls.enabled` to `False` to disable TLS communication. Further, there are improvements in the test environment to support all options in the `http_options.tls.*` namespace
1 parent 68af962 commit 0a9d8c1

File tree

9 files changed

+148
-12
lines changed

9 files changed

+148
-12
lines changed

csharp/src/Drivers/Apache/Hive2/HiveServer2TlsImpl.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace Apache.Arrow.Adbc.Drivers.Apache.Hive2
2626
{
2727
class TlsProperties
2828
{
29-
public bool IsTlsEnabled { get; set; }
29+
public bool IsTlsEnabled { get; set; } = true;
3030
public bool DisableServerCertificateValidation { get; set; }
3131
public bool AllowHostnameMismatch { get; set; }
3232
public bool AllowSelfSigned { get; set; }
@@ -43,15 +43,15 @@ static internal TlsProperties GetHttpTlsOptions(IReadOnlyDictionary<string, stri
4343
var uriValue = new Uri(uri);
4444
tlsProperties.IsTlsEnabled = uriValue.Scheme == Uri.UriSchemeHttps || (properties.TryGetValue(HttpTlsOptions.IsTlsEnabled, out string? isSslEnabled) && bool.TryParse(isSslEnabled, out bool isSslEnabledBool) && isSslEnabledBool);
4545
}
46-
else
46+
else if (properties.TryGetValue(HttpTlsOptions.IsTlsEnabled, out string? isSslEnabled) && bool.TryParse(isSslEnabled, out bool isSslEnabledBool))
4747
{
48-
tlsProperties.IsTlsEnabled = properties.TryGetValue(HttpTlsOptions.IsTlsEnabled, out string? isSslEnabled) && bool.TryParse(isSslEnabled, out bool isSslEnabledBool) && isSslEnabledBool;
48+
tlsProperties.IsTlsEnabled = isSslEnabledBool;
4949
}
5050
if (!tlsProperties.IsTlsEnabled)
5151
{
5252
return tlsProperties;
5353
}
54-
tlsProperties.IsTlsEnabled = true;
54+
5555
if (properties.TryGetValue(HttpTlsOptions.DisableServerCertificateValidation, out string? disableServerCertificateValidation) && bool.TryParse(disableServerCertificateValidation, out bool disableServerCertificateValidationBool) && disableServerCertificateValidationBool)
5656
{
5757
tlsProperties.DisableServerCertificateValidation = true;

csharp/src/Drivers/Apache/Hive2/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ but can also be passed in the call to `AdbcDatabase.Connect`.
3939
| `adbc.apache.statement.batch_size` | Sets the maximum number of rows to retrieve in a single batch request. | `50000` |
4040
| `adbc.apache.statement.polltime_ms` | If polling is necessary to get a result, this option sets the length of time (in milliseconds) to wait between polls. | `500` |
4141
| `adbc.apache.statement.query_timeout_s` | Sets the maximum time (in seconds) for a query to complete. Values can be 0 (infinite) or greater than zero. | `60` |
42-
| `adbc.http_options.tls.enabled` | If tls needs to enabled or not. One of `True`, `False` | `False` |
42+
| `adbc.http_options.tls.enabled` | If tls needs to enabled or not. One of `True`, `False` | `True` |
4343
| `adbc.http_options.tls.disable_server_certificate_validation` | If tls/ssl server certificate validation needs to enabled or not. One of `True`, `False`. If set to True, all certificate validation errors are ignored | `False` |
4444
| `adbc.http_options.tls.allow_self_signed` | If self signed tls/ssl certificate needs to be allowed or not. One of `True`, `False` | `False` |
4545
| `adbc.http_options.tls.allow_hostname_mismatch` | If hostname mismatch is allowed for ssl. One of `True`, `False` | `False` |

csharp/src/Drivers/Apache/Spark/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ but can also be passed in the call to `AdbcDatabase.Connect`.
4040
| `adbc.apache.statement.batch_size` | Sets the maximum number of rows to retrieve in a single batch request. | `50000` |
4141
| `adbc.apache.statement.polltime_ms` | If polling is necessary to get a result, this option sets the length of time (in milliseconds) to wait between polls. | `500` |
4242
| `adbc.apache.statement.query_timeout_s` | Sets the maximum time (in seconds) for a query to complete. Values can be 0 (infinite) or greater than zero. | `60` |
43-
| `adbc.http_options.tls.enabled` | If tls needs to enabled or not. One of `True`, `False` | `False` |
43+
| `adbc.http_options.tls.enabled` | If tls needs to enabled or not. One of `True`, `False` | `True` |
4444
| `adbc.http_options.tls.disable_server_certificate_validation` | If tls/ssl server certificate validation needs to enabled or not. One of `True`, `False`. If set to True, all certificate validation errors are ignored | `False` |
4545
| `adbc.http_options.tls.allow_self_signed` | If self signed tls/ssl certificate needs to be allowed or not. One of `True`, `False` | `False` |
4646
| `adbc.http_options.tls.allow_hostname_mismatch` | If hostname mismatch is allowed for ssl. One of `True`, `False` | `False` |

csharp/test/Drivers/Apache/ApacheTestConfiguration.cs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,31 @@ public class ApacheTestConfiguration : TestConfiguration
6060
[JsonPropertyName("data_type_conv"), JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
6161
public string DataTypeConversion { get; set; } = string.Empty;
6262

63-
[JsonPropertyName("tls_options"), JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
64-
public string TlsOptions { get; set; } = string.Empty;
63+
[JsonPropertyName("http_options"), JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
64+
public HttpTestConfiguration? HttpOptions { get; set; }
65+
}
66+
67+
public class HttpTestConfiguration
68+
{
69+
[JsonPropertyName("tls"), JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
70+
public TlsTestConfiguration? Tls { get; set; }
71+
}
72+
73+
public class TlsTestConfiguration
74+
{
75+
[JsonPropertyName("enabled"), JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
76+
public bool? Enabled { get; set; }
77+
78+
[JsonPropertyName("disable_server_certificate_validation"), JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
79+
public bool? DisableServerCertificateValidation { get; set; }
80+
81+
[JsonPropertyName("allow_self_signed"), JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
82+
public bool? AllowSelfSigned { get; set; }
83+
84+
[JsonPropertyName("allow_hostname_mismatch"), JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
85+
public bool? AllowHostnameMismatch { get; set; }
86+
87+
[JsonPropertyName("trusted_certificate_path"), JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
88+
public string? TrustedCertificatePath { get; set; }
6589
}
6690
}

csharp/test/Drivers/Apache/Hive2/HiveServer2TestEnvironment.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,34 @@ public override Dictionary<string, string> GetDriverParameters(ApacheTestConfigu
106106
{
107107
parameters.Add(ApacheParameters.QueryTimeoutSeconds, testConfiguration.QueryTimeoutSeconds!);
108108
}
109+
if (testConfiguration.HttpOptions != null)
110+
{
111+
if (testConfiguration.HttpOptions.Tls != null)
112+
{
113+
TlsTestConfiguration tlsOptions = testConfiguration.HttpOptions.Tls;
114+
if (tlsOptions.Enabled.HasValue)
115+
{
116+
parameters.Add(HttpTlsOptions.IsTlsEnabled, tlsOptions.Enabled.Value.ToString());
117+
}
118+
if (tlsOptions.AllowSelfSigned.HasValue)
119+
{
120+
parameters.Add(HttpTlsOptions.AllowSelfSigned, tlsOptions.AllowSelfSigned.Value.ToString());
121+
}
122+
if (tlsOptions.AllowHostnameMismatch.HasValue)
123+
{
124+
parameters.Add(HttpTlsOptions.AllowHostnameMismatch, tlsOptions.AllowHostnameMismatch.Value.ToString());
125+
}
126+
if (tlsOptions.DisableServerCertificateValidation.HasValue)
127+
{
128+
parameters.Add(HttpTlsOptions.DisableServerCertificateValidation, tlsOptions.DisableServerCertificateValidation.Value.ToString());
129+
}
130+
if (!string.IsNullOrEmpty(tlsOptions.TrustedCertificatePath))
131+
{
132+
parameters.Add(HttpTlsOptions.TrustedCertificatePath, tlsOptions.TrustedCertificatePath!);
133+
}
134+
}
135+
}
136+
109137
return parameters;
110138
}
111139

csharp/test/Drivers/Apache/Impala/ImpalaTestEnvironment.cs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,6 @@ public override Dictionary<string, string> GetDriverParameters(ApacheTestConfigu
9191
{
9292
parameters.Add(ImpalaParameters.DataTypeConv, testConfiguration.DataTypeConversion!);
9393
}
94-
if (!string.IsNullOrEmpty(testConfiguration.TlsOptions))
95-
{
96-
parameters.Add(ImpalaParameters.TLSOptions, testConfiguration.TlsOptions!);
97-
}
9894
if (!string.IsNullOrEmpty(testConfiguration.BatchSize))
9995
{
10096
parameters.Add(ApacheParameters.BatchSize, testConfiguration.BatchSize!);
@@ -111,6 +107,34 @@ public override Dictionary<string, string> GetDriverParameters(ApacheTestConfigu
111107
{
112108
parameters.Add(ApacheParameters.QueryTimeoutSeconds, testConfiguration.QueryTimeoutSeconds!);
113109
}
110+
if (testConfiguration.HttpOptions != null)
111+
{
112+
if (testConfiguration.HttpOptions.Tls != null)
113+
{
114+
TlsTestConfiguration tlsOptions = testConfiguration.HttpOptions.Tls;
115+
if (tlsOptions.Enabled.HasValue)
116+
{
117+
parameters.Add(HttpTlsOptions.IsTlsEnabled, tlsOptions.Enabled.Value.ToString());
118+
}
119+
if (tlsOptions.AllowSelfSigned.HasValue)
120+
{
121+
parameters.Add(HttpTlsOptions.AllowSelfSigned, tlsOptions.AllowSelfSigned.Value.ToString());
122+
}
123+
if (tlsOptions.AllowHostnameMismatch.HasValue)
124+
{
125+
parameters.Add(HttpTlsOptions.AllowHostnameMismatch, tlsOptions.AllowHostnameMismatch.Value.ToString());
126+
}
127+
if (tlsOptions.DisableServerCertificateValidation.HasValue)
128+
{
129+
parameters.Add(HttpTlsOptions.DisableServerCertificateValidation, tlsOptions.DisableServerCertificateValidation.Value.ToString());
130+
}
131+
if (!string.IsNullOrEmpty(tlsOptions.TrustedCertificatePath))
132+
{
133+
parameters.Add(HttpTlsOptions.TrustedCertificatePath, tlsOptions.TrustedCertificatePath!);
134+
}
135+
}
136+
}
137+
114138
return parameters;
115139
}
116140

csharp/test/Drivers/Apache/Spark/Resources/sparkconfig-databricks.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,21 @@
1212
"schema": "default",
1313
"table": "<tableName>",
1414
"expectedColumnCount": 19
15+
},
16+
"http_options-comment": "Allowed values, null|object",
17+
"http_options": {
18+
"tls-comment": "Allowed values, null|object",
19+
"tls": {
20+
"enabled-comment": "Allowed values, true|false|null.",
21+
"enabled": null,
22+
"disable_server_certificate_validation-comment": "Allowed values, true|false|null.",
23+
"disable_server_certificate_validation": null,
24+
"allow_self_signed-comment": "Allowed values, true|false|null.",
25+
"allow_self_signed": null,
26+
"allow_hostname_mismatch-comment": "Allowed values, true|false|null.",
27+
"allow_hostname_mismatch": null,
28+
"trusted_certificate_path-commnt": "Allowed values: string|null",
29+
"trusted_certificate_path": null
30+
}
1531
}
1632
}

csharp/test/Drivers/Apache/Spark/Resources/sparkconfig-http.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,21 @@
1111
"schema": "default",
1212
"table": "<tableName>",
1313
"expectedColumnCount": 17
14+
},
15+
"http_options-comment": "Allowed values, null|object",
16+
"http_options": {
17+
"tls-comment": "Allowed values, null|object",
18+
"tls": {
19+
"enabled-comment": "Allowed values, true|false|null.",
20+
"enabled": null,
21+
"disable_server_certificate_validation-comment": "Allowed values, true|false|null.",
22+
"disable_server_certificate_validation": null,
23+
"allow_self_signed-comment": "Allowed values, true|false|null.",
24+
"allow_self_signed": null,
25+
"allow_hostname_mismatch-comment": "Allowed values, true|false|null.",
26+
"allow_hostname_mismatch": null,
27+
"trusted_certificate_path-commnt": "Allowed values: string|null",
28+
"trusted_certificate_path": null
29+
}
1430
}
1531
}

csharp/test/Drivers/Apache/Spark/SparkTestEnvironment.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using System.Collections.Generic;
2020
using System.Data.SqlTypes;
2121
using System.Text;
22+
using System.Text.Json.Serialization;
2223
using Apache.Arrow.Adbc.Drivers.Apache;
2324
using Apache.Arrow.Adbc.Drivers.Apache.Hive2;
2425
using Apache.Arrow.Adbc.Drivers.Apache.Spark;
@@ -117,6 +118,33 @@ public override Dictionary<string, string> GetDriverParameters(SparkTestConfigur
117118
{
118119
parameters.Add(ApacheParameters.QueryTimeoutSeconds, testConfiguration.QueryTimeoutSeconds!);
119120
}
121+
if (testConfiguration.HttpOptions != null)
122+
{
123+
if (testConfiguration.HttpOptions.Tls != null)
124+
{
125+
TlsTestConfiguration tlsOptions = testConfiguration.HttpOptions.Tls;
126+
if (tlsOptions.Enabled.HasValue)
127+
{
128+
parameters.Add(HttpTlsOptions.IsTlsEnabled, tlsOptions.Enabled.Value.ToString());
129+
}
130+
if (tlsOptions.AllowSelfSigned.HasValue)
131+
{
132+
parameters.Add(HttpTlsOptions.AllowSelfSigned, tlsOptions.AllowSelfSigned.Value.ToString());
133+
}
134+
if (tlsOptions.AllowHostnameMismatch.HasValue)
135+
{
136+
parameters.Add(HttpTlsOptions.AllowHostnameMismatch, tlsOptions.AllowHostnameMismatch.Value.ToString());
137+
}
138+
if (tlsOptions.DisableServerCertificateValidation.HasValue)
139+
{
140+
parameters.Add(HttpTlsOptions.DisableServerCertificateValidation, tlsOptions.DisableServerCertificateValidation.Value.ToString());
141+
}
142+
if (!string.IsNullOrEmpty(tlsOptions.TrustedCertificatePath))
143+
{
144+
parameters.Add(HttpTlsOptions.TrustedCertificatePath, tlsOptions.TrustedCertificatePath!);
145+
}
146+
}
147+
}
120148

121149
return parameters;
122150
}

0 commit comments

Comments
 (0)