Put session ID in ALPN (#1966)
This allows us to use SNI for actual host (e.g. routing) information. We don't have the client cert yet so we can't look at that, so this provides a way for us to convey the information needed to look up that session's TLS stack. Using SNI for hosts means we also run into the fact that we don't have automatic agreement in terms of SANs. So when generating the certs we now also pass worker address information to the function to be encoded in the cert. Finally, there is a change in how the websocket dialing happens, because http.RoundTripper tries to be too clever for its own good and overwrites NextProtos on a whim.
This commit is contained in:
1 parent
62f0d18885
commit
58a448fc6a
12 files changed
+176
-39
No files matched your search
@@ -427,6 +427,15 @@ func (c *Command) Run(args []string) (retCode int) {
|
||||
|
||||
c.connectionsLeft.Store(c.sessionAuthzData.ConnectionLimit)
|
||||
workerAddr := c.sessionAuthzData.GetWorkerInfo()[0].GetAddress()
|
||||
workerHost, _, err := net.SplitHostPort(workerAddr)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "missing port") {
|
||||
workerHost = workerAddr
|
||||
} else {
|
||||
c.PrintCliError(fmt.Errorf("Error splitting worker adddress host/port: %w", err))
|
||||
return base.CommandUserError
|
||||
}
|
||||
}
|
||||
|
||||
parsedCert, err := x509.ParseCertificate(c.sessionAuthzData.Certificate)
|
||||
if err != nil {
|
||||
@@ -434,11 +443,6 @@ func (c *Command) Run(args []string) (retCode int) {
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
if len(parsedCert.DNSNames) != 1 {
|
||||
c.PrintCliError(fmt.Errorf("mTLS certificate has invalid parameters: %w", err))
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
c.expiration = parsedCert.NotAfter
|
||||
|
||||
// We don't _rely_ on client-side timeout verification but this prevents us
|
||||
@@ -459,16 +463,20 @@ func (c *Command) Run(args []string) (retCode int) {
|
||||
},
|
||||
},
|
||||
RootCAs: certPool,
|
||||
ServerName: parsedCert.DNSNames[0],
|
||||
ServerName: workerHost,
|
||||
MinVersion: tls.VersionTLS13,
|
||||
NextProtos: []string{"http/1.1", c.sessionAuthzData.SessionId},
|
||||
}
|
||||
|
||||
transport := cleanhttp.DefaultTransport()
|
||||
transport.DisableKeepAlives = false
|
||||
transport.TLSClientConfig = tlsConf
|
||||
// This isn't/shouldn't used anyways really because the connection is
|
||||
// hijacked, just setting for completeness
|
||||
transport.IdleConnTimeout = 0
|
||||
transport.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||
dialer := &tls.Dialer{Config: tlsConf}
|
||||
return dialer.DialContext(ctx, network, addr)
|
||||
}
|
||||
|
||||
c.listener, err = net.ListenTCP("tcp", &net.TCPAddr{
|
||||
IP: listenAddr,
|
||||
@@ -691,7 +699,7 @@ func (c *Command) getWsConn(
|
||||
) (*websocket.Conn, error) {
|
||||
conn, resp, err := websocket.Dial(
|
||||
ctx,
|
||||
fmt.Sprintf("wss://%s/v1/proxy", workerAddr),
|
||||
fmt.Sprintf("ws://%s/v1/proxy", workerAddr),
|
||||
&websocket.DialOptions{
|
||||
HTTPClient: &http.Client{
|
||||
Transport: transport,
|
||||
|
||||
Reference in new issue
Block a user