-
Notifications
You must be signed in to change notification settings - Fork 334
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
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 ? |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason for dropping DialTLSWithBackOff
?
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.
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
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/hold cancel |
Current
NewProxyAutoTLSTransport
takesTLSConfig
. 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
NewProxyAutoTLSTransport
withTLSConfig
. ButNewProxyAutoTLSTransport
was added for internal encryption #2479 1 year ago. If an user wantsNewProxyAutoTLSTransport
to takeTLSConfig
we can add it later.See also knative/serving#14452