-
Notifications
You must be signed in to change notification settings - Fork 268
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
Suggestions for #3160 #3272
Merged
Merged
Suggestions for #3160 #3272
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
use crate::{ | ||
server::{detect_sni, DetectIo}, | ||
ServerName, | ||
}; | ||
use linkerd_error::Error; | ||
use linkerd_io as io; | ||
use linkerd_stack::{layer, NewService, Service, ServiceExt}; | ||
use std::{ | ||
future::Future, | ||
pin::Pin, | ||
task::{Context, Poll}, | ||
}; | ||
use thiserror::Error; | ||
use tokio::time; | ||
use tracing::debug; | ||
|
||
#[derive(Clone, Debug, Error)] | ||
#[error("SNI detection timed out")] | ||
pub struct SniDetectionTimeoutError; | ||
|
||
#[derive(Clone, Debug, Error)] | ||
#[error("Could not find SNI")] | ||
pub struct NoSniFoundError; | ||
|
||
/// A NewService that instruments an inner stack with knowledge of the | ||
/// connection's TLS ServerName (i.e. from an SNI header). | ||
/// | ||
/// This differs from the parent module's NewDetectTls in a a few ways: | ||
/// | ||
/// - It requires that all connections have an SNI. | ||
/// - It assumes that these connections may not be terminated locally, so there | ||
/// is no concept of a local server name. | ||
/// - There are no special affordances for mutually authenticated TLS, so we | ||
/// make no attempt to detect the client's identity. | ||
/// - The detection timeout is fixed and cannot vary per target (for | ||
/// convenience, to reduce needless boilerplate). | ||
#[derive(Clone, Debug)] | ||
pub struct NewDetectRequiredSni<N> { | ||
inner: N, | ||
timeout: time::Duration, | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct DetectRequiredSni<T, N> { | ||
target: T, | ||
inner: N, | ||
timeout: time::Duration, | ||
} | ||
|
||
impl<N> NewDetectRequiredSni<N> { | ||
fn new(timeout: time::Duration, inner: N) -> Self { | ||
Self { inner, timeout } | ||
} | ||
|
||
pub fn layer(timeout: time::Duration) -> impl layer::Layer<N, Service = Self> + Clone { | ||
layer::mk(move |inner| Self::new(timeout, inner)) | ||
} | ||
} | ||
|
||
impl<T, N> NewService<T> for NewDetectRequiredSni<N> | ||
where | ||
N: Clone, | ||
{ | ||
type Service = DetectRequiredSni<T, N>; | ||
|
||
fn new_service(&self, target: T) -> Self::Service { | ||
DetectRequiredSni::new(self.timeout, target, self.inner.clone()) | ||
} | ||
} | ||
|
||
// === impl DetectSni === | ||
|
||
impl<T, N> DetectRequiredSni<T, N> { | ||
fn new(timeout: time::Duration, target: T, inner: N) -> Self { | ||
Self { | ||
target, | ||
inner, | ||
timeout, | ||
} | ||
} | ||
} | ||
|
||
impl<T, I, N, S> Service<I> for DetectRequiredSni<T, N> | ||
where | ||
T: Clone + Send + Sync + 'static, | ||
I: io::AsyncRead + io::Peek + io::AsyncWrite + Send + Sync + Unpin + 'static, | ||
N: NewService<(ServerName, T), Service = S> + Clone + Send + 'static, | ||
S: Service<DetectIo<I>> + Send, | ||
S::Error: Into<Error>, | ||
S::Future: Send, | ||
{ | ||
type Response = S::Response; | ||
type Error = Error; | ||
type Future = Pin<Box<dyn Future<Output = Result<S::Response, Error>> + Send + 'static>>; | ||
|
||
#[inline] | ||
fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> { | ||
Poll::Ready(Ok(())) | ||
} | ||
|
||
fn call(&mut self, io: I) -> Self::Future { | ||
let target = self.target.clone(); | ||
let new_accept = self.inner.clone(); | ||
|
||
// Detect the SNI from a ClientHello (or timeout). | ||
let detect = time::timeout(self.timeout, detect_sni(io)); | ||
Box::pin(async move { | ||
let (res, io) = detect.await.map_err(|_| SniDetectionTimeoutError)??; | ||
let sni = res.ok_or(NoSniFoundError)?; | ||
debug!(?sni, "Detected TLS"); | ||
|
||
let svc = new_accept.new_service((sni, target)); | ||
svc.oneshot(io).await.map_err(Into::into) | ||
}) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What are the special affordances in the other case? From my understand, in the
DetectTLS
, we determine whether we terminate based on whether the SNI matches the local identitty. Is that what you are refering to here?