Use DialTLSContextFunc instead of tls.Config for NewProxyAutoTLSTransport#2842
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #2842 +/- ##
==========================================
- Coverage 81.82% 81.81% -0.02%
==========================================
Files 167 167
Lines 10224 10222 -2
==========================================
- Hits 8366 8363 -3
Misses 1612 1612
- Partials 246 247 +1
☔ View full report in Codecov by Sentry. |
|
So by switching to use the DialTLSContext, it will let us insert some custom logic to handle setting up the TLS connection, such as verifying a custom SAN? Reading this, and your linked PR to serving, it looks like it goes together nicely. But just for my understanding, why is the GetCertificate function on the TLSConfig not enough for this case? My understanding was you could use that to get SAN info from the client hello, and in there you could return the correct cert. Perhaps I'm mixing things up? |
Yes, that's right.
We want the client to validate if the server certificate matches the certificate of the expected namespace - i.e., to prevent MITM attacks. |
Okay I see, I was mixing up client and server activities. Thanks for taking the time to explain that, I appreciate it 👍 Seems like a good change to me, but perhaps you want Dave or Reto to see it as well? |
|
I learned how to use these labels lol It looks good to me, but I'll put it on hold. @nak3 feel free to unhold, or keep it held for Reto or someone else to look at. /lgtm |
|
@dprotaso Could you please take a look at this and knative/serving#14452 ? |
dprotaso
left a comment
There was a problem hiding this comment.
It might be simpler to plumb in a tls.Config with GetConfigForClient set?
| return DialTLSWithBackOff(context.Background(), | ||
| netw, addr, tlsConf) | ||
| DialTLSContext: func(ctx context.Context, network, addr string, cfg *tls.Config) (net.Conn, error) { | ||
| return tlsContext(ctx, network, addr) |
There was a problem hiding this comment.
Any reason for dropping DialTLSWithBackOff ?
There was a problem hiding this comment.
DialWithBackOff is called downstream knative/serving#14452.
If we keep DialWithBackOff and call it here, we need to bring tlsConf as an extra argument of newH2Transport(). Is it better to call DialTLSWithBackOff here?
[1] https://pkg.go.dev/crypto/tls#Config
|
|
/test unit-tests |
|
/lgtm |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: dprotaso, nak3 The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/hold cancel |
Current
NewProxyAutoTLSTransporttakesTLSConfig. It is easy to use but impossible to customize to verify custom SAN.So, this patch replaces it with
DialTLSContext.Alternative
I considered a downstream may be using
NewProxyAutoTLSTransportwithTLSConfig. ButNewProxyAutoTLSTransportwas added for internal encryption #2479 1 year ago. If an user wantsNewProxyAutoTLSTransportto takeTLSConfigwe can add it later.See also knative/serving#14452