Skip to content

access logging: pass downstream TLS information to access logs#6144

Merged
htuch merged 17 commits intoenvoyproxy:masterfrom
snowp:ssl-stream
Mar 19, 2019
Merged

access logging: pass downstream TLS information to access logs#6144
htuch merged 17 commits intoenvoyproxy:masterfrom
snowp:ssl-stream

Conversation

@snowp
Copy link
Contributor

@snowp snowp commented Mar 1, 2019

Passes along the Ssl::ConnectionInfo (renamed from Ssl::Connection)
to StreamInfo, allowing it to be read in access loggers. Updates both
the formatter and gRPC access logger with uri san/subject details,
and adds the SNI to the gRPC access log.

Signed-off-by: Snow Pettersen snowp@squareup.com

Risk Level: Low
Testing: Unit tests
Docs Changes: Added description for new access log formats
Release Notes: n/a
#4926

Passes along the Ssl::ConnectionInfo to StreamInfo, allowing it to be
read in access loggers. Updates both the formatter and gRPC access
logger with uri san/subject details, and wires up the SNI to the gRPC
access log.

Signed-off-by: Snow Pettersen <snowp@squareup.com>
@snowp snowp requested a review from htuch as a code owner March 1, 2019 15:48
@snowp
Copy link
Contributor Author

snowp commented Mar 1, 2019

This only exposes the SSL information that I found readily available, but it should be easy to expose whatever bits anyone's interested now by adding getters to Ssl::ConnectionInfo + reading it in the
access logs.

@snowp
Copy link
Contributor Author

snowp commented Mar 1, 2019

/retest

@repokitteh-read-only
Copy link

🐴 hold your horses - no failures detected, yet.

🐱

Caused by: a #6144 (comment) was created by @snowp.

see: more, trace.

Signed-off-by: Snow Pettersen <snowp@squareup.com>
@lizan lizan self-assigned this Mar 1, 2019

namespace {

// Helper that handles the case when the ConectionInfo is missiring or if the desired value is
Copy link
Member

Choose a reason for hiding this comment

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

nit: s/missiring/missing


message CertificateProperties {
// The URI in the SAN field of the certificate.
string uri_san = 1;
Copy link
Member

Choose a reason for hiding this comment

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

this is not quite reflect what is in X.509, perhaps something like:

message SubjectAltName {
  oneof {
    string uri;
    string dns;
  }
}
repeated SubjectAltName subject_alt_names;

@PiotrSikora?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, seems like SAN should be a repeated.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry. I did not see this earlier. We already have CertificateDetails message which does what @lizan mentioned above. Probably there is a chance to reuse here

message CertificateDetails {

* @return the const SSL connection data if this is an SSL connection, or nullptr if it is not.
*/
virtual const Ssl::Connection* ssl() const PURE;
virtual const Ssl::ConnectionInfo* ssl() const PURE;
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to remove this interface from Connection and move into StreamInfo? If the change will be too heavy just leave a TODO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll add a TODO, it seems to require changing a bunch of functions that pass the connection around

}

void setDownstreamSslConnection(const Ssl::ConnectionInfo* connection_info) override {
downstream_ssl_info_ = connection_info;
Copy link
Member

Choose a reason for hiding this comment

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

I'm slightly worried that StreamInfoImpl might outlive Ssl::ConnectionInfo, will that be the case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From what I can tell it seems like Ssl::ConnectionInfo/Network::Connection comes from the FilterManagerImpl which should outlive the Filters that the StreamInfoImpl belongs to. Do you think it would be useful to expose the ConnectionInfo as a shared ptr to avoid potential lifetime issues in the future?

Copy link
Member

Choose a reason for hiding this comment

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

No I think it is fine to leave as is.

Signed-off-by: Snow Pettersen <snowp@squareup.com>
dio
dio previously approved these changes Mar 1, 2019
Copy link
Member

@dio dio left a comment

Choose a reason for hiding this comment

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

Thanks @snowp, Looks good for me.

* Base connection interface for all SSL connections.
*/
class Connection {
class ConnectionInfo {
Copy link
Member

Choose a reason for hiding this comment

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

+1


// Helper that handles the case when the ConectionInfo is missiring or if the desired value is
// empty.
StreamInfoFormatter::FieldExtractor sslConnectionStringInfoExtractor(
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if sslConnectionInfoStringExtractor sounds better.

Copy link
Member

Choose a reason for hiding this comment

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

+1

Copy link
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

LG overall, CI seems b0rk3d.

// empty.
StreamInfoFormatter::FieldExtractor sslConnectionStringInfoExtractor(
std::function<std::string(const Ssl::ConnectionInfo& connection_info)> string_extractor) {
return [=](const StreamInfo::StreamInfo& stream_info) {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: prefer explicit capture.


// Helper that handles the case when the ConectionInfo is missiring or if the desired value is
// empty.
StreamInfoFormatter::FieldExtractor sslConnectionStringInfoExtractor(
Copy link
Member

Choose a reason for hiding this comment

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

+1

Snow Pettersen added 2 commits March 5, 2019 23:27
Signed-off-by: Snow Pettersen <snowp@squareup.com>
Signed-off-by: Snow Pettersen <snowp@squareup.com>
Snow Pettersen added 2 commits March 6, 2019 01:28
Signed-off-by: Snow Pettersen <snowp@squareup.com>
Signed-off-by: Snow Pettersen <snowp@squareup.com>
TCP
String value set on ssl connection socket for Server Name Indication (SNI)

%DOWNSTREAM_LOCAL_URI_SAN%
Copy link
Member

Choose a reason for hiding this comment

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

Not directly actionable in this PR perhaps, but need to think about how to structurally express those field in logging format and keep file access log feature parity with gRPC. We'll likely have upstream TLS set for this as well, and other properties which is defined in accesslog.proto.

Some random idea would be making the proto representation as first class, and have some expression in file access log to represent extractor from there.

} else if (field_name == "DOWNSTREAM_PEER_URI_SAN") {
field_extractor_ =
sslConnectionInfoStringExtractor([](const Ssl::ConnectionInfo& connection_info) {
return connection_info.uriSanPeerCertificate();
Copy link
Member

Choose a reason for hiding this comment

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

When I look at how SslSocket::uriSanPeerCertificate() implemented today, it seems that it should really be returning all SAN. Should we fix this, so that we create template patterns that are stable and forward compatible? CC @PiotrSikora

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure I don't mind fixing that. I'll just have all current usage just use the first SAN from the new function

message SubjectAltName {
oneof san {
string uri = 1;
string dns = 2;
Copy link
Member

Choose a reason for hiding this comment

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

Is this used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no, i'll remove

Copy link
Member

Choose a reason for hiding this comment

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

A not implemented annotation is also fine.

Signed-off-by: Snow Pettersen <snowp@squareup.com>
Snow Pettersen added 2 commits March 11, 2019 15:39
Signed-off-by: Snow Pettersen <snowp@squareup.com>
Signed-off-by: Snow Pettersen <snowp@squareup.com>
Snow Pettersen added 3 commits March 11, 2019 16:21
Signed-off-by: Snow Pettersen <snowp@squareup.com>
Signed-off-by: Snow Pettersen <snowp@squareup.com>
Signed-off-by: Snow Pettersen <snowp@squareup.com>
@htuch
Copy link
Member

htuch commented Mar 12, 2019

@snowp need master merge.

Copy link
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

Looks good, just one question (which is somewhat orthogonal to what you're doing here anyway..).

@htuch htuch added the waiting label Mar 12, 2019
Signed-off-by: Snow Pettersen <snowp@squareup.com>
Signed-off-by: Snow Pettersen <snowp@squareup.com>
Copy link
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

LGTM, needs master merge. Do we want release notes?

@htuch htuch added the waiting label Mar 15, 2019
Snow Pettersen added 2 commits March 18, 2019 14:34
Signed-off-by: Snow Pettersen <snowp@squareup.com>
Signed-off-by: Snow Pettersen <snowp@squareup.com>
Copy link
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

Great, thanks @snowp!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants