From a86dc5c9202f56ed1ed9e9318b88f2e2b412fdef Mon Sep 17 00:00:00 2001 From: Ingo Oppermann Date: Wed, 28 Jun 2023 10:47:07 +0200 Subject: [PATCH] Fix make autocert manager available to followers --- cluster/cluster.go | 75 +++++++++++++++++++++++----------------------- 1 file changed, 38 insertions(+), 37 deletions(-) diff --git a/cluster/cluster.go b/cluster/cluster.go index 679d74cb..cc98135b 100644 --- a/cluster/cluster.go +++ b/cluster/cluster.go @@ -397,45 +397,46 @@ func New(ctx context.Context, config Config) (Cluster, error) { c.logger.Info().Log("Cluster is operational") if c.isTLSRequired { + // Create certificate manager + names, err := c.getClusterHostnames() + if err != nil { + c.Shutdown() + return nil, fmt.Errorf("tls: failed to assemble list of all configured hostnames: %w", err) + } + + if len(names) == 0 { + c.Shutdown() + return nil, fmt.Errorf("tls: no hostnames are configured") + } + + kvs, err := NewClusterKVS(c, c.logger.WithComponent("KVS")) + if err != nil { + c.Shutdown() + return nil, fmt.Errorf("tls: cluster KVS: %w", err) + } + + storage, err := NewClusterStorage(kvs, "core-cluster-certificates") + if err != nil { + c.Shutdown() + return nil, fmt.Errorf("tls: certificate store: %w", err) + } + + manager, err := autocert.New(autocert.Config{ + Storage: storage, + DefaultHostname: names[0], + EmailAddress: c.config.TLS.Email, + IsProduction: false, + Logger: c.logger.WithComponent("Let's Encrypt"), + }) + if err != nil { + c.Shutdown() + return nil, fmt.Errorf("tls: certificate manager: %w", err) + } + + c.certManager = manager + if c.IsRaftLeader() { // Acquire certificates - names, err := c.getClusterHostnames() - if err != nil { - c.Shutdown() - return nil, fmt.Errorf("tls: failed to assemble list of all configured hostnames: %w", err) - } - - if len(names) == 0 { - c.Shutdown() - return nil, fmt.Errorf("tls: no hostnames are configured") - } - - kvs, err := NewClusterKVS(c, c.logger.WithComponent("KVS")) - if err != nil { - c.Shutdown() - return nil, fmt.Errorf("tls: cluster KVS: %w", err) - } - - storage, err := NewClusterStorage(kvs, "core-cluster-certificates") - if err != nil { - c.Shutdown() - return nil, fmt.Errorf("tls: certificate store: %w", err) - } - - manager, err := autocert.New(autocert.Config{ - Storage: storage, - DefaultHostname: names[0], - EmailAddress: c.config.TLS.Email, - IsProduction: false, - Logger: c.logger.WithComponent("Let's Encrypt"), - }) - if err != nil { - c.Shutdown() - return nil, fmt.Errorf("tls: certificate manager: %w", err) - } - - c.certManager = manager - err = manager.AcquireCertificates(ctx, c.config.Address, names) if err != nil { c.Shutdown()