mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-01 11:08:10 +00:00
Initial Diagnose Command for TLS and Listener [VAULT-1896, VAULT-1899] (#11249)
* sanity checks for tls config in diagnose * backup * backup * backup * added necessary tests * remove comment * remove parallels causing test flakiness * comments * small fix * separate out config hcl test case into new hcl file * newline * addressed comments * addressed comments * addressed comments * addressed comments * addressed comments * reload funcs should be allowed to be nil
This commit is contained in:
@@ -871,6 +871,92 @@ func (c *ServerCommand) setupStorage(config *server.Config) (physical.Backend, e
|
||||
return backend, nil
|
||||
}
|
||||
|
||||
// InitListeners returns a response code, error message, Listeners, and a TCP Address list.
|
||||
func (c *ServerCommand) InitListeners(config *server.Config, disableClustering bool, infoKeys *[]string, info *map[string]string) (int, []listenerutil.Listener, []*net.TCPAddr, error) {
|
||||
clusterAddrs := []*net.TCPAddr{}
|
||||
|
||||
// Initialize the listeners
|
||||
lns := make([]listenerutil.Listener, 0, len(config.Listeners))
|
||||
|
||||
c.reloadFuncsLock.Lock()
|
||||
|
||||
defer c.reloadFuncsLock.Unlock()
|
||||
|
||||
var errMsg error
|
||||
for i, lnConfig := range config.Listeners {
|
||||
ln, props, reloadFunc, err := server.NewListener(lnConfig, c.gatedWriter, c.UI)
|
||||
if err != nil {
|
||||
errMsg = fmt.Errorf("Error initializing listener of type %s: %s", lnConfig.Type, err)
|
||||
return 1, nil, nil, errMsg
|
||||
}
|
||||
|
||||
if reloadFunc != nil {
|
||||
relSlice := (*c.reloadFuncs)["listener|"+lnConfig.Type]
|
||||
relSlice = append(relSlice, reloadFunc)
|
||||
(*c.reloadFuncs)["listener|"+lnConfig.Type] = relSlice
|
||||
}
|
||||
|
||||
if !disableClustering && lnConfig.Type == "tcp" {
|
||||
addr := lnConfig.ClusterAddress
|
||||
if addr != "" {
|
||||
tcpAddr, err := net.ResolveTCPAddr("tcp", lnConfig.ClusterAddress)
|
||||
if err != nil {
|
||||
errMsg = fmt.Errorf("Error resolving cluster_address: %s", err)
|
||||
return 1, nil, nil, errMsg
|
||||
}
|
||||
clusterAddrs = append(clusterAddrs, tcpAddr)
|
||||
} else {
|
||||
tcpAddr, ok := ln.Addr().(*net.TCPAddr)
|
||||
if !ok {
|
||||
errMsg = fmt.Errorf("Failed to parse tcp listener")
|
||||
return 1, nil, nil, errMsg
|
||||
}
|
||||
clusterAddr := &net.TCPAddr{
|
||||
IP: tcpAddr.IP,
|
||||
Port: tcpAddr.Port + 1,
|
||||
}
|
||||
clusterAddrs = append(clusterAddrs, clusterAddr)
|
||||
addr = clusterAddr.String()
|
||||
}
|
||||
props["cluster address"] = addr
|
||||
}
|
||||
|
||||
if lnConfig.MaxRequestSize == 0 {
|
||||
lnConfig.MaxRequestSize = vaulthttp.DefaultMaxRequestSize
|
||||
}
|
||||
props["max_request_size"] = fmt.Sprintf("%d", lnConfig.MaxRequestSize)
|
||||
|
||||
if lnConfig.MaxRequestDuration == 0 {
|
||||
lnConfig.MaxRequestDuration = vault.DefaultMaxRequestDuration
|
||||
}
|
||||
props["max_request_duration"] = lnConfig.MaxRequestDuration.String()
|
||||
|
||||
lns = append(lns, listenerutil.Listener{
|
||||
Listener: ln,
|
||||
Config: lnConfig,
|
||||
})
|
||||
|
||||
// Store the listener props for output later
|
||||
key := fmt.Sprintf("listener %d", i+1)
|
||||
propsList := make([]string, 0, len(props))
|
||||
for k, v := range props {
|
||||
propsList = append(propsList, fmt.Sprintf(
|
||||
"%s: %q", k, v))
|
||||
}
|
||||
sort.Strings(propsList)
|
||||
*infoKeys = append(*infoKeys, key)
|
||||
(*info)[key] = fmt.Sprintf(
|
||||
"%s (%s)", lnConfig.Type, strings.Join(propsList, ", "))
|
||||
|
||||
}
|
||||
if !disableClustering {
|
||||
if c.logger.IsDebug() {
|
||||
c.logger.Debug("cluster listener addresses synthesized", "cluster_addresses", clusterAddrs)
|
||||
}
|
||||
}
|
||||
return 0, lns, clusterAddrs, nil
|
||||
}
|
||||
|
||||
func (c *ServerCommand) Run(args []string) int {
|
||||
f := c.Flags()
|
||||
|
||||
@@ -1482,82 +1568,12 @@ CLUSTER_SYNTHESIS_COMPLETE:
|
||||
}
|
||||
}
|
||||
|
||||
clusterAddrs := []*net.TCPAddr{}
|
||||
status, lns, clusterAddrs, errMsg := c.InitListeners(config, disableClustering, &infoKeys, &info)
|
||||
|
||||
// Initialize the listeners
|
||||
lns := make([]listenerutil.Listener, 0, len(config.Listeners))
|
||||
c.reloadFuncsLock.Lock()
|
||||
for i, lnConfig := range config.Listeners {
|
||||
ln, props, reloadFunc, err := server.NewListener(lnConfig, c.gatedWriter, c.UI)
|
||||
if err != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error initializing listener of type %s: %s", lnConfig.Type, err))
|
||||
return 1
|
||||
}
|
||||
|
||||
if reloadFunc != nil {
|
||||
relSlice := (*c.reloadFuncs)["listener|"+lnConfig.Type]
|
||||
relSlice = append(relSlice, reloadFunc)
|
||||
(*c.reloadFuncs)["listener|"+lnConfig.Type] = relSlice
|
||||
}
|
||||
|
||||
if !disableClustering && lnConfig.Type == "tcp" {
|
||||
addr := lnConfig.ClusterAddress
|
||||
if addr != "" {
|
||||
tcpAddr, err := net.ResolveTCPAddr("tcp", lnConfig.ClusterAddress)
|
||||
if err != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error resolving cluster_address: %s", err))
|
||||
return 1
|
||||
}
|
||||
clusterAddrs = append(clusterAddrs, tcpAddr)
|
||||
} else {
|
||||
tcpAddr, ok := ln.Addr().(*net.TCPAddr)
|
||||
if !ok {
|
||||
c.UI.Error("Failed to parse tcp listener")
|
||||
return 1
|
||||
}
|
||||
clusterAddr := &net.TCPAddr{
|
||||
IP: tcpAddr.IP,
|
||||
Port: tcpAddr.Port + 1,
|
||||
}
|
||||
clusterAddrs = append(clusterAddrs, clusterAddr)
|
||||
addr = clusterAddr.String()
|
||||
}
|
||||
props["cluster address"] = addr
|
||||
}
|
||||
|
||||
if lnConfig.MaxRequestSize == 0 {
|
||||
lnConfig.MaxRequestSize = vaulthttp.DefaultMaxRequestSize
|
||||
}
|
||||
props["max_request_size"] = fmt.Sprintf("%d", lnConfig.MaxRequestSize)
|
||||
|
||||
if lnConfig.MaxRequestDuration == 0 {
|
||||
lnConfig.MaxRequestDuration = vault.DefaultMaxRequestDuration
|
||||
}
|
||||
props["max_request_duration"] = fmt.Sprintf("%s", lnConfig.MaxRequestDuration.String())
|
||||
|
||||
lns = append(lns, listenerutil.Listener{
|
||||
Listener: ln,
|
||||
Config: lnConfig,
|
||||
})
|
||||
|
||||
// Store the listener props for output later
|
||||
key := fmt.Sprintf("listener %d", i+1)
|
||||
propsList := make([]string, 0, len(props))
|
||||
for k, v := range props {
|
||||
propsList = append(propsList, fmt.Sprintf(
|
||||
"%s: %q", k, v))
|
||||
}
|
||||
sort.Strings(propsList)
|
||||
infoKeys = append(infoKeys, key)
|
||||
info[key] = fmt.Sprintf(
|
||||
"%s (%s)", lnConfig.Type, strings.Join(propsList, ", "))
|
||||
|
||||
}
|
||||
c.reloadFuncsLock.Unlock()
|
||||
if !disableClustering {
|
||||
if c.logger.IsDebug() {
|
||||
c.logger.Debug("cluster listener addresses synthesized", "cluster_addresses", clusterAddrs)
|
||||
}
|
||||
if status != 0 {
|
||||
c.UI.Output("Error parsing listener configuration.")
|
||||
c.UI.Error(errMsg.Error())
|
||||
return 1
|
||||
}
|
||||
|
||||
// Make sure we close all listeners from this point on
|
||||
|
||||
Reference in New Issue
Block a user