Skip to content
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

admin: Assume meshed connections are HTTP/2 #982

Merged
merged 1 commit into from
Apr 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 38 additions & 6 deletions linkerd/app/src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ pub struct Admin {
}

#[derive(Debug, Error)]
#[error("non-HTTP connection from {} (tls={:?})", self.0.client_addr, self.0.tls)]
struct NonHttpClient(TcpAccept);
#[error("non-HTTP connection from {}", self.0)]
struct NonHttpClient(Remote<ClientAddr>);

#[derive(Debug, Error)]
#[error("Unexpected TLS connection to {} from {}", self.0, self.1)]
struct UnexpectedSni(tls::ServerId, Remote<ClientAddr>);

// === impl Config ===

Expand Down Expand Up @@ -77,11 +81,39 @@ impl Config {
)| {
match version {
Ok(Some(version)) => Ok(HttpAccept::from((version, tcp))),
Err(_) => {
debug!("HTTP detection timed out; handling as HTTP/1");
Ok(HttpAccept::from((http::Version::Http1, tcp)))
// If detection timed out, we can make an educated guess
// at the proper behavior:
// - If the connection was meshed, it was most likely
// transported over HTTP/2.
// - If the connection was unmehsed, it was mostly
// likely HTTP/1.
// - If we received some unexpected SNI, the client is
// mostly likely confused/stale.
Err(_timeout) => {
let version = match tcp.tls.clone() {
tls::ConditionalServerTls::None(_) => http::Version::Http1,
tls::ConditionalServerTls::Some(tls::ServerTls::Established {
..
}) => http::Version::H2,
tls::ConditionalServerTls::Some(tls::ServerTls::Passthru {
sni,
}) => {
debug_assert!(false, "If we know the stream is non-mesh TLS, we should be able to prove its not HTTP.");
return Err(Error::from(UnexpectedSni(sni, tcp.client_addr)));
}
};
debug!(%version, "HTTP detection timed out; assuming HTTP");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe be a little more specific?

Suggested change
debug!(%version, "HTTP detection timed out; assuming HTTP");
debug!(%version, "HTTP detection timed out; assuming HTTP/2");

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not necessarily true, which is why we log the version field -- it will Http1 if no identity was present

                                tls::ConditionalServerTls::None(_) => http::Version::Http1,

Ok(HttpAccept::from((version, tcp)))
}
Ok(None) => Err(NonHttpClient(tcp)),
// If the connection failed HTTP detection, check if we
// detected TLS for another target. This might indicate
// that the client is confused/stale.
Ok(None) => match tcp.tls {
tls::ConditionalServerTls::Some(tls::ServerTls::Passthru { sni }) => {
Err(UnexpectedSni(sni, tcp.client_addr).into())
}
_ => Err(NonHttpClient(tcp.client_addr).into()),
},
}
},
)
Expand Down