mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-10-30 18:17:55 +00:00
* Adding explicit MPL license for sub-package. This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Adding explicit MPL license for sub-package. This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Updating the license from MPL to Business Source License. Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at https://hashi.co/bsl-blog, FAQ at www.hashicorp.com/licensing-faq, and details of the license at www.hashicorp.com/bsl. * add missing license headers * Update copyright file headers to BUS-1.1 * Fix test that expected exact offset on hcl file --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com> Co-authored-by: Sarah Thompson <sthompson@hashicorp.com> Co-authored-by: Brian Kassouf <bkassouf@hashicorp.com>
59 lines
1.7 KiB
Go
59 lines
1.7 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package server
|
|
|
|
import (
|
|
_ "crypto/sha512"
|
|
"fmt"
|
|
"io"
|
|
"net"
|
|
|
|
// We must import sha512 so that it registers with the runtime so that
|
|
// certificates that use it can be parsed.
|
|
|
|
"github.com/hashicorp/go-secure-stdlib/reloadutil"
|
|
"github.com/hashicorp/vault/helper/proxyutil"
|
|
"github.com/hashicorp/vault/internalshared/configutil"
|
|
"github.com/mitchellh/cli"
|
|
)
|
|
|
|
// ListenerFactory is the factory function to create a listener.
|
|
type ListenerFactory func(*configutil.Listener, io.Writer, cli.Ui) (net.Listener, map[string]string, reloadutil.ReloadFunc, error)
|
|
|
|
// BuiltinListeners is the list of built-in listener types.
|
|
var BuiltinListeners = map[string]ListenerFactory{
|
|
"tcp": tcpListenerFactory,
|
|
"unix": unixListenerFactory,
|
|
}
|
|
|
|
// NewListener creates a new listener of the given type with the given
|
|
// configuration. The type is looked up in the BuiltinListeners map.
|
|
func NewListener(l *configutil.Listener, logger io.Writer, 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)
|
|
}
|
|
|
|
return f(l, logger, ui)
|
|
}
|
|
|
|
func listenerWrapProxy(ln net.Listener, l *configutil.Listener) (net.Listener, error) {
|
|
behavior := l.ProxyProtocolBehavior
|
|
if behavior == "" {
|
|
return ln, nil
|
|
}
|
|
|
|
proxyProtoConfig := &proxyutil.ProxyProtoConfig{
|
|
Behavior: behavior,
|
|
AuthorizedAddrs: l.ProxyProtocolAuthorizedAddrs,
|
|
}
|
|
|
|
newLn, err := proxyutil.WrapInProxyProto(ln, proxyProtoConfig)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed configuring PROXY protocol wrapper: %w", err)
|
|
}
|
|
|
|
return newLn, nil
|
|
}
|