nats-server icon indicating copy to clipboard operation
nats-server copied to clipboard

Include TLS client information in connz output

Open RedShift1 opened this issue 1 year ago • 4 comments

Feature Request

When clients connect via TLS with client side certificate validation, no information about the client is available in the HTTP monitoring endpoints. This is what the data looks like right now:

image

Use Case:

Better insight into NATS server activity and its client connections.

Proposed Change:

Add public key, fingerprints, serial, subject to connz endpoint when query parameter auth is truthy.

RedShift1 avatar Aug 01 '22 08:08 RedShift1

I like this idea, want to make sure @kozlovic and @philpennock approve as well from an idea/security standpoint.

derekcollison avatar Aug 01 '22 13:08 derekcollison

What exactly should we then report? Exporting the whole tls.Conn.ConnectionState().PeerCertificates will be way too much content. Also note that this will be empty unless the server requires client certificate. We may need a complete list of what we would want to report...

kozlovic avatar Aug 02 '22 01:08 kozlovic

Certificate subject and fingerprints would be a good start I think. Subject is typically human readable to quickly identify a certificate, the fingerprint is the truely unique identifier that can be used for, for example, database lookups.

RedShift1 avatar Aug 02 '22 08:08 RedShift1

@RedShift1 @philpennock I am struggling to know what we would need to include as the new TLS details entry. I am assuming that we would report a subset of PeerCertificates slice, but from the godoc Certificate definition here: https://pkg.go.dev/crypto/x509#Certificate, what are the fields we would want exactly?

kozlovic avatar Aug 09 '22 16:08 kozlovic

@RedShift1 @philpennock I am struggling to know what we would need to include as the new TLS details entry. I am assuming that we would report a subset of PeerCertificates slice, but from the godoc Certificate definition here: https://pkg.go.dev/crypto/x509#Certificate, what are the fields we would want exactly?

https://github.com/nats-io/nats-server/issues/3317#issuecomment-1202165750

RedShift1 avatar Aug 12 '22 12:08 RedShift1

@RedShift1 I saw your original comment, my point is that the "Subject" is actually a pkix.Name (see https://pkg.go.dev/crypto/x509/pkix#Name) and that seem a lot to return. As for the fingerprint, what would that be? A google search found this post (https://blog.abhi.host/blog/2020/02/01/Get-certificate-fingerprint-in-golang/) that seem to indicate that it would be a md5.sum of the certificate's Raw byte slice, and then make it a hex representation. Is that what it would be?

kozlovic avatar Aug 12 '22 15:08 kozlovic

@RedShift1 I saw your original comment, my point is that the "Subject" is actually a pkix.Name (see https://pkg.go.dev/crypto/x509/pkix#Name) and that seem a lot to return. As for the fingerprint, what would that be? A google search found this post (https://blog.abhi.host/blog/2020/02/01/Get-certificate-fingerprint-in-golang/) that seem to indicate that it would be a md5.sum of the certificate's Raw byte slice, and then make it a hex representation. Is that what it would be?

Yes, the fingerprint (sometimes also called thumbprint) is the hash of the certificate. MD5 used to be common but nowadays sha256 is used, for example:

image

And the subject is typically presented as a string like CN=mydevice,OU=IT,C=FR.

RedShift1 avatar Aug 15 '22 17:08 RedShift1

Thanks!

RedShift1 avatar Aug 25 '22 06:08 RedShift1