Skip to content

tls: certificates auto renewal will become stuck if issuer is changed between config reloads #6732

@WeidiDeng

Description

@WeidiDeng

When config is reloaded with a changed acme issuer, certmagic will check for the existence of the certificate of created from the new issuer next time certificate should be issued. These certificates don't exist because we want to use them to be created in the first place. certmagic will try in vain for 30 days to renew these certificates.

Detailed explanation:

When caddy is starting, a global tls cache is created if needed

certCacheMu.Lock()
if certCache == nil {
certCache = certmagic.NewCache(cacheOpts)
} else {
certCache.SetOptions(cacheOpts)
}
certCacheMu.Unlock()

it will be destroyed if tls is not used anymore

} else {
// no more TLS app running, so delete in-memory cert cache
certCache.Stop()
certCacheMu.Lock()
certCache = nil
certCacheMu.Unlock()
}

TLS cache will start renewing certificates in the background

https://github.com/caddyserver/certmagic/blob/3fcd710c0cfc6d80026011c8ef9b0d7e94860b2b/cache.go#L127

Managed domains are updated through caddy configuration.

Eventually, renewal will be done here

https://github.com/caddyserver/certmagic/blob/3fcd710c0cfc6d80026011c8ef9b0d7e94860b2b/maintain.go#L235

TLS cache will try to renew the certificate using the latest issuer url, but first it will check the existence of the old certificate:

https://github.com/caddyserver/certmagic/blob/3fcd710c0cfc6d80026011c8ef9b0d7e94860b2b/config.go#L807-L812

It doesn't exist because the old certificate if from a different issuer and the path checked is from the latest issuer.

This will be retried here

https://github.com/caddyserver/certmagic/blob/3fcd710c0cfc6d80026011c8ef9b0d7e94860b2b/config.go#L982

There are at least two ways to fix this: to restart caddy or remove the active caddy configuration and reload it so that caddy will realize these certificates don't exist and should be created instead.

Metadata

Metadata

Assignees

Labels

bug 🐞Something isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions