autocert: use atomic pointer to allow nil (#3817)

autocert: use atomic pointer to allow nil (#3816)

Co-authored-by: Caleb Doxsey <cdoxsey@pomerium.com>
This commit is contained in:
backport-actions-token[bot] 2022-12-16 13:49:44 -07:00 committed by GitHub
parent 8924c47392
commit f68ea66006
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -11,6 +11,7 @@ import (
"net/http" "net/http"
"sort" "sort"
"sync" "sync"
"sync/atomic"
"time" "time"
"github.com/caddyserver/certmagic" "github.com/caddyserver/certmagic"
@ -19,7 +20,6 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
"github.com/pomerium/pomerium/config" "github.com/pomerium/pomerium/config"
"github.com/pomerium/pomerium/internal/atomicutil"
"github.com/pomerium/pomerium/internal/httputil" "github.com/pomerium/pomerium/internal/httputil"
"github.com/pomerium/pomerium/internal/log" "github.com/pomerium/pomerium/internal/log"
"github.com/pomerium/pomerium/internal/telemetry/metrics" "github.com/pomerium/pomerium/internal/telemetry/metrics"
@ -48,7 +48,7 @@ type Manager struct {
mu sync.RWMutex mu sync.RWMutex
config *config.Config config *config.Config
certmagic *certmagic.Config certmagic *certmagic.Config
acmeMgr *atomicutil.Value[*certmagic.ACMEIssuer] acmeMgr atomic.Pointer[certmagic.ACMEIssuer]
srv *http.Server srv *http.Server
acmeTLSALPNListener net.Listener acmeTLSALPNListener net.Listener
@ -90,7 +90,6 @@ func newManager(ctx context.Context,
mgr := &Manager{ mgr := &Manager{
src: src, src: src,
acmeTemplate: acmeTemplate, acmeTemplate: acmeTemplate,
acmeMgr: atomicutil.NewValue(new(certmagic.ACMEIssuer)),
certmagic: certmagicConfig, certmagic: certmagicConfig,
ocspCache: ocspRespCache, ocspCache: ocspRespCache,
} }
@ -265,6 +264,7 @@ func (mgr *Manager) renewCert(ctx context.Context, domain string, cert certmagic
func (mgr *Manager) updateAutocert(ctx context.Context, cfg *config.Config) error { func (mgr *Manager) updateAutocert(ctx context.Context, cfg *config.Config) error {
if !cfg.Options.AutocertOptions.Enable { if !cfg.Options.AutocertOptions.Enable {
mgr.acmeMgr.Store(nil)
return nil return nil
} }