Remove ALPN Muxer (#1965)
We never ended up using this and it makes it much harder to reason about the listeners. An explanation: for the moment I separated out all of the listeners in the struct, even though one should suffice, because when I did it that way first I was hitting some really weird and hard to find intermittent behavior where it seemed like the listeners were getting crossed. So I re-did it this way with each listener very explicitly referenced. I'm happy to make a follow-up PR that attempts to combine them all into a single listener without hitting the issues I did, if desired, but at least doing it via a separate PR means that it won't be something with removing the ALPN muxer that is at fault.
This commit is contained in:
1 parent
ce7292d9c8
commit
07dc3db974
13 files changed
+191
-832
No files matched your search
@@ -11,8 +11,8 @@ import (
|
||||
// We must import sha512 so that it registers with the runtime so that
|
||||
// certificates that use it can be parsed.
|
||||
_ "crypto/sha512"
|
||||
"crypto/tls"
|
||||
|
||||
"github.com/hashicorp/boundary/internal/libs/alpnmux"
|
||||
"github.com/hashicorp/go-secure-stdlib/listenerutil"
|
||||
"github.com/hashicorp/go-secure-stdlib/reloadutil"
|
||||
"github.com/mitchellh/cli"
|
||||
@@ -21,11 +21,13 @@ import (
|
||||
)
|
||||
|
||||
type ServerListener struct {
|
||||
Mux *alpnmux.ALPNMux
|
||||
Config *listenerutil.ListenerConfig
|
||||
HTTPServer *http.Server
|
||||
GrpcServer *grpc.Server
|
||||
ALPNListener net.Listener
|
||||
Config *listenerutil.ListenerConfig
|
||||
HTTPServer *http.Server
|
||||
GrpcServer *grpc.Server
|
||||
ApiListener net.Listener
|
||||
ClusterListener net.Listener
|
||||
ProxyListener net.Listener
|
||||
OpsListener net.Listener
|
||||
}
|
||||
|
||||
type WorkerAuthInfo struct {
|
||||
@@ -47,7 +49,7 @@ var BuiltinListeners = map[string]ListenerFactory{
|
||||
|
||||
// New creates a new listener of the given type with the given
|
||||
// configuration. The type is looked up in the BuiltinListeners map.
|
||||
func NewListener(l *listenerutil.ListenerConfig, ui cli.Ui) (*alpnmux.ALPNMux, map[string]string, reloadutil.ReloadFunc, error) {
|
||||
func NewListener(l *listenerutil.ListenerConfig, ui cli.Ui) (net.Listener, map[string]string, reloadutil.ReloadFunc, error) {
|
||||
f, ok := BuiltinListeners[l.Type]
|
||||
if !ok {
|
||||
return nil, nil, nil, fmt.Errorf("unknown listener type: %q", l.Type)
|
||||
@@ -58,8 +60,23 @@ func NewListener(l *listenerutil.ListenerConfig, ui cli.Ui) (*alpnmux.ALPNMux, m
|
||||
}
|
||||
purpose := l.Purpose[0]
|
||||
|
||||
finalAddr, ln, err := f(purpose, l, ui)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
ln, err = listenerWrapProxy(ln, l)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
props := map[string]string{
|
||||
"addr": finalAddr,
|
||||
}
|
||||
|
||||
switch purpose {
|
||||
case "cluster":
|
||||
// We handle our own cluster authentication
|
||||
l.TLSDisable = true
|
||||
case "proxy":
|
||||
// TODO: Eventually we'll support bringing your own cert, and we'd only
|
||||
@@ -78,24 +95,8 @@ func NewListener(l *listenerutil.ListenerConfig, ui cli.Ui) (*alpnmux.ALPNMux, m
|
||||
}
|
||||
}
|
||||
|
||||
finalAddr, ln, err := f(purpose, l, ui)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
ln, err = listenerWrapProxy(ln, l)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
props := map[string]string{
|
||||
"addr": finalAddr,
|
||||
}
|
||||
|
||||
alpnMux := alpnmux.New(ln)
|
||||
|
||||
if l.TLSDisable {
|
||||
return alpnMux, props, nil, nil
|
||||
return ln, props, nil, nil
|
||||
}
|
||||
|
||||
// Don't request a client cert unless they've explicitly configured it to do
|
||||
@@ -107,23 +108,15 @@ func NewListener(l *listenerutil.ListenerConfig, ui cli.Ui) (*alpnmux.ALPNMux, m
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
// Register no proto, "http/1.1", and "h2", with same TLS config
|
||||
if _, err = alpnMux.RegisterProto("", tlsConfig); err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
if _, err = alpnMux.RegisterProto("http/1.1", tlsConfig); err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
if _, err = alpnMux.RegisterProto("h2", tlsConfig); err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
return alpnMux, props, reloadFunc, nil
|
||||
return tls.NewListener(ln, tlsConfig), props, reloadFunc, nil
|
||||
}
|
||||
|
||||
func tcpListenerFactory(purpose string, l *listenerutil.ListenerConfig, ui cli.Ui) (string, net.Listener, error) {
|
||||
if l.Address == "" {
|
||||
switch purpose {
|
||||
case "api":
|
||||
l.Address = "127.0.0.1:9200"
|
||||
case "cluster":
|
||||
l.Address = "127.0.0.1:9201"
|
||||
case "proxy":
|
||||
@@ -131,7 +124,7 @@ func tcpListenerFactory(purpose string, l *listenerutil.ListenerConfig, ui cli.U
|
||||
case "ops":
|
||||
l.Address = "127.0.0.1:9203"
|
||||
default:
|
||||
l.Address = "127.0.0.1:9200"
|
||||
return "", nil, errors.New("no purpose provided for listener and no address given")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,6 +132,8 @@ func tcpListenerFactory(purpose string, l *listenerutil.ListenerConfig, ui cli.U
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "missing port") {
|
||||
switch purpose {
|
||||
case "api":
|
||||
port = "9200"
|
||||
case "cluster":
|
||||
port = "9201"
|
||||
case "proxy":
|
||||
@@ -146,7 +141,7 @@ func tcpListenerFactory(purpose string, l *listenerutil.ListenerConfig, ui cli.U
|
||||
case "ops":
|
||||
port = "9203"
|
||||
default:
|
||||
port = "9200"
|
||||
return "", nil, errors.New("no purpose provided for listener and no port discoverable")
|
||||
}
|
||||
host = l.Address
|
||||
} else {
|
||||
|
||||
@@ -381,7 +381,18 @@ func (b *Server) SetupListeners(ui cli.Ui, config *configutil.SharedConfig, allo
|
||||
// we ignore errors
|
||||
b.ShutdownFuncs = append(b.ShutdownFuncs, func() error {
|
||||
for _, ln := range b.Listeners {
|
||||
ln.Mux.Close()
|
||||
if ln.ProxyListener != nil {
|
||||
ln.ProxyListener.Close()
|
||||
}
|
||||
if ln.ClusterListener != nil {
|
||||
ln.ClusterListener.Close()
|
||||
}
|
||||
if ln.ApiListener != nil {
|
||||
ln.ApiListener.Close()
|
||||
}
|
||||
if ln.OpsListener != nil {
|
||||
ln.OpsListener.Close()
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
@@ -414,7 +425,7 @@ func (b *Server) SetupListeners(ui cli.Ui, config *configutil.SharedConfig, allo
|
||||
}
|
||||
}
|
||||
|
||||
lnMux, props, reloadFunc, err := NewListener(lnConfig, ui)
|
||||
ln, props, reloadFunc, err := NewListener(lnConfig, ui)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error initializing listener of type %s: %w", lnConfig.Type, err)
|
||||
}
|
||||
@@ -460,10 +471,22 @@ func (b *Server) SetupListeners(ui cli.Ui, config *configutil.SharedConfig, allo
|
||||
}
|
||||
props["max_request_duration"] = lnConfig.MaxRequestDuration.String()
|
||||
|
||||
b.Listeners = append(b.Listeners, &ServerListener{
|
||||
Mux: lnMux,
|
||||
serverListener := &ServerListener{
|
||||
Config: lnConfig,
|
||||
})
|
||||
}
|
||||
|
||||
switch purpose {
|
||||
case "api":
|
||||
serverListener.ApiListener = ln
|
||||
case "cluster":
|
||||
serverListener.ClusterListener = ln
|
||||
case "proxy":
|
||||
serverListener.ProxyListener = ln
|
||||
case "ops":
|
||||
serverListener.OpsListener = ln
|
||||
}
|
||||
|
||||
b.Listeners = append(b.Listeners, serverListener)
|
||||
|
||||
props["purpose"] = strings.Join(lnConfig.Purpose, ",")
|
||||
|
||||
|
||||
Reference in new issue
Block a user