Skip to content

Commit 4588cec

Browse files
authored
enhancement(tls settings): support of SNI when connecting to remote server (#21365)
* support of SNI when connecting to remote server * incorporate comments * bubble up error * change unwrap to expect and other comment incorporation * refactor to remove expect * fix change log file
1 parent 04d21fb commit 4588cec

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+682
-17
lines changed

.github/actions/spelling/expect.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,3 +1280,4 @@ zulip
12801280
Zunstable
12811281
zup
12821282
zurp
1283+
sni
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Add support for providing Server Name Indication in the TLS handshake when connecting to a server.
2+
3+
authors: anil-db

lib/vector-core/src/tls/mod.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ pub enum TlsError {
100100
AddCertToStore { source: ErrorStack },
101101
#[snafu(display("Error setting up the verification certificate: {}", source))]
102102
SetVerifyCert { source: ErrorStack },
103+
#[snafu(display("Error setting SNI: {}", source))]
104+
SetSni { source: ErrorStack },
103105
#[snafu(display("Error setting ALPN protocols: {}", source))]
104106
SetAlpnProtocols { source: ErrorStack },
105107
#[snafu(display(
@@ -183,13 +185,15 @@ pub fn tls_connector_builder(settings: &MaybeTlsSettings) -> Result<SslConnector
183185
}
184186

185187
fn tls_connector(settings: &MaybeTlsSettings) -> Result<ConnectConfiguration> {
186-
let verify_hostname = settings
187-
.tls()
188-
.map_or(true, |settings| settings.verify_hostname);
189-
let configure = tls_connector_builder(settings)?
188+
let mut configure = tls_connector_builder(settings)?
190189
.build()
191190
.configure()
192-
.context(TlsBuildConnectorSnafu)?
193-
.verify_hostname(verify_hostname);
191+
.context(TlsBuildConnectorSnafu)?;
192+
let tls_setting = settings.tls().cloned();
193+
if let Some(tls_setting) = &tls_setting {
194+
tls_setting
195+
.apply_connect_configuration(&mut configure)
196+
.context(SetSniSnafu)?;
197+
}
194198
Ok(configure)
195199
}

lib/vector-core/src/tls/settings.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,14 @@ pub struct TlsConfig {
148148
#[configurable(metadata(docs::examples = "PassWord1"))]
149149
#[configurable(metadata(docs::human_name = "Key File Password"))]
150150
pub key_pass: Option<String>,
151+
152+
/// Server name to use when using Server Name Indication (SNI).
153+
///
154+
/// Only relevant for outgoing connections.
155+
#[serde(alias = "server_name")]
156+
#[configurable(metadata(docs::examples = "www.example.com"))]
157+
#[configurable(metadata(docs::human_name = "Server Name"))]
158+
pub server_name: Option<String>,
151159
}
152160

153161
impl TlsConfig {
@@ -169,6 +177,7 @@ pub struct TlsSettings {
169177
authorities: Vec<X509>,
170178
pub(super) identity: Option<IdentityStore>, // openssl::pkcs12::ParsedPkcs12 doesn't impl Clone yet
171179
alpn_protocols: Option<Vec<u8>>,
180+
server_name: Option<String>,
172181
}
173182

174183
#[derive(Clone)]
@@ -203,6 +212,7 @@ impl TlsSettings {
203212
authorities: options.load_authorities()?,
204213
identity: options.load_identity()?,
205214
alpn_protocols: options.parse_alpn_protocols()?,
215+
server_name: options.server_name.clone(),
206216
})
207217
}
208218

@@ -333,8 +343,17 @@ impl TlsSettings {
333343
Ok(())
334344
}
335345

336-
pub fn apply_connect_configuration(&self, connection: &mut ConnectConfiguration) {
346+
pub fn apply_connect_configuration(
347+
&self,
348+
connection: &mut ConnectConfiguration,
349+
) -> std::result::Result<(), openssl::error::ErrorStack> {
337350
connection.set_verify_hostname(self.verify_hostname);
351+
if let Some(server_name) = &self.server_name {
352+
// Prevent native TLS lib from inferring default SNI using domain name from url.
353+
connection.set_use_server_name_indication(false);
354+
connection.set_hostname(server_name)?;
355+
}
356+
Ok(())
338357
}
339358
}
340359

src/http.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
11
#![allow(missing_docs)]
2-
use std::{
3-
fmt,
4-
net::SocketAddr,
5-
task::{Context, Poll},
6-
time::Duration,
7-
};
8-
92
use futures::future::BoxFuture;
103
use headers::{Authorization, HeaderMapExt};
114
use http::{
@@ -22,6 +15,12 @@ use hyper_proxy::ProxyConnector;
2215
use rand::Rng;
2316
use serde_with::serde_as;
2417
use snafu::{ResultExt, Snafu};
18+
use std::{
19+
fmt,
20+
net::SocketAddr,
21+
task::{Context, Poll},
22+
time::Duration,
23+
};
2524
use tokio::time::Instant;
2625
use tower::{Layer, Service};
2726
use tower_http::{
@@ -205,10 +204,10 @@ pub fn build_tls_connector(
205204
let settings = tls_settings.tls().cloned();
206205
https.set_callback(move |c, _uri| {
207206
if let Some(settings) = &settings {
208-
settings.apply_connect_configuration(c);
207+
settings.apply_connect_configuration(c)
208+
} else {
209+
Ok(())
209210
}
210-
211-
Ok(())
212211
});
213212
Ok(https)
214213
}

website/cue/reference/components/sinks/base/amqp.cue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,15 @@ base: components: sinks: amqp: configuration: {
387387
required: false
388388
type: string: examples: ["${KEY_PASS_ENV_VAR}", "PassWord1"]
389389
}
390+
server_name: {
391+
description: """
392+
Server name to use when using Server Name Indication (SNI).
393+
394+
Only relevant for outgoing connections.
395+
"""
396+
required: false
397+
type: string: examples: ["www.example.com"]
398+
}
390399
verify_certificate: {
391400
description: """
392401
Enables certificate verification. For components that create a server, this requires that the

website/cue/reference/components/sinks/base/appsignal.cue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,15 @@ base: components: sinks: appsignal: configuration: {
386386
required: false
387387
type: string: examples: ["${KEY_PASS_ENV_VAR}", "PassWord1"]
388388
}
389+
server_name: {
390+
description: """
391+
Server name to use when using Server Name Indication (SNI).
392+
393+
Only relevant for outgoing connections.
394+
"""
395+
required: false
396+
type: string: examples: ["www.example.com"]
397+
}
389398
verify_certificate: {
390399
description: """
391400
Enables certificate verification. For components that create a server, this requires that the

website/cue/reference/components/sinks/base/aws_cloudwatch_logs.cue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,15 @@ base: components: sinks: aws_cloudwatch_logs: configuration: {
781781
required: false
782782
type: string: examples: ["${KEY_PASS_ENV_VAR}", "PassWord1"]
783783
}
784+
server_name: {
785+
description: """
786+
Server name to use when using Server Name Indication (SNI).
787+
788+
Only relevant for outgoing connections.
789+
"""
790+
required: false
791+
type: string: examples: ["www.example.com"]
792+
}
784793
verify_certificate: {
785794
description: """
786795
Enables certificate verification. For components that create a server, this requires that the

website/cue/reference/components/sinks/base/aws_cloudwatch_metrics.cue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,15 @@ base: components: sinks: aws_cloudwatch_metrics: configuration: {
460460
required: false
461461
type: string: examples: ["${KEY_PASS_ENV_VAR}", "PassWord1"]
462462
}
463+
server_name: {
464+
description: """
465+
Server name to use when using Server Name Indication (SNI).
466+
467+
Only relevant for outgoing connections.
468+
"""
469+
required: false
470+
type: string: examples: ["www.example.com"]
471+
}
463472
verify_certificate: {
464473
description: """
465474
Enables certificate verification. For components that create a server, this requires that the

website/cue/reference/components/sinks/base/aws_kinesis_firehose.cue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,15 @@ base: components: sinks: aws_kinesis_firehose: configuration: {
730730
required: false
731731
type: string: examples: ["${KEY_PASS_ENV_VAR}", "PassWord1"]
732732
}
733+
server_name: {
734+
description: """
735+
Server name to use when using Server Name Indication (SNI).
736+
737+
Only relevant for outgoing connections.
738+
"""
739+
required: false
740+
type: string: examples: ["www.example.com"]
741+
}
733742
verify_certificate: {
734743
description: """
735744
Enables certificate verification. For components that create a server, this requires that the

website/cue/reference/components/sinks/base/aws_kinesis_streams.cue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,15 @@ base: components: sinks: aws_kinesis_streams: configuration: {
730730
required: false
731731
type: string: examples: ["${KEY_PASS_ENV_VAR}", "PassWord1"]
732732
}
733+
server_name: {
734+
description: """
735+
Server name to use when using Server Name Indication (SNI).
736+
737+
Only relevant for outgoing connections.
738+
"""
739+
required: false
740+
type: string: examples: ["www.example.com"]
741+
}
733742
verify_certificate: {
734743
description: """
735744
Enables certificate verification. For components that create a server, this requires that the

website/cue/reference/components/sinks/base/aws_s3.cue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,15 @@ base: components: sinks: aws_s3: configuration: {
10671067
required: false
10681068
type: string: examples: ["${KEY_PASS_ENV_VAR}", "PassWord1"]
10691069
}
1070+
server_name: {
1071+
description: """
1072+
Server name to use when using Server Name Indication (SNI).
1073+
1074+
Only relevant for outgoing connections.
1075+
"""
1076+
required: false
1077+
type: string: examples: ["www.example.com"]
1078+
}
10701079
verify_certificate: {
10711080
description: """
10721081
Enables certificate verification. For components that create a server, this requires that the

website/cue/reference/components/sinks/base/aws_sns.cue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,15 @@ base: components: sinks: aws_sns: configuration: {
659659
required: false
660660
type: string: examples: ["${KEY_PASS_ENV_VAR}", "PassWord1"]
661661
}
662+
server_name: {
663+
description: """
664+
Server name to use when using Server Name Indication (SNI).
665+
666+
Only relevant for outgoing connections.
667+
"""
668+
required: false
669+
type: string: examples: ["www.example.com"]
670+
}
662671
verify_certificate: {
663672
description: """
664673
Enables certificate verification. For components that create a server, this requires that the

website/cue/reference/components/sinks/base/aws_sqs.cue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,15 @@ base: components: sinks: aws_sqs: configuration: {
664664
required: false
665665
type: string: examples: ["${KEY_PASS_ENV_VAR}", "PassWord1"]
666666
}
667+
server_name: {
668+
description: """
669+
Server name to use when using Server Name Indication (SNI).
670+
671+
Only relevant for outgoing connections.
672+
"""
673+
required: false
674+
type: string: examples: ["www.example.com"]
675+
}
667676
verify_certificate: {
668677
description: """
669678
Enables certificate verification. For components that create a server, this requires that the

website/cue/reference/components/sinks/base/axiom.cue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,15 @@ base: components: sinks: axiom: configuration: {
323323
required: false
324324
type: string: examples: ["${KEY_PASS_ENV_VAR}", "PassWord1"]
325325
}
326+
server_name: {
327+
description: """
328+
Server name to use when using Server Name Indication (SNI).
329+
330+
Only relevant for outgoing connections.
331+
"""
332+
required: false
333+
type: string: examples: ["www.example.com"]
334+
}
326335
verify_certificate: {
327336
description: """
328337
Enables certificate verification. For components that create a server, this requires that the

website/cue/reference/components/sinks/base/azure_monitor_logs.cue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,15 @@ base: components: sinks: azure_monitor_logs: configuration: {
390390
required: false
391391
type: string: examples: ["${KEY_PASS_ENV_VAR}", "PassWord1"]
392392
}
393+
server_name: {
394+
description: """
395+
Server name to use when using Server Name Indication (SNI).
396+
397+
Only relevant for outgoing connections.
398+
"""
399+
required: false
400+
type: string: examples: ["www.example.com"]
401+
}
393402
verify_certificate: {
394403
description: """
395404
Enables certificate verification. For components that create a server, this requires that the

website/cue/reference/components/sinks/base/clickhouse.cue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,15 @@ base: components: sinks: clickhouse: configuration: {
459459
required: false
460460
type: string: examples: ["${KEY_PASS_ENV_VAR}", "PassWord1"]
461461
}
462+
server_name: {
463+
description: """
464+
Server name to use when using Server Name Indication (SNI).
465+
466+
Only relevant for outgoing connections.
467+
"""
468+
required: false
469+
type: string: examples: ["www.example.com"]
470+
}
462471
verify_certificate: {
463472
description: """
464473
Enables certificate verification. For components that create a server, this requires that the

website/cue/reference/components/sinks/base/databend.cue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,15 @@ base: components: sinks: databend: configuration: {
548548
required: false
549549
type: string: examples: ["${KEY_PASS_ENV_VAR}", "PassWord1"]
550550
}
551+
server_name: {
552+
description: """
553+
Server name to use when using Server Name Indication (SNI).
554+
555+
Only relevant for outgoing connections.
556+
"""
557+
required: false
558+
type: string: examples: ["www.example.com"]
559+
}
551560
verify_certificate: {
552561
description: """
553562
Enables certificate verification. For components that create a server, this requires that the

website/cue/reference/components/sinks/base/datadog_events.cue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,15 @@ base: components: sinks: datadog_events: configuration: {
320320
required: false
321321
type: string: examples: ["${KEY_PASS_ENV_VAR}", "PassWord1"]
322322
}
323+
server_name: {
324+
description: """
325+
Server name to use when using Server Name Indication (SNI).
326+
327+
Only relevant for outgoing connections.
328+
"""
329+
required: false
330+
type: string: examples: ["www.example.com"]
331+
}
323332
verify_certificate: {
324333
description: """
325334
Enables certificate verification. For components that create a server, this requires that the

website/cue/reference/components/sinks/base/datadog_logs.cue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,15 @@ base: components: sinks: datadog_logs: configuration: {
423423
required: false
424424
type: string: examples: ["${KEY_PASS_ENV_VAR}", "PassWord1"]
425425
}
426+
server_name: {
427+
description: """
428+
Server name to use when using Server Name Indication (SNI).
429+
430+
Only relevant for outgoing connections.
431+
"""
432+
required: false
433+
type: string: examples: ["www.example.com"]
434+
}
426435
verify_certificate: {
427436
description: """
428437
Enables certificate verification. For components that create a server, this requires that the

website/cue/reference/components/sinks/base/datadog_metrics.cue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,15 @@ base: components: sinks: datadog_metrics: configuration: {
362362
required: false
363363
type: string: examples: ["${KEY_PASS_ENV_VAR}", "PassWord1"]
364364
}
365+
server_name: {
366+
description: """
367+
Server name to use when using Server Name Indication (SNI).
368+
369+
Only relevant for outgoing connections.
370+
"""
371+
required: false
372+
type: string: examples: ["www.example.com"]
373+
}
365374
verify_certificate: {
366375
description: """
367376
Enables certificate verification. For components that create a server, this requires that the

0 commit comments

Comments
 (0)